MainController.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. /**
  2. * This class is the controller for the main view for the application. It is specified as
  3. * the "controller" of the Main view class.
  4. */
  5. Ext.define('saas.view.main.MainController', {
  6. extend: 'Ext.app.ViewController',
  7. alias: 'controller.main',
  8. init: function() {
  9. this.setCompanyMenu();
  10. },
  11. setCompanyMenu: function() {
  12. var me = this, view = me.getView(), viewModel = me.getViewModel(),
  13. account = viewModel.get('account'), companies = account && account.companies,
  14. companyMenu = view.lookup('mainprofile').getMenu(), items = [];
  15. if (companies) {
  16. items = companies.map(function(c){
  17. return {
  18. text: c.name,
  19. value: c.id,
  20. handler: 'selectCompany',
  21. iconCls: c.id == account.companyId ? 'x-fa fa-check' : ''
  22. }
  23. });
  24. }
  25. if(items.length > 1) {
  26. companyMenu.insert(0, items);
  27. viewModel.set('hasManyCompany', true);
  28. }else {
  29. viewModel.set('hasManyCompany', false);
  30. }
  31. },
  32. onToggleNavigationSize: function () {
  33. var me = this,
  34. viewModel = me.getViewModel(),
  35. refs = me.getReferences(),
  36. navigationList = refs.navigationTreeList,
  37. navCollapsed = !navigationList.navCollapsed,
  38. new_width = navCollapsed ? viewModel.get('smallNavWidth') : viewModel.get('navWidth'),
  39. newLogoImgStyle = navCollapsed ? { width: 36, height: 36, top: 6, left: 12 } : { width: 32, height: 32, top: 8, left: 28 },
  40. newLogoTextStyle = navCollapsed ? {
  41. 0: { opacity: 0 },
  42. 100: { opacity: 0, display: 'none' }
  43. } : {
  44. 10: { opacity: 0 },
  45. 90: { opacity: 1 }
  46. },
  47. newNavIconStyle = navCollapsed ? { marginLeft: 6, fontSize: 28 } : { marginLeft: 22, fontSize: 24 },
  48. newNavTextStyle = navCollapsed ? { opacity: 0 } : { opacity: 1 },
  49. ope = navCollapsed ? 'addCls' : 'removeCls',
  50. toggleIconCls = navCollapsed ? 'sa-arrows-right' : 'sa-arrows-left';
  51. var mainLogo = refs.mainLogo;
  52. var logoImg = mainLogo.el.dom.getElementsByTagName('img')[0];
  53. var logoText = mainLogo.el.dom.getElementsByClassName('logo-text')[0];
  54. var navItems = navigationList.el.dom.getElementsByClassName('x-navitem');
  55. var toggleIcon = Ext.getCmp('main-navigation-toggle-btn');
  56. Ext.suspendLayouts();
  57. toggleIcon.setIconCls('x-sa ' + toggleIconCls);
  58. mainLogo.animate({dynamic: true, duration: 500, to: {width: new_width}});
  59. Ext.fly(logoImg).animate({dynamic: true, duration: 500, to: newLogoImgStyle});
  60. Ext.fly(logoText).animate({dynamic: true, duration: 500, keyframes: newLogoTextStyle});
  61. navigationList.animate({dynamic: true, duration: 500, to: {width: new_width}});
  62. for(var i = 0; i < navItems.length; i++) {
  63. var item = navItems[i];
  64. var icon = item.getElementsByClassName('nav-inner-icon')[0];
  65. var text = item.getElementsByClassName('nav-inner-text')[0];
  66. Ext.fly(icon).animate({dynamic: true, duration: 500, to: newNavIconStyle});
  67. Ext.fly(text).animate({dynamic: true, duration: 500, to: newNavTextStyle});
  68. }
  69. navigationList.el[ope]('nav-collapsed');
  70. navigationList.navCollapsed = navCollapsed;
  71. Ext.resumeLayouts(true);
  72. },
  73. selectCompany: function(item) {
  74. this.fireEvent('selectCompany', item.value);
  75. },
  76. onLogout: function() {
  77. this.fireEvent('logout');
  78. },
  79. feedbackMsg:function(btn){
  80. var me = this,
  81. win = Ext.getCmp("feedbackWin");
  82. if (!win) {
  83. win = Ext.create('Ext.window.Window', {
  84. modal: true,
  85. draggable: false,
  86. resizable: false,
  87. id:"feedbackWin",
  88. cls: 'x-window-dbfind',
  89. height: 343,
  90. width: 756,
  91. title: '意见反馈',
  92. scrollable: true,
  93. constrain: true,
  94. closable: true,
  95. layout: 'fit',
  96. items: [{
  97. xtype: 'sys-feedback-formpanel'
  98. }]
  99. });
  100. };
  101. win.show();
  102. },
  103. loadInvitationMsg: function(count,nowCompanyId) {
  104. var me = this.view;//视图层
  105. var hasInvitationMsg = false;
  106. //查询后台
  107. var param = [{
  108. type:'condition',
  109. value:"re_status=2"
  110. },{
  111. type:'condition',
  112. value:"companyId="+nowCompanyId
  113. }]
  114. Ext.Ajax.request({
  115. url :'/api/commons/remind/apply/list',
  116. timeout: 8000,
  117. async:true,
  118. headers:{
  119. 'Access-Control-Allow-Origin': '*',
  120. 'Authorization': saas.util.State.get('session').token,
  121. "Content-Type": 'application/json;charset=UTF-8'
  122. },
  123. method: 'GET',
  124. params:{
  125. condition:JSON.stringify(param)
  126. },
  127. success: function(fp, o){
  128. var res = Ext.decode(fp.responseText);
  129. me.InvitationList = res.data == null ?[]:res.data.list;
  130. if(res.data&&res.data.list.length>0){
  131. hasInvitationMsg = true;
  132. }else{
  133. hasInvitationMsg = false;
  134. }
  135. var s = me.items.items[0].down('[name=realname]')
  136. if(hasInvitationMsg){
  137. s.getEl().dom.classList.add('x-header-redpoint')
  138. }else{
  139. s.getEl().dom.classList.remove('x-header-redpoint')
  140. }
  141. if(count==1){
  142. //打开加入邀请窗口
  143. setTimeout(function() {
  144. me.getController().invitation();
  145. }, 300);
  146. }
  147. },
  148. failure: function (response, opts) {}
  149. });
  150. //与后台建立连接
  151. //me.getController().InvitationSocket();
  152. },
  153. InvitationSocket:function(){
  154. //建立连接
  155. var  wsServer = 'ws://10.1.80.23:8560/msg/invitation';
  156. var  ws = new WebSocket(wsServer);
  157. ws.onopen = function () {
  158. // 使用 send() 方法发送数据
  159. ws.send("发送数据");
  160. alert("数据发送中...");
  161. };
  162. // 接收服务端数据时触发事件
  163. ws.onmessage = function (evt) {
  164. var received_msg = evt.data;
  165. alert("数据已接收...");
  166. };
  167. // 断开 web socket 连接成功触发事件
  168. ws.onclose = function () {
  169. alert("连接已关闭...");
  170. };
  171. },
  172. invitation:function(){
  173. var me = this;
  174. var data = me.view.InvitationList;
  175. if(data.length>0){
  176. var items = [{
  177. margin:'0 0 0 60px',
  178. xtype:'displayfield',
  179. fieldStyle : 'font-weight: 800;font-size: 18px;color: #35baf6;',
  180. value:'收到加入企业申请'
  181. }];
  182. Ext.each(data, function(item, index){
  183. if(index<3){
  184. //最多3条
  185. var o = {
  186. margin:'10 0 0 0',
  187. xtype:'panel',
  188. layout: 'hbox',
  189. style:'border:1px solid #34BAF6; padding-top: 3px;',
  190. items:[{
  191. labelWidth:60,
  192. fieldLabel:'申请人',
  193. xtype:'displayfield',
  194. fieldStyle : 'color: black;',
  195. value:item.username
  196. },{
  197. labelWidth:80,
  198. padding:'0 10 0 0',
  199. fieldLabel:'联系方式',
  200. xtype:'displayfield',
  201. fieldStyle : 'color: black;',
  202. value:item.mobile
  203. }]
  204. }
  205. items.push(o);
  206. }
  207. });
  208. items.push({
  209. width:128,
  210. margin:'20 0 0 70',
  211. xtype:'button',
  212. text:'查 看',
  213. handler:function(){
  214. saas.util.BaseUtil.openTab('sys-invitation-datalist','申请列表', 'sys-invitation-datalist');
  215. this.ownerCt.ownerCt.close()
  216. }
  217. });
  218. var nowHeight = (items.length-2)*70+130;
  219. //打开邀请窗口
  220. var win = Ext.create('Ext.window.Window', {
  221. cls:'x-window-dbfind',
  222. height: nowHeight,
  223. width: '45%',
  224. modal:true,
  225. title: '加入邀请',
  226. bodyPadding: 10,
  227. constrain: true,
  228. closable: true,
  229. layout: {
  230. type: 'vbox',
  231. align: 'center'
  232. },
  233. items:[{
  234. xtype:'panel',
  235. layout:'vbox',
  236. items:items
  237. }]
  238. });
  239. win.show();
  240. }
  241. },
  242. shareCompany:function(){
  243. if(this.getViewModel()._parent.data.account.companyId==2){
  244. saas.util.BaseUtil.showErrorToast('演示账套无法分享');
  245. return false;
  246. }
  247. //打开分享窗口
  248. var win = Ext.create('Ext.window.Window', {
  249. cls:'x-window-dbfind',
  250. height: 415,
  251. width: 550,
  252. modal:true,
  253. title: '邀请同事',
  254. bodyPadding: 10,
  255. constrain: true,
  256. closable: true,
  257. layout: 'fit',
  258. items:[{
  259. plain:true,
  260. xtype:'tabpanel',
  261. cls:'x-tab-shareTab',
  262. items:[{
  263. title:'二维码邀请',
  264. xtype:'panel',
  265. layout: {
  266. type: 'vbox',
  267. align: 'center'
  268. },
  269. items:[{
  270. width:180,
  271. height:180,
  272. xtype: 'image',
  273. margin:'25 0 0 0',
  274. padding:'5',
  275. style:'border: 1px solid #000;',
  276. src:'resources/images/default/basePhoto.png',
  277. name:'QRcode',
  278. listeners:{
  279. afterrender:function(f){
  280. var companyName = document.getElementsByClassName('x-main-master')[0].getElementsByClassName('x-btn-inner x-btn-inner-header-small')[0].innerText;
  281. var serverOptions = Ext.manifest.server;
  282. var delay = 1;//天
  283. var accountCenter = serverOptions.accountCenter;
  284. var basePath = serverOptions.basePath.https?serverOptions.basePath.https:serverOptions.basePath;
  285. Ext.Ajax.request({
  286. url :basePath+'/api/commons/share/qrcode?basePath='+accountCenter+'&delay='+delay+'&companyName='+companyName,
  287. timeout: 8000,
  288. headers:{
  289. 'Access-Control-Allow-Origin': '*',
  290. 'Authorization': saas.util.State.get('session').token,
  291. "Content-Type": 'application/json;charset=UTF-8'
  292. },
  293. method: 'GET',
  294. responseType:'blob',
  295. success: function(fp, o){
  296. var url = URL.createObjectURL(fp.responseBlob);
  297. f.setSrc(url)
  298. },
  299. failure: function (response, opts) {
  300. saas.util.BaseUtil.showErrorToast('获取二维码失败');
  301. }
  302. });
  303. }
  304. }
  305. },{
  306. xtype:'displayfield',
  307. value:'扫描二维码分享至微信/QQ'
  308. },{
  309. xtype:'displayfield',
  310. value:'(分享后'+'<font style="color:#ff0000;">24小时</font>'+'内有效)'
  311. }]
  312. },{
  313. title:'链接邀请',
  314. xtype:'panel',
  315. layout: {
  316. type: 'vbox',
  317. align: 'center'
  318. },
  319. items:[{
  320. margin:'60 0 0 0',
  321. xtype:'displayfield',
  322. value:'复制以下链接分享给好友'
  323. },{
  324. xtype:'textfield',
  325. width:500,
  326. value:'暂无',
  327. listeners:{
  328. afterrender:function(f){
  329. var serverOptions = Ext.manifest.server;
  330. var accountCenter = serverOptions.accountCenter;
  331. var companyName = document.getElementsByClassName('x-main-master')[0].getElementsByClassName('x-btn-inner x-btn-inner-header-small')[0].innerText;
  332. var delay = 1;
  333. var basePath = serverOptions.basePath.https?serverOptions.basePath.https:serverOptions.basePath;
  334. Ext.Ajax.request({
  335. url :basePath+'/api/commons/share/pc?basePath='+accountCenter+'&delay='+delay+'&companyName='+companyName,
  336. timeout: 8000,
  337. async:false,
  338. headers:{
  339. 'Access-Control-Allow-Origin': '*',
  340. 'Authorization': saas.util.State.get('session').token,
  341. "Content-Type": 'application/json;charset=UTF-8'
  342. },
  343. method: 'GET',
  344. success: function(response, o){
  345. var res = Ext.decode(response.responseText);
  346. var url = res.data;
  347. f.setValue(url + '&_noc=1')
  348. },
  349. failure: function (response, opts) {
  350. saas.util.BaseUtil.showErrorToast('获取分享地址失败');
  351. }
  352. });
  353. }
  354. }
  355. },{
  356. margin:'10 0 0 0',
  357. width:110,
  358. xtype:'button',
  359. text:'复 制',
  360. handler:function(b){
  361. var text = b.ownerCt.items.items[1].value;
  362. var target = Ext.DomHelper.append(document.body, {
  363. tag: 'textarea',
  364. style: 'opacity: 0;position: absolute;top: -10000px;right: 0;',
  365. html: text
  366. });
  367. target.focus();
  368. target.select();
  369. document.execCommand('Copy');
  370. target.blur();
  371. document.body.removeChild(target);
  372. saas.util.BaseUtil.showSuccessToast('复制链接成功');
  373. }
  374. },{
  375. margin:'10 0 0 0',
  376. xtype:'displayfield',
  377. value:'(分享后'+'<font style="color:#ff0000;">24小时</font>'+'内有效)'
  378. }]
  379. }]
  380. }]
  381. });
  382. win.show();
  383. }
  384. });