Main.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924
  1. /*
  2. 控制层,
  3. 所有逻辑代码都在这里写
  4. */
  5. Ext.QuickTips.init();
  6. Ext.define('erp.controller.common.Main', {
  7. extend: 'Ext.app.Controller',
  8. requires: ['erp.util.FormUtil'],
  9. /* refs:[
  10. {ref: 'erpTreePanel',selector: 'erpTablePanel'},
  11. {ref: 'erpTabPanel',selector:'erpTablePanel'}
  12. ], */
  13. stores: ['TreeStore'], //声明该控制层要用到的store
  14. /* models: ['TreeModel'],//声明该控制层要用到的model
  15. */
  16. views: ['common.main.Header', 'common.main.Bottom', 'common.main.TreePanel', 'common.main.TabPanel', 'common.main.Viewport', 'common.main.FlowPanel',
  17. 'common.main.Toolbar', 'common.main.TreeTabPanel', 'core.trigger.SearchField', 'core.window.ReLogin','common.main.NavigationTreePanel','common.main.NavigationToolbar'
  18. ], //声明该控制层要用到的view
  19. init: function() {
  20. var me = this;
  21. me.FormUtil = Ext.create('erp.util.FormUtil');
  22. this.flag = true; //防止双击时tree节点重复加载
  23. this.naviFlag = true; //防止双击时tree节点重复加载
  24. //每隔8秒刷新【网络寻呼】
  25. Ext.defer(function() {
  26. me.loadPagingRelease();
  27. }, 1000);
  28. //每隔一分钟刷新[首页]---主要考虑点开首页不做任何操作
  29. Ext.defer(function() {
  30. me.refreshDesk();
  31. }, 60000);
  32. this.control({
  33. 'erpTreePanel': {
  34. itemmousedown: function(selModel, record) {
  35. if (!this.flag) {
  36. return;
  37. }
  38. this.flag = false;
  39. setTimeout(function() {
  40. me.flag = true;
  41. me.loadTab(selModel, record);
  42. }, 20); //防止双击时tree节点重复加载
  43. },
  44. itemclick: function(selModel, record) {
  45. if (!this.flag) {
  46. return;
  47. }
  48. this.flag = false;
  49. setTimeout(function() {
  50. me.flag = true;
  51. me.loadTab(selModel, record);
  52. }, 20);
  53. },
  54. itemdbclick: function(selModel, record) {
  55. if (!this.flag) {
  56. return;
  57. }
  58. this.flag = false;
  59. setTimeout(function() {
  60. me.flag = true;
  61. me.loadTab(selModel, record);
  62. }, 20);
  63. },
  64. itemmouseenter: me.showActions,
  65. itemmouseleave: me.hideActions,
  66. beforeitemmouseenter: me.showActions,
  67. addclick: me.handleAddClick
  68. },
  69. 'panel[id=HomePage]':{
  70. activate :function(tab){
  71. if(iframe_homePage){
  72. var win=iframe_homePage.contentWindow;
  73. if(win && win.Ext){
  74. var desk=win.Ext.ComponentQuery.query('deskportal');
  75. if(desk.length>0) desk[0].fireEvent('datarefresh',desk[0],'activeRefresh');
  76. }
  77. }
  78. }
  79. },
  80. 'menuitem[id=lock]': {
  81. click: function(btn) {
  82. //锁定屏幕
  83. me.lockPage();
  84. }
  85. },
  86. 'menuitem[id=addrbook]': {
  87. click: function() {
  88. me.showAddrBook();
  89. }
  90. },
  91. 'treepanel[id=addr-tree]': {
  92. itemmousedown: function(view, record, item, index, e) {
  93. if (record.data['leaf']) {
  94. //开始寻呼
  95. me.showDialogBox(null, Math.abs(record.data['id']), record.data['text']);
  96. } else {
  97. if (!record.isExpanded() && contains(record.data['id'], 'org', true)) { //如果是组织
  98. var ch = record.childNodes,
  99. bool = false;
  100. Ext.each(ch, function() {
  101. if (this.data['leaf']) {
  102. bool = true;
  103. }
  104. });
  105. if (bool) {
  106. //刷新当前组织下人员在线状态
  107. me.checkOnline(record, e);
  108. }
  109. }
  110. }
  111. }
  112. },
  113. 'erpNavigationTreePanel': {//全功能导航
  114. itemmousedown: function(selModel, record) {
  115. if (!this.naviFlag) {
  116. return;
  117. }
  118. this.naviFlag = false;
  119. setTimeout(function() {
  120. me.naviFlag = true;
  121. me.loadNavigation(selModel, record);
  122. }, 20); //防止双击时tree节点重复加载
  123. },
  124. itemclick: function(selModel, record) {
  125. if (!this.naviFlag) {
  126. return;
  127. }
  128. this.naviFlag = false;
  129. setTimeout(function() {
  130. me.naviFlag = true;
  131. me.loadNavigation(selModel, record);
  132. }, 20);
  133. },
  134. itemdbclick: function(selModel, record) {
  135. if (!this.naviFlag) {
  136. return;
  137. }
  138. this.naviFlag = false;
  139. setTimeout(function() {
  140. me.naviFlag = true;
  141. me.loadNavigation(selModel, record);
  142. }, 20);
  143. },
  144. itemmouseenter: me.showSyanavigationActions,
  145. itemmouseleave: me.hideSyanavigationActions,
  146. beforeitemmouseenter: me.showSyanavigationActions,
  147. addclick:me.openSyanavigationDetail
  148. },
  149. 'menuitem[id=set-pwd]': {
  150. click: function() {
  151. me.showPwdPanel();
  152. }
  153. }
  154. });
  155. },
  156. openSyanavigationDetail: function(view, rowIndex, colIndex, column, e){//全功能导航
  157. var record = view.getRecord(view.findTargetByEvent(e)),
  158. id=record.get('id'),title = record.get('text');
  159. var panel = Ext.getCmp('SyanavigationDetail'+record.get('id'));
  160. if(!panel){
  161. var url = 'jsps/common/navigationDetails.jsp?id='+id;
  162. panel = {
  163. title: record.get('text').length > 5 ? (record.get('text').substring(0, 5) + '..') : record.get('text'),
  164. tag: 'iframe',
  165. tabConfig:{tooltip: title},
  166. border: false,
  167. frame: true,
  168. layout: 'fit',
  169. iconCls: record.data.iconCls,
  170. html : '<iframe id="iframe_maindetail_pageSet" src="' + basePath + url + '" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>',
  171. closable: true,
  172. listeners: {
  173. close: function() {
  174. var main = Ext.getCmp("content-panel");
  175. main.setActiveTab(Ext.getCmp("HomePage"));
  176. }
  177. }
  178. };
  179. this.openTab(panel, 'SyanavigationDetail'+record.get('id'), url);
  180. }else {
  181. var main = Ext.getCmp("content-panel");
  182. main.setActiveTab(panel);
  183. }
  184. },
  185. loadNavigation:function(selModel, record){
  186. var me = this;
  187. if (!record.get('leaf')) {
  188. if (record.isExpanded() && record.childNodes.length > 0) { //是根节点,且已展开
  189. record.collapse(true, true); //收拢
  190. me.naviFlag = true;
  191. } else { //未展开
  192. //看是否加载了其children
  193. if (record.childNodes.length == 0) {
  194. //从后台加载
  195. var tree = Ext.getCmp('navigation-panel');
  196. var condition = tree.baseCondition;
  197. tree.setLoading(true, tree.body);
  198. Ext.Ajax.request({ //拿到tree数据
  199. url: basePath + 'common/getAllNavigation.action',
  200. params: {
  201. parentId: record.data['id'],
  202. condition: condition
  203. },
  204. callback: function(options, success, response) {
  205. tree.setLoading(false);
  206. var res = new Ext.decode(response.responseText);
  207. if (res.tree) {
  208. if (!record.get('level')) {
  209. record.set('level', 0);
  210. }
  211. Ext.each(res.tree, function(n) {
  212. if (!n.leaf) {
  213. n.level = record.get('level') + 1;
  214. n.iconCls = 'x-tree-icon-level-' + n.level;
  215. }
  216. });
  217. record.appendChild(res.tree);
  218. record.expand(false, true); //展开
  219. me.naviFlag = true;
  220. } else if (res.exceptionInfo) {
  221. showError(res.exceptionInfo);
  222. me.naviFlag = true;
  223. }
  224. }
  225. });
  226. } else {
  227. record.expand(false, true); //展开
  228. me.naviFlag = true;
  229. }
  230. }
  231. }else{
  232. var id=record.get('id'),title = record.get('text');
  233. var panel = Ext.getCmp('SyanavigationDetail'+record.get('id'));
  234. if(!panel){
  235. var url = 'jsps/common/navigationDetails.jsp?id='+id;
  236. panel = {
  237. title: record.get('text').length > 5 ? (record.get('text').substring(0, 5) + '..') : record.get('text'),
  238. tag: 'iframe',
  239. tabConfig:{tooltip: title},
  240. border: false,
  241. frame: true,
  242. layout: 'fit',
  243. iconCls: record.data.iconCls,
  244. html : '<iframe id="iframe_maindetail_pageSet" src="' + basePath + url + '" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>',
  245. closable: true,
  246. listeners: {
  247. close: function() {
  248. var main = Ext.getCmp("content-panel");
  249. main.setActiveTab(Ext.getCmp("HomePage"));
  250. }
  251. }
  252. };
  253. this.openTab(panel, 'SyanavigationDetail'+record.get('id'), url);
  254. }else {
  255. var main = Ext.getCmp("content-panel");
  256. main.setActiveTab(panel);
  257. }
  258. }
  259. },
  260. showSyanavigationActions: function(view, list, node, rowIndex, e) {
  261. var icons = Ext.DomQuery.select('.x-action-col-icon', node),
  262. record = view.getRecord(node);
  263. if (!record.get('leaf')) {
  264. Ext.each(icons, function(icon) {
  265. Ext.get(icon).removeCls('x-hidden');
  266. });
  267. }
  268. },
  269. hideSyanavigationActions: function(view, list, node, rowIndex, e) {
  270. var icons = Ext.DomQuery.select('.x-action-col-icon', node),
  271. record = view.getRecord(node);
  272. Ext.each(icons, function(icon) {
  273. Ext.get(icon).addCls('x-hidden');
  274. });
  275. },
  276. loadTab: function(selModel, record) {
  277. var me = this;
  278. if (record.get('leaf') || record.get('url') != null) {
  279. switch (record.data['showMode']) {
  280. case 0: //0-选项卡模式
  281. me.openCard(record);
  282. break;
  283. case 1: //1-弹出框式
  284. me.openBox(record);
  285. break;
  286. case 2: //2-空白页
  287. me.openBlank(record);
  288. break;
  289. case 3: //3-窗口模式
  290. me.openWin(record);
  291. break;
  292. default:
  293. me.openCard(record);
  294. break;
  295. }
  296. //***********常用模块++
  297. //工作台所在页面
  298. var w = Ext.getCmp("content-panel").items.items[0].body.dom.getElementsByTagName('iframe')[0].contentWindow;
  299. /*
  300. * 常用模块修改需要考虑到直接箭头点开的情况
  301. * //常用模块
  302. var link = w.Ext.getCmp("bench_link");
  303. if (link) {
  304. w.workbench._set_bench_link(record.get('id'));
  305. }*/
  306. me.setCommonUse(record.get('url'));
  307. me.flag = true;
  308. }
  309. if (!record.get('leaf')) {
  310. if (record.isExpanded() && record.childNodes.length > 0) { //是根节点,且已展开
  311. record.collapse(true, true); //收拢
  312. me.flag = true;
  313. } else { //未展开
  314. //看是否加载了其children
  315. if (record.childNodes.length == 0) {
  316. //从后台加载
  317. var tree = Ext.getCmp('tree-panel');
  318. var condition = tree.baseCondition;
  319. tree.setLoading(true, tree.body);
  320. Ext.Ajax.request({ //拿到tree数据
  321. url: basePath + 'common/lazyTree.action',
  322. params: {
  323. parentId: record.data['id'],
  324. condition: condition
  325. },
  326. callback: function(options, success, response) {
  327. tree.setLoading(false);
  328. var res = new Ext.decode(response.responseText);
  329. if (res.tree) {
  330. if (!record.get('level')) {
  331. record.set('level', 0);
  332. }
  333. Ext.each(res.tree, function(n) {
  334. if (n.showMode == 2) { //openBlank
  335. n.text = "<a href='" + basePath + me.parseUrl(n.url) + "' target='_blank'>" + n.text + "</a>";
  336. }
  337. if (!n.leaf) {
  338. n.level = record.get('level') + 1;
  339. n.iconCls = 'x-tree-icon-level-' + n.level;
  340. }
  341. });
  342. record.appendChild(res.tree);
  343. record.expand(false, true); //展开
  344. me.flag = true;
  345. } else if (res.exceptionInfo) {
  346. showError(res.exceptionInfo);
  347. me.flag = true;
  348. }
  349. }
  350. });
  351. } else {
  352. record.expand(false, true); //展开
  353. me.flag = true;
  354. }
  355. }
  356. }
  357. },
  358. openTab: function(panel, id, url) {
  359. var o = (typeof panel == "string" ? panel : id || panel.id);
  360. var main = Ext.getCmp("content-panel");
  361. var tab = main.getComponent(o);
  362. if (tab) {
  363. main.setActiveTab(tab);
  364. } else if (typeof panel != "string") {
  365. panel.id = o;
  366. var p = main.add(panel);
  367. main.setActiveTab(p);
  368. }
  369. },
  370. getMyNewEmails: function() {
  371. Ext.Ajax.request({
  372. url: basePath + "oa/mail/getNewMail.action",
  373. method: 'post',
  374. callback: function(options, success, response) {
  375. var res = new Ext.decode(response.responseText);
  376. if (res.exceptionInfo) {
  377. showError(res.exceptionInfo);
  378. return;
  379. }
  380. }
  381. });
  382. },
  383. setCommonUse:function(url){
  384. Ext.Ajax.request({
  385. url : basePath + 'common/setCommonUse.action',
  386. params: {
  387. url:url,
  388. count:15
  389. },
  390. method : 'post',
  391. callback : function(options,success,response){
  392. var res = new Ext.decode(response.responseText);
  393. if(res.exception || res.exceptionInfo){
  394. showError(res.exceptionInfo);
  395. return;
  396. }
  397. }
  398. });
  399. },
  400. parseUrl: function(url) {
  401. var id = url.substring(url.lastIndexOf('?') + 1); //将作为新tab的id
  402. if (id == null) {
  403. id = url.substring(0, url.lastIndexOf('.'));
  404. }
  405. if (contains(url, 'session:em_uu', true)) { //对url中session值的处理
  406. url = url.replace(/session:em_uu/g, em_uu);
  407. }
  408. if (contains(url, 'session:em_code', true)) { //对url中em_code值的处理
  409. url = url.replace(/session:em_code/g, "'" + em_code + "'");
  410. }
  411. if (contains(url, 'sysdate', true)) { //对url中系统时间sysdate的处理
  412. url = url.replace(/sysdate/g, "to_date('" + Ext.Date.toString(new Date()) + "','yyyy-mm-dd')");
  413. }
  414. if (contains(url, 'session:em_name', true)) {
  415. url = url.replace(/session:em_name/g, "'" + em_name + "'");
  416. }
  417. if (contains(url, 'session:em_type', true)) {
  418. url = url.replace(/session:em_type/g, "'" + em_type + "'");
  419. }
  420. if (contains(url, 'session:em_id', true)) {
  421. url = url.replace(/session:em_id/g,em_id);
  422. }
  423. if (contains(url, 'session:em_depart', true)) {
  424. url = url.replace(/session:em_depart/g,em_id);
  425. }
  426. return url;
  427. },
  428. openCard: function(record) {
  429. var me = this;
  430. var panel = Ext.getCmp(record.get('id'));
  431. if (!panel) {
  432. var url = me.parseUrl(record.data['url']); //解析url里的特殊描述
  433. panel = {
  434. title: record.get('text').length > 5 ? (record.get('text').substring(0, 5) + '..') : record.get('text'),
  435. tag: 'iframe',
  436. tabConfig: {
  437. tooltip: record.get('qtip')
  438. },
  439. border: false,
  440. frame: false,
  441. layout: 'fit',
  442. iconCls: record.data.iconCls,
  443. html: '<iframe id="iframe_' + id + '" src="' + basePath + url + '" height="100%" width="100%" frameborder="0" style="border-width: 0px;padding: 0px;" scrolling="auto"></iframe>',
  444. closable: true,
  445. listeners: {
  446. close: function() {
  447. var main = Ext.getCmp("content-panel");
  448. main.setActiveTab(Ext.getCmp("HomePage"));
  449. }
  450. }
  451. };
  452. if (record.get('leaf')) {
  453. this.openTab(panel, record.get('id'), url);}
  454. } else {
  455. var main = Ext.getCmp("content-panel");
  456. main.setActiveTab(panel);
  457. }
  458. },
  459. openBox: function(record) {
  460. window.open(basePath + this.parseUrl(record.data['url']), record.get('qtip'), 'width=' + (window.screen.width - 10) +
  461. ',height=' + (window.screen.height * 0.87) + ',top=0,left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
  462. },
  463. openBlank: function(record) {
  464. //window.open(basePath + this.parseUrl(record.data['url']));
  465. },
  466. openWin: function(record) {
  467. if (Ext.getCmp('twin_' + record.data['id'])) {
  468. Ext.getCmp('twin_' + record.data['id']).show();
  469. } else {
  470. new Ext.window.Window({
  471. id: 'twin_' + record.data['id'],
  472. title: record.get('qtip').length > 5 ? (record.get('qtip').substring(0, 5) + '..') : record.get('qtip'),
  473. height: "100%",
  474. width: "80%",
  475. maximizable: true,
  476. layout: 'anchor',
  477. items: [{
  478. tag: 'iframe',
  479. frame: true,
  480. anchor: '100% 100%',
  481. layout: 'fit',
  482. html: '<iframe id="iframe_twin" src="' + basePath + this.parseUrl(record.data['url']) + '" height="100%" width="100%" frameborder="0" scrolling="auto"></iframe>'
  483. }]
  484. }).show();
  485. }
  486. },
  487. lockPage: function() {
  488. var me = this;
  489. Ext.Ajax.request({
  490. url: basePath + "common/logout.action",
  491. method: 'post',
  492. callback: function(options, success, response) {
  493. var res = Ext.decode(response.responseText);
  494. if (res.success) {
  495. //弹出解锁框
  496. me.showLock();
  497. }
  498. }
  499. });
  500. },
  501. /**
  502. * 显示锁屏window
  503. */
  504. showLock: function() {
  505. var me = this;
  506. var panel = Ext.create('Ext.window.Window', {
  507. id: 'lock-win',
  508. frame: true,
  509. closable: false,
  510. modal: true,
  511. autoShow: true,
  512. title: '<div style="height:25;padding-top:5px;color:blue;background: #E0EEEE url(' + basePath + 'resource/ext/resources/themes/images/default/grid/grid-blue-hd.gif) repeat center center">&nbsp;!您的屏幕已锁定</div>',
  513. bodyStyle: 'background: #E0EEEE',
  514. width: 360,
  515. height: 260,
  516. renderTo: Ext.getBody(),
  517. items: [{
  518. xtype: 'displayfield',
  519. height: 130,
  520. labelWidth: 128,
  521. labelSeparator: '',
  522. fieldStyle: 'color:#7D9EC0;font-size:15px;font-family:隶书;',
  523. fieldLabel: '<img src="' + basePath + 'resource/images/screens/locked.png" style="background: #E0EEEE;">',
  524. value: '如需解锁,请输入您的密码'
  525. }, {
  526. xtype: 'hidden',
  527. name: 'username',
  528. id: 'username',
  529. value: em_code
  530. }, {
  531. xtype: 'form',
  532. bodyStyle: 'background: #E0EEEE',
  533. layout: 'column',
  534. items: [{
  535. xtype: 'textfield',
  536. labelSeparator: '',
  537. columnWidth: 0.8,
  538. fieldLabel: '<img src="' + basePath + 'resource/images/screens/key.png" style="background: #E0EEEE;padding-left:15px;">',
  539. labelWidth: 40,
  540. fieldCls: 'x-form-field-cir',
  541. id: 'password',
  542. name: 'password',
  543. inputType: 'password'
  544. }, {
  545. xtype: 'button',
  546. columnWidth: 0.2,
  547. cls: 'x-btn-blue',
  548. text: '解锁',
  549. handler: function() {
  550. me.removeLock();
  551. }
  552. }]
  553. }]
  554. });
  555. panel.el.slideIn('b', {
  556. duration: 1000
  557. });
  558. },
  559. removeLock: function() {
  560. var win = Ext.getCmp('lock-win');
  561. if (win && win.down('#password').value != null) {
  562. Ext.Ajax.request({
  563. url: basePath + "common/login.action",
  564. params: {
  565. username: win.down('#username').value,
  566. password: win.down('#password').value,
  567. language: language
  568. },
  569. method: 'post',
  570. callback: function(options, success, response) {
  571. var res = Ext.decode(response.responseText);
  572. if (res.success) {
  573. //弹出解锁框
  574. win.close();
  575. } else {
  576. if (res.reason) {
  577. alert(res.reason);
  578. win.down('#password').setValue('');
  579. win.down('#password').focus();
  580. }
  581. }
  582. }
  583. });
  584. }
  585. },
  586. /**
  587. * 右下角小消息提示
  588. * @param title 标题
  589. * @param fromId 发送人Id
  590. * @param from 发送人
  591. * @param date 日期
  592. * @param context 正文
  593. * @param url 消息链接
  594. * @param msgId 消息ID
  595. */
  596. showMsgTip: function(title, prId, fromId, from, date, context, url, msgId, master) {
  597. var me = this;
  598. var panel = Ext.getCmp('msg-win-' + prId);
  599. if (!panel) {
  600. panel = Ext.create('erp.view.core.window.MsgTip', {
  601. title: title,
  602. from: from,
  603. date: date,
  604. url: url,
  605. msgId: msgId,
  606. prId: prId,
  607. height: 120, //提示信息显示不全
  608. context: context,
  609. listeners: {
  610. close: function() {
  611. me.updatePagingStatus(msgId, 1, master);
  612. },
  613. check: function() {
  614. me.showDialogBox(msgId, fromId, from, date, context);
  615. },
  616. reply: function() {
  617. me.showDialogBox(msgId, fromId, from, date, context);
  618. }
  619. }
  620. });
  621. }
  622. },
  623. transImages: function(msg) {
  624. msg = msg.toString();
  625. var faces = msg.match(/&f\d+;/g);
  626. Ext.each(faces, function(f) { //表情
  627. msg = msg.replace(f, '<img src="' + basePath + 'resource/images/face/' + f.substr(2).replace(';', '') + '.gif">');
  628. });
  629. var images = msg.match(/&img\d+;/g);
  630. Ext.each(images, function(m) { //图片
  631. msg = msg.replace(m, '');
  632. });
  633. return msg;
  634. },
  635. /**
  636. * 对话框
  637. * @param id 消息的主键值
  638. * @param otherId 对方人员ID
  639. * @param other 对方人名
  640. * @param date 时间
  641. * @param context 对话内容
  642. */
  643. showDialogBox: function(id, otherId, other, date, context) {
  644. var me = this;
  645. var panel = Ext.getCmp('dialog-win-' + otherId);
  646. if (!panel) {
  647. panel = Ext.create('erp.view.core.window.DialogBox', {
  648. other: other,
  649. otherId: otherId
  650. });
  651. }
  652. if (!Ext.isEmpty(id)) {
  653. panel.insertDialogItem(other, date, context);
  654. if (Ext.getCmp('dialog-min-' + otherId)) {
  655. Ext.getCmp('dialog-min-' + otherId).setText("<font color=red>有新消息...</font>");
  656. } else {
  657. me.updatePagingStatus(id, 1);
  658. }
  659. }
  660. },
  661. /**
  662. * 循环刷新寻呼信息
  663. * @param cycletime 间隔时间 {快速4000(聊天过程中)、中等8000(普通模式)、慢速15000(session中断等异常情况下)}
  664. */
  665. loadPagingRelease: function() {
  666. var me = this;
  667. me.cycletime = me.cycletime || 8000;
  668. if (!Ext.getCmp('lock-win')) {
  669. try {
  670. me.getPagingRelease();
  671. Ext.getCmp('process-lazy').setText('');
  672. } catch (e) {
  673. //需要try catch一下,不然,循环会因出现的异常而中断。网络中断后,如果不刷新主页,而是直接重新登录的话,就不会继续循环刷新寻呼
  674. me._showerr(e);
  675. }
  676. }
  677. setTimeout(function() {
  678. if (me.allowMsg)
  679. me.loadPagingRelease();
  680. }, me.cycletime);
  681. },
  682. /**
  683. * 循环刷新首页
  684. * */
  685. refreshDesk: function() {
  686. var me = this;
  687. var win= Ext.getCmp("content-panel").items.items[0].body.dom.getElementsByTagName('iframe')[0].contentWindow;
  688. if(win && win.Ext){
  689. var desk=win.Ext.ComponentQuery.query('deskportal');
  690. if(desk.length>0) desk[0].fireEvent('datarefresh',desk[0],'autoRefresh');
  691. }
  692. setTimeout(function() {
  693. me.refreshDesk();
  694. }, 120000);
  695. },
  696. _showerr: function(e) {
  697. var me = this;
  698. if (e.code == 101 || e.message == 'NETWORK_ERR' || e.message == 'NETWORK_LAZY' || e.message == 'NETWORK_LOCK') { //NETWORK_ERR
  699. me.cycletime = 20000;
  700. if (e.message == 'NETWORK_ERR') {
  701. showLoginDiv(true);
  702. Ext.getCmp('process-lazy').setText('服务器连接中断,服务器可能已关闭或在重启,尝试连接中...');
  703. } else if (e.message == 'NETWORK_LAZY') {
  704. Ext.getCmp('process-lazy').setText('请求超时8000ms,服务器负荷过大或网络延迟,请暂缓操作,尝试恢复中...');
  705. } else if (e.message == 'NETWORK_LOCK') { //账号被强制锁定
  706. Ext.Ajax.request({
  707. url: basePath + "common/logout.action",
  708. method: 'post',
  709. callback: function(options, success, response) {
  710. var res = Ext.decode(response.responseText);
  711. if (res.success) {
  712. alert('您已被管理员强制注销,请重新登录!');
  713. window.location.reload();
  714. }
  715. }
  716. });
  717. }
  718. }
  719. },
  720. /**
  721. * 获取未读网络寻呼
  722. */
  723. getPagingRelease: function() {
  724. var me = this,
  725. t1 = new Date().getTime();
  726. Ext.Ajax.request({
  727. url: basePath + 'oa/info/getPagingRelease.action',
  728. method: 'get',
  729. timeout: 8000,
  730. callback: function(options, success, response) {
  731. var e = null;
  732. if (success == false) {
  733. var lazy = new Date().getTime() - t1;
  734. if (lazy > 7500) { // 表示超时引起
  735. e = new Error("NETWORK_LAZY");
  736. } else { // 表示服务器连接中断引起
  737. e = new Error("NETWORK_ERR");
  738. }
  739. } else {
  740. me.cycletime = 8000;
  741. }
  742. var localJson = new Ext.decode(response.responseText, true);
  743. if (localJson.exceptionInfo) {
  744. var info = localJson.exceptionInfo;
  745. if (info == 'ERR_NETWORK_SESSIONOUT') {
  746. e = new Error("NETWORK_ERR");
  747. } else if (info == 'ERR_NETWORK_LOCKED') {
  748. e = new Error("NETWORK_LOCK");
  749. } else {
  750. showMessage('警告', info);
  751. }
  752. }
  753. if (e != null) {
  754. me._showerr(e);
  755. return;
  756. }
  757. if (localJson.success) {
  758. if (localJson.IsRemind) {
  759. me.allowMsg = true;
  760. var data = Ext.decode(localJson.data);
  761. if (data != null && data.length > 0) {
  762. Ext.each(data, function(d) {
  763. if(d.pr_istop){
  764. me.showTopWin(d);
  765. }
  766. else{ if (Ext.getCmp('dialog-win-' + d.pr_releaserid)) {
  767. 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);
  768. } else {
  769. 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'),
  770. d.pr_context, 'jsps/oa/info/pagingDetail.jsp?formCondition=prd_idIS' + d.prd_id, d.prd_id, d.currentMaster);
  771. }
  772. }
  773. });
  774. }
  775. } else {
  776. me.allowMsg = false; // 设置为不允许弹消息窗
  777. }
  778. }
  779. }
  780. });
  781. },
  782. /**
  783. * 消息框置顶
  784. * */
  785. showTopWin:function(d){
  786. var iWidth=800,iHeight=550;
  787. var iTop = (window.screen.availHeight-30-iHeight)/2; //获得窗口的垂直位置;
  788. var iLeft = (window.screen.availWidth-10-iWidth)/2; //
  789. 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');
  790. },
  791. /**
  792. * @param id 明细ID
  793. * @param status 待修改状态
  794. */
  795. updatePagingStatus: function(id, status, master) {
  796. Ext.Ajax.request({
  797. url: basePath + 'oa/info/updateStatus.action',
  798. params: {
  799. id: id,
  800. status: status,
  801. master: master
  802. },
  803. method: 'post',
  804. callback: function(options, success, response) {
  805. var localJson = new Ext.decode(response.responseText);
  806. if (localJson.exceptionInfo) {
  807. showError(localJson.exceptionInfo);
  808. return null;
  809. }
  810. }
  811. });
  812. },
  813. /**
  814. * 通讯录
  815. */
  816. showAddrBook: function() {
  817. if (!Ext.getCmp('addrbook-win')) {
  818. Ext.create('Ext.window.Window', {
  819. id: 'addrbook-win',
  820. title: '我的通讯录',
  821. height: screen.height * 0.8,
  822. width: screen.width * 0.2,
  823. renderTo: Ext.getBody(),
  824. animCollapse: false,
  825. constrainHeader: true,
  826. bodyBorder: true,
  827. layout: 'accordion',
  828. border: false,
  829. autoShow: true,
  830. collapsible: true,
  831. x: screen.width * 0.8,
  832. items: [
  833. Ext.create('erp.view.oa.addrBook.AddrBookTree', {
  834. id: 'addr-tree',
  835. title: '联系人'
  836. }), {
  837. title: '设置',
  838. html: '<p>...</p>',
  839. autoScroll: true
  840. }, {
  841. title: '我的应用',
  842. html: '<p>...</p>'
  843. }
  844. ]
  845. });
  846. } else {
  847. Ext.getCmp('addrbook-win').show();
  848. }
  849. },
  850. checkOnline: function(record, e) {
  851. Ext.Ajax.request({
  852. url: 'oa/info/checkOnline.action',
  853. params: {
  854. orgid: Number(record.data.data ? record.data.data.or_id : record.raw.data.or_id)
  855. },
  856. method: 'POST',
  857. callback: function(options, success, response) {
  858. var res = Ext.decode(response.responseText);
  859. var data = res.data;
  860. if (data) {
  861. var count = 0;
  862. var ems = Ext.Array.pluck(data, 'em_id');
  863. Ext.each(record.childNodes, function(node) {
  864. if (Ext.Array.contains(ems, Math.abs(node.data['id']))) {
  865. node.set('iconCls', 'x-tree-icon-happy');
  866. node.set('cls', 'x-tree-cls-node-on');
  867. var d = Ext.Array.filter(data, function(dd) {
  868. return dd.em_id == Math.abs(node.get('id'));
  869. })[0];
  870. node.set('qtip', '<table>' +
  871. '<tr><td>编号:</td><td>' + d.em_code + '</td></tr>' +
  872. '<tr><td>姓名:</td><td>' + d.em_name + '</td></tr>' +
  873. '<tr><td>IP:</td><td>' + d.ip + '</td></tr>' +
  874. '<tr><td>时间:</td><td>' + Ext.Date.format(new Date(d.date), 'Y-m-d H:i:s') + '</td></tr>' +
  875. '</table>');
  876. count++;
  877. } else {
  878. node.set('iconCls', 'x-tree-icon-sad');
  879. node.set('cls', 'x-tree-cls-node-off');
  880. }
  881. });
  882. if (count > 0) {
  883. if (!record.data.oriText) {
  884. record.data.oriText = record.data.text;
  885. }
  886. record.expand(false, true);
  887. }
  888. }
  889. }
  890. });
  891. },
  892. showPwdPanel: function() {
  893. Ext.create('erp.view.core.window.PwdWindow');
  894. },
  895. showActions: function(view, list, node, rowIndex, e) {
  896. var icons = Ext.DomQuery.select('.x-action-col-icon', node),
  897. record = view.getRecord(node);
  898. if (record.get('addurl')) {
  899. Ext.each(icons, function(icon) {
  900. Ext.get(icon).removeCls('x-hidden');
  901. });
  902. }
  903. },
  904. hideActions: function(view, list, node, rowIndex, e) {
  905. var icons = Ext.DomQuery.select('.x-action-col-icon', node),
  906. record = view.getRecord(node);
  907. Ext.each(icons, function(icon) {
  908. Ext.get(icon).addCls('x-hidden');
  909. });
  910. },
  911. handleAddClick: function(view, rowIndex, colIndex, column, e) {
  912. var me=this;
  913. var record = view.getRecord(view.findTargetByEvent(e)),
  914. title = record.get('text');
  915. if (record.get('addurl')) {
  916. openTable(title, record.get('addurl'), record.get('caller'));
  917. me.setCommonUse(record.get('addurl'));
  918. }
  919. }
  920. });