SysPanel.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. Ext.define('erp.view.common.sysinit.SysPanel',{
  2. extend: 'Ext.panel.Panel',
  3. alias: 'widget.syspanel',
  4. id:'syspanel',
  5. animCollapse: false,
  6. constrainHeader: true,
  7. bodyBorder: true,
  8. layout: 'accordion',
  9. border: false,
  10. autoShow: true,
  11. collapsible : true,
  12. title:'初始化导航',
  13. bodyStyle:'background-color:#f1f1f1;',
  14. initComponent : function(){
  15. this.getNodes(0,this);
  16. this.callParent(arguments);
  17. },
  18. getNodes: function(pid,p){
  19. var me = this;
  20. Ext.Ajax.request({//拿到tree数据
  21. url : basePath + 'system/initTree.action',
  22. params: {
  23. pid: pid
  24. },
  25. callback : function(options,success,response){
  26. var res = new Ext.decode(response.responseText);
  27. if(res.tree){
  28. Ext.each(res.tree, function(t){
  29. p.add({
  30. title: t.in_desc,
  31. autoScroll: true,
  32. caller: t.in_caller,
  33. id: t.in_id,
  34. listeners: {
  35. expand: function(n){
  36. if(n.items.items.length == 0){
  37. me.getTreeNode(n);
  38. }
  39. }
  40. }
  41. });
  42. });
  43. var n = p.items.items[0];
  44. if(n && n.items.items.length == 0) {
  45. me.getTreeNode(n);
  46. }
  47. }else if(res.exceptionInfo){
  48. showError(res.exceptionInfo);
  49. }
  50. }
  51. });
  52. },
  53. getTreeNode: function(node){
  54. var me = this;
  55. Ext.Ajax.request({// 拿到tree数据
  56. url : basePath + 'system/initTree.action',
  57. params: {
  58. pid: node.id
  59. },
  60. callback : function(options,success,response){
  61. var res = new Ext.decode(response.responseText);
  62. if(res.tree){
  63. var tree = me.parseTree(res.tree);
  64. node.add({
  65. xtype: 'treepanel',
  66. height: '100%',
  67. rootVisible: false,
  68. containerScroll : true,
  69. autoScroll: false,
  70. border:false,
  71. store: Ext.create('Ext.data.TreeStore', {
  72. root: {
  73. text: 'root',
  74. id: 'root',
  75. expanded: true,
  76. children: tree
  77. }
  78. }),
  79. listeners: {
  80. itemmousedown: function(selModel, record){
  81. //Ext.getCmp('template').setTitle(me.getPathString(selModel.ownerCt, record));
  82. //me.getNode(record);
  83. me.OpenUrl(record);
  84. me.currentRecord=record;
  85. }
  86. }
  87. });
  88. } else if(res.exceptionInfo){
  89. showError(res.exceptionInfo);
  90. }
  91. }
  92. });
  93. },
  94. listeners: {
  95. scrollershow: function(scroller) {
  96. if (scroller && scroller.scrollEl) {
  97. scroller.clearManagedListeners();
  98. scroller.mon(scroller.scrollEl, 'scroll', scroller.onElScroll, scroller);
  99. }
  100. }
  101. },
  102. parseTree: function(arr){
  103. var tree = new Array(),t;
  104. Ext.each(arr, function(r){
  105. t = new Object();
  106. t.id = r.in_id;
  107. t.text = r.in_desc;
  108. t.qtip = r.in_desc;
  109. t.caller = r.in_caller;
  110. t.img = r.in_img;
  111. t.parentId = r.in_pid;
  112. t.leaf = r.in_leaf == 1;
  113. t.url =r.in_url;
  114. t.description=r.in_description;
  115. tree.push(t);
  116. });
  117. return tree;
  118. },
  119. OpenUrl:function(record){
  120. var me = this,id=record.get('id');
  121. var panel = Ext.getCmp(id),main = Ext.getCmp("content-panel");
  122. if(!panel){
  123. var url = me.parseUrl(record.raw['url']);//解析url里的特殊描述
  124. panel = {
  125. title : record.get('qtip').length>5?(record.get('qtip').substring(0,5)+'..'):record.get('qtip'),
  126. tag : 'iframe',
  127. tabConfig: {tooltip:record.get('qtip')},
  128. border : false,
  129. frame: false,
  130. layout : 'fit',
  131. iconCls : record.data.iconCls,
  132. html : '<iframe id="iframe_' + id + '" src="' + basePath + url + '" height="100%" width="100%" frameborder="0" style="border-width: 0px;padding: 0px;" scrolling="auto"></iframe>',
  133. closable : true,
  134. listeners : {
  135. close : function(){
  136. var main = Ext.getCmp("content-panel");
  137. main.setActiveTab(Ext.getCmp("HomePage"));
  138. }
  139. }
  140. };
  141. this.openTab(panel, record.get('id'), url);
  142. } else{
  143. main.setActiveTab(panel);
  144. }
  145. },
  146. parseUrl: function(url){
  147. var id = url.substring(url.lastIndexOf('?')+1);//将作为新tab的id
  148. if (id == null) {
  149. id = url.substring(0,url.lastIndexOf('.'));
  150. }
  151. if(contains(url, 'session:em_uu', true)){//对url中session值的处理
  152. url = url.replace(/session:em_uu/g,em_uu);
  153. }
  154. if(contains(url, 'session:em_code', true)){//对url中em_code值的处理
  155. url = url.replace(/session:em_code/g, "'" + em_code + "'");
  156. }
  157. if(contains(url, 'sysdate', true)){//对url中系统时间sysdate的处理
  158. url = url.replace(/sysdate/g, "to_date('" + Ext.Date.toString(new Date()) + "','yyyy-mm-dd')");
  159. }
  160. if(contains(url, 'session:em_name', true)){
  161. url = url.replace(/session:em_name/g,"'"+em_name+"'" );
  162. }
  163. return url;
  164. },
  165. openTab : function (panel, id, url){
  166. var o = (typeof panel == "string" ? panel : id || panel.id);
  167. var main = Ext.getCmp("content-panel");
  168. var tab = main.getComponent(o);
  169. if (tab) {
  170. main.setActiveTab(tab);
  171. } else if(typeof panel!="string"){
  172. panel.id = o;
  173. var p = main.add(panel);
  174. main.setActiveTab(p);
  175. }
  176. }
  177. });