/* 控制层, 所有逻辑代码都在这里写 */ Ext.QuickTips.init(); Ext.define('erp.controller.common.Main', { extend: 'Ext.app.Controller', requires: ['erp.util.FormUtil'], /* refs:[ {ref: 'erpTreePanel',selector: 'erpTablePanel'}, {ref: 'erpTabPanel',selector:'erpTablePanel'} ], */ stores: ['TreeStore'], //声明该控制层要用到的store /* models: ['TreeModel'],//声明该控制层要用到的model */ views: ['common.main.Header', 'common.main.Bottom', 'common.main.TreePanel', 'common.main.TabPanel', 'common.main.Viewport', 'common.main.FlowPanel', 'common.main.Toolbar', 'common.main.TreeTabPanel', 'core.trigger.SearchField', 'core.window.ReLogin' ], //声明该控制层要用到的view init: function() { var me = this; me.FormUtil = Ext.create('erp.util.FormUtil'); this.flag = true; //防止双击时tree节点重复加载 //每隔8秒刷新【网络寻呼】 Ext.defer(function() { me.loadPagingRelease(); }, 1000); //每隔一分钟刷新[首页待办事宜] Ext.defer(function() { me.loadJprocess(); }, 60000); this.control({ 'erpTreePanel': { itemmousedown: function(selModel, record) { if (!this.flag) { return; } this.flag = false; setTimeout(function() { me.flag = true; me.loadTab(selModel, record); }, 20); //防止双击时tree节点重复加载 }, itemclick: function(selModel, record) { if (!this.flag) { return; } this.flag = false; setTimeout(function() { me.flag = true; me.loadTab(selModel, record); }, 20); }, itemdbclick: function(selModel, record) { if (!this.flag) { return; } this.flag = false; setTimeout(function() { me.flag = true; me.loadTab(selModel, record); }, 20); }, itemmouseenter: me.showActions, itemmouseleave: me.hideActions, beforeitemmouseenter: me.showActions, addclick: me.handleAddClick }, 'erpTabPanel': { tabchange: function(tab, newC, oldC, obj) { } }, 'menuitem[id=lock]': { click: function(btn) { //锁定屏幕 me.lockPage(); } }, 'menuitem[id=addrbook]': { click: function() { me.showAddrBook(); } }, 'treepanel[id=addr-tree]': { itemmousedown: function(view, record, item, index, e) { if (record.data['leaf']) { //开始寻呼 me.showDialogBox(null, Math.abs(record.data['id']), record.data['text']); } else { if (!record.isExpanded() && contains(record.data['id'], 'org', true)) { //如果是组织 var ch = record.childNodes, bool = false; Ext.each(ch, function() { if (this.data['leaf']) { bool = true; } }); if (bool) { //刷新当前组织下人员在线状态 me.checkOnline(record, e); } } } } }, 'menuitem[id=set-pwd]': { click: function() { me.showPwdPanel(); } } }); }, loadTab: function(selModel, record) { var me = this; if (record.get('leaf') || record.get('url') != null) { switch (record.data['showMode']) { case 0: //0-选项卡模式 me.openCard(record); break; case 1: //1-弹出框式 me.openBox(record); break; case 2: //2-空白页 me.openBlank(record); break; case 3: //3-窗口模式 me.openWin(record); break; default: me.openCard(record); break; } //***********常用模块++ //工作台所在页面 var w = Ext.getCmp("content-panel").items.items[0].body.dom.getElementsByTagName('iframe')[0].contentWindow; //常用模块 me.setCommonUse(record.get('url')); me.flag = true; } if (!record.get('leaf')) { if (record.isExpanded() && record.childNodes.length > 0) { //是根节点,且已展开 record.collapse(true, true); //收拢 me.flag = true; } else { //未展开 //看是否加载了其children if (record.childNodes.length == 0) { //从后台加载 var tree = Ext.getCmp('tree-panel'); var condition = tree.baseCondition; tree.setLoading(true, tree.body); Ext.Ajax.request({ //拿到tree数据 url: basePath + 'common/lazyTree.action', params: { parentId: record.data['id'], condition: condition }, callback: function(options, success, response) { tree.setLoading(false); var res = new Ext.decode(response.responseText); if (res.tree) { if (!record.get('level')) { record.set('level', 0); } Ext.each(res.tree, function(n) { if (n.showMode == 2) { //openBlank n.text = "" + n.text + ""; } if (!n.leaf) { n.level = record.get('level') + 1; n.iconCls = 'x-tree-icon-level-' + n.level; } }); record.appendChild(res.tree); record.expand(false, true); //展开 me.flag = true; } else if (res.exceptionInfo) { showError(res.exceptionInfo); me.flag = true; } } }); } else { record.expand(false, true); //展开 me.flag = true; } } } }, openTab: function(panel, id, url) { var o = (typeof panel == "string" ? panel : id || panel.id); var main = Ext.getCmp("content-panel"); var tab = main.getComponent(o); if (tab) { main.setActiveTab(tab); } else if (typeof panel != "string") { panel.id = o; var p = main.add(panel); main.setActiveTab(p); } }, getMyNewEmails: function() { Ext.Ajax.request({ url: basePath + "oa/mail/getNewMail.action", method: 'post', callback: function(options, success, response) { var res = new Ext.decode(response.responseText); if (res.exceptionInfo) { showError(res.exceptionInfo); return; } } }); }, parseUrl: function(url) { var id = url.substring(url.lastIndexOf('?') + 1); //将作为新tab的id if (id == null) { id = url.substring(0, url.lastIndexOf('.')); } if (contains(url, 'session:em_uu', true)) { //对url中session值的处理 url = url.replace(/session:em_uu/g, em_uu); } if (contains(url, 'session:em_code', true)) { //对url中em_code值的处理 url = url.replace(/session:em_code/g, "'" + em_code + "'"); } if (contains(url, 'sysdate', true)) { //对url中系统时间sysdate的处理 url = url.replace(/sysdate/g, "to_date('" + Ext.Date.toString(new Date()) + "','yyyy-mm-dd')"); } if (contains(url, 'session:em_name', true)) { url = url.replace(/session:em_name/g, "'" + em_name + "'"); } return url; }, openCard: function(record) { var me = this; var panel = Ext.getCmp(record.get('id')); if (!panel) { var url = me.parseUrl(record.data['url']); //解析url里的特殊描述 panel = { title: record.get('text').length > 5 ? (record.get('text').substring(0, 5) + '..') : record.get('text'), tag: 'iframe', tabConfig: { tooltip: record.get('qtip') }, border: false, frame: false, layout: 'fit', iconCls: record.data.iconCls, html: '', closable: true, listeners: { close: function() { var main = Ext.getCmp("content-panel"); main.setActiveTab(Ext.getCmp("HomePage")); } } }; if (record.get('leaf')) { this.openTab(panel, record.get('id'), url);} } else { var main = Ext.getCmp("content-panel"); main.setActiveTab(panel); } }, openBox: function(record) { window.open(basePath + this.parseUrl(record.data['url']), record.get('qtip'), 'width=' + (window.screen.width - 10) + ',height=' + (window.screen.height * 0.87) + ',top=0,left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no'); }, openBlank: function(record) { //window.open(basePath + this.parseUrl(record.data['url'])); }, openWin: function(record) { if (Ext.getCmp('twin_' + record.data['id'])) { Ext.getCmp('twin_' + record.data['id']).show(); } else { new Ext.window.Window({ id: 'twin_' + record.data['id'], title: record.get('qtip').length > 5 ? (record.get('qtip').substring(0, 5) + '..') : record.get('qtip'), height: "100%", width: "80%", maximizable: true, layout: 'anchor', items: [{ tag: 'iframe', frame: true, anchor: '100% 100%', layout: 'fit', html: '' }] }).show(); } }, lockPage: function() { var me = this; Ext.Ajax.request({ url: basePath + "common/logout.action", method: 'post', callback: function(options, success, response) { var res = Ext.decode(response.responseText); if (res.success) { //弹出解锁框 me.showLock(); } } }); }, /** * 显示锁屏window */ showLock: function() { var me = this; var panel = Ext.create('Ext.window.Window', { id: 'lock-win', frame: true, closable: false, modal: true, autoShow: true, title: '
 !您的屏幕已锁定
', bodyStyle: 'background: #E0EEEE', width: 360, height: 260, renderTo: Ext.getBody(), items: [{ xtype: 'displayfield', height: 130, labelWidth: 128, labelSeparator: '', fieldStyle: 'color:#7D9EC0;font-size:15px;font-family:隶书;', fieldLabel: '', value: '如需解锁,请输入您的密码' }, { xtype: 'hidden', name: 'username', id: 'username', value: em_code }, { xtype: 'form', bodyStyle: 'background: #E0EEEE', layout: 'column', items: [{ xtype: 'textfield', labelSeparator: '', columnWidth: 0.8, fieldLabel: '', labelWidth: 40, fieldCls: 'x-form-field-cir', id: 'password', name: 'password', inputType: 'password' }, { xtype: 'button', columnWidth: 0.2, cls: 'x-btn-blue', text: '解锁', handler: function() { me.removeLock(); } }] }] }); panel.el.slideIn('b', { duration: 1000 }); }, removeLock: function() { var win = Ext.getCmp('lock-win'); if (win && win.down('#password').value != null) { Ext.Ajax.request({ url: basePath + "common/login.action", params: { username: win.down('#username').value, password: win.down('#password').value, language: language }, method: 'post', callback: function(options, success, response) { var res = Ext.decode(response.responseText); if (res.success) { //弹出解锁框 win.close(); } else { if (res.reason) { alert(res.reason); win.down('#password').setValue(''); win.down('#password').focus(); } } } }); } }, /** * 右下角小消息提示 * @param title 标题 * @param fromId 发送人Id * @param from 发送人 * @param date 日期 * @param context 正文 * @param url 消息链接 * @param msgId 消息ID */ showMsgTip: function(title, prId, fromId, from, date, context, url, msgId, master) { var me = this; var panel = Ext.getCmp('msg-win-' + prId); if (!panel) { panel = Ext.create('erp.view.core.window.MsgTip', { title: title, from: from, date: date, url: url, msgId: msgId, prId: prId, height: 120, //提示信息显示不全 context: context, listeners: { close: function() { me.updatePagingStatus(msgId, 1, master); }, check: function() { me.showDialogBox(msgId, fromId, from, date, context); }, reply: function() { me.showDialogBox(msgId, fromId, from, date, context); } } }); } }, transImages: function(msg) { msg = msg.toString(); var faces = msg.match(/&f\d+;/g); Ext.each(faces, function(f) { //表情 msg = msg.replace(f, ''); }); var images = msg.match(/&img\d+;/g); Ext.each(images, function(m) { //图片 msg = msg.replace(m, ''); }); return msg; }, /** * 对话框 * @param id 消息的主键值 * @param otherId 对方人员ID * @param other 对方人名 * @param date 时间 * @param context 对话内容 */ showDialogBox: function(id, otherId, other, date, context) { var me = this; var panel = Ext.getCmp('dialog-win-' + otherId); if (!panel) { panel = Ext.create('erp.view.core.window.DialogBox', { other: other, otherId: otherId }); } if (!Ext.isEmpty(id)) { panel.insertDialogItem(other, date, context); if (Ext.getCmp('dialog-min-' + otherId)) { Ext.getCmp('dialog-min-' + otherId).setText("有新消息..."); } else { me.updatePagingStatus(id, 1); } } }, /** * 循环刷新寻呼信息 * @param cycletime 间隔时间 {快速4000(聊天过程中)、中等8000(普通模式)、慢速15000(session中断等异常情况下)} */ loadPagingRelease: function() { var me = this; me.cycletime = me.cycletime || 8000; if (!Ext.getCmp('lock-win')) { try { me.getPagingRelease(); Ext.getCmp('process-lazy').setText(''); } catch (e) { //需要try catch一下,不然,循环会因出现的异常而中断。网络中断后,如果不刷新主页,而是直接重新登录的话,就不会继续循环刷新寻呼 me._showerr(e); } } setTimeout(function() { if (me.allowMsg) me.loadPagingRelease(); }, me.cycletime); }, /** * 循环刷新流程信息 * */ loadJprocess: function() { var me = this; if (!me.bench) me.bench = Ext.getCmp("content-panel").items.items[0].body.dom.getElementsByTagName('iframe')[0].contentWindow.workbench; if (!Ext.getCmp('lock-win') && me.bench) { me.bench.refreshTask(me.onlyJprocess); } setTimeout(function() { me.loadJprocess(); }, 60000); }, _showerr: function(e) { var me = this; if (e.code == 101 || e.message == 'NETWORK_ERR' || e.message == 'NETWORK_LAZY' || e.message == 'NETWORK_LOCK') { //NETWORK_ERR me.cycletime = 20000; if (e.message == 'NETWORK_ERR') { showLoginDiv(true); Ext.getCmp('process-lazy').setText('服务器连接中断,服务器可能已关闭或在重启,尝试连接中...'); } else if (e.message == 'NETWORK_LAZY') { Ext.getCmp('process-lazy').setText('请求超时8000ms,服务器负荷过大或网络延迟,请暂缓操作,尝试恢复中...'); } else if (e.message == 'NETWORK_LOCK') { //账号被强制锁定 Ext.Ajax.request({ url: basePath + "common/logout.action", method: 'post', callback: function(options, success, response) { var res = Ext.decode(response.responseText); if (res.success) { alert('您已被管理员强制注销,请重新登录!'); window.location.reload(); } } }); } } }, /** * 获取未读网络寻呼 */ getPagingRelease: function() { var me = this, t1 = new Date().getTime(); Ext.Ajax.request({ url: basePath + 'oa/info/getPagingRelease.action', method: 'get', timeout: 8000, callback: function(options, success, response) { var e = null; if (success == false) { var lazy = new Date().getTime() - t1; if (lazy > 7500) { // 表示超时引起 e = new Error("NETWORK_LAZY"); } else { // 表示服务器连接中断引起 e = new Error("NETWORK_ERR"); } } else { me.cycletime = 8000; } var localJson = new Ext.decode(response.responseText, true); if (localJson.exceptionInfo) { var info = localJson.exceptionInfo; if (info == 'ERR_NETWORK_SESSIONOUT') { e = new Error("NETWORK_ERR"); } else if (info == 'ERR_NETWORK_LOCKED') { e = new Error("NETWORK_LOCK"); } else { showMessage('警告', info); } } if (e != null) { me._showerr(e); return; } if (localJson.success) { if (localJson.IsRemind) { me.allowMsg = true; var data = Ext.decode(localJson.data); if (data != null && data.length > 0) { Ext.each(data, function(d) { if(d.pr_istop){ me.showTopWin(d); } else{ if (Ext.getCmp('dialog-win-' + d.pr_releaserid)) { me.showDialogBox(d.prd_id, d.pr_releaserid, d.pr_releaser, Ext.Date.format(Ext.Date.parse(d.pr_date, 'Y-m-d H:i:s'), 'Y-m-d H:i:s'), d.pr_context, d.currentMaster); } else { me.showMsgTip('您收到了新的寻呼', d.pr_id, d.pr_releaserid, d.pr_releaser, Ext.Date.format(Ext.Date.parse(d.pr_date, 'Y-m-d H:i:s'), 'Y-m-d H:i:s'), d.pr_context, 'jsps/oa/info/pagingDetail.jsp?formCondition=prd_idIS' + d.prd_id, d.prd_id, d.currentMaster); } } }); } } else { me.allowMsg = false; // 设置为不允许弹消息窗 } } } }); }, /** * 消息框置顶 * */ showTopWin:function(d){ var iWidth=800,iHeight=550; var iTop = (window.screen.availHeight-30-iHeight)/2; //获得窗口的垂直位置; var iLeft = (window.screen.availWidth-10-iWidth)/2; // window.open(basePath+'oa/info/receive.action?id='+d.prd_id,'_blank','width='+iWidth+',height='+iHeight+',top='+iTop+',left='+iLeft+',target=_top,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no'); }, /** * @param id 明细ID * @param status 待修改状态 */ updatePagingStatus: function(id, status, master) { Ext.Ajax.request({ url: basePath + 'oa/info/updateStatus.action', params: { id: id, status: status, master: master }, method: 'post', callback: function(options, success, response) { var localJson = new Ext.decode(response.responseText); if (localJson.exceptionInfo) { showError(localJson.exceptionInfo); return null; } } }); }, /** * 通讯录 */ showAddrBook: function() { if (!Ext.getCmp('addrbook-win')) { Ext.create('Ext.window.Window', { id: 'addrbook-win', title: '我的通讯录', height: screen.height * 0.8, width: screen.width * 0.2, renderTo: Ext.getBody(), animCollapse: false, constrainHeader: true, bodyBorder: true, layout: 'accordion', border: false, autoShow: true, collapsible: true, x: screen.width * 0.8, items: [ Ext.create('erp.view.oa.addrBook.AddrBookTree', { id: 'addr-tree', title: '联系人' }), { title: '设置', html: '

...

', autoScroll: true }, { title: '我的应用', html: '

...

' } ] }); } else { Ext.getCmp('addrbook-win').show(); } }, checkOnline: function(record, e) { Ext.Ajax.request({ url: 'oa/info/checkOnline.action', params: { orgid: Number(record.data.data ? record.data.data.or_id : record.raw.data.or_id) }, method: 'POST', callback: function(options, success, response) { var res = Ext.decode(response.responseText); var data = res.data; if (data) { var count = 0; var ems = Ext.Array.pluck(data, 'em_id'); Ext.each(record.childNodes, function(node) { if (Ext.Array.contains(ems, Math.abs(node.data['id']))) { node.set('iconCls', 'x-tree-icon-happy'); node.set('cls', 'x-tree-cls-node-on'); var d = Ext.Array.filter(data, function(dd) { return dd.em_id == Math.abs(node.get('id')); })[0]; node.set('qtip', '' + '' + '' + '' + '' + '
编号:' + d.em_code + '
姓名:' + d.em_name + '
IP:' + d.ip + '
时间:' + Ext.Date.format(new Date(d.date), 'Y-m-d H:i:s') + '
'); count++; } else { node.set('iconCls', 'x-tree-icon-sad'); node.set('cls', 'x-tree-cls-node-off'); } }); if (count > 0) { if (!record.data.oriText) { record.data.oriText = record.data.text; } record.expand(false, true); } } } }); }, showPwdPanel: function() { Ext.create('erp.view.core.window.PwdWindow'); }, showActions: function(view, list, node, rowIndex, e) { var icons = Ext.DomQuery.select('.x-action-col-icon', node), record = view.getRecord(node); if (record.get('addurl')) { Ext.each(icons, function(icon) { Ext.get(icon).removeCls('x-hidden'); }); } }, hideActions: function(view, list, node, rowIndex, e) { var icons = Ext.DomQuery.select('.x-action-col-icon', node), record = view.getRecord(node); Ext.each(icons, function(icon) { Ext.get(icon).addCls('x-hidden'); }); }, handleAddClick: function(view, rowIndex, colIndex, column, e) { var record = view.getRecord(view.findTargetByEvent(e)), title = record.get('text'); if (record.get('addurl')) { openTable(title, record.get('addurl'), record.get('caller')); me.setCommonUse(record.get('addurl')); } }, setCommonUse:function(url){ Ext.Ajax.request({ url : basePath + 'common/setCommonUse.action', params: { url:url, count:15 }, method : 'post', callback : function(options,success,response){ var res = new Ext.decode(response.responseText); if(res.exception || res.exceptionInfo){ showError(res.exceptionInfo); return; } } }); } });