common.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. var webContext = "/ZEUS";
  2. $(document).ready(function(){
  3. });
  4. //设置AJAX全局属性
  5. $.ajaxSetup({
  6. contentType : 'application/x-www-form-urlencoded; charset=UTF-8',
  7. complete : function(XHR, TS) {
  8. var resText = XHR.responseText;
  9. var sessionstatus = XHR.getResponseHeader("sessionstatus");
  10. var loginPath = XHR.getResponseHeader("loginPath");
  11. if (911 == XHR.status && "timeout" == sessionstatus) {
  12. if (window.confirm('session 过期!')) {
  13. window.location.href = webContext+"/toLogin.html";
  14. }
  15. return;
  16. }
  17. }
  18. });
  19. //汉化消息框默认按钮
  20. $.messager.defaults = { ok: "确定", cancel: "取消" };
  21. //扩展jquery
  22. (function($){
  23. /**
  24. * 获取项目上下文路径
  25. */
  26. $.getWebPath = function(){
  27. var strFullPath=window.document.location.href;
  28. var strPath=window.document.location.pathname;
  29. var pos=strFullPath.indexOf(strPath);
  30. var prePath=strFullPath.substring(0,pos);
  31. var postPath=strPath.substring(0,strPath.substr(1).indexOf('/')+1);
  32. return (prePath+postPath);
  33. };
  34. /**
  35. * 获取当前页URL中指定参数名的值,使用decodeURI进行解码
  36. * name:参数名称
  37. */
  38. $.getUrlParam = function(name)
  39. {
  40. var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  41. var r = window.location.search.substr(1).match(reg);
  42. if (r!=null) return decodeURI(r[2]); return "";
  43. };
  44. /**
  45. * 宽度采用百分比
  46. */
  47. $.fixWidth = function (percent){
  48. return Math.floor(document.body.clientWidth * percent) ;
  49. };
  50. /**
  51. * 取textarea标签中光标选中内容
  52. * id:textarea标签的ID属性值
  53. * 返回JOSN对象
  54. */
  55. $.getTextAreaSelected = function(id)
  56. {
  57. var textAreaSelected = ""; //选中内容
  58. var selectionStart = 0; //开始位置
  59. var selectionEnd = 0; //结束位置
  60. var element = document.getElementById(id);
  61. if (!window.getSelection) {
  62. //alert('IE');
  63. //IE浏览器
  64. textAreaSelected = document.selection.createRange().text;
  65. selectionStart = element.selectionStart;
  66. selectionEnd = element.selectionEnd;
  67. //alert(selectionStart);
  68. //alert(selectionEnd);
  69. } else {
  70. //alert('FF');
  71. selectionStart = element.selectionStart;
  72. selectionEnd = element.selectionEnd;
  73. textAreaSelected = element.value.substr(selectionStart, selectionEnd - selectionStart);
  74. }
  75. //如果当前没有选中,则取全部textarea的内容
  76. if(textAreaSelected.replace(/(^\s*)|(\s*$)/g, "")==""){
  77. textAreaSelected = element.value;
  78. selectionStart = 0;
  79. selectionEnd = textAreaSelected.length;
  80. }
  81. //alert(textAreaSelected);
  82. return {"textAreaSelected":textAreaSelected,"selectionStart":selectionStart,"selectionEnd":selectionEnd};
  83. };
  84. /**
  85. * 选中textarea中指定的内容
  86. * id:textarea标签的ID属性值
  87. * obj:json对象
  88. */
  89. $.setTextAreaSelected = function(id, obj) {
  90. var textObj = document.getElementById(id);
  91. if (textObj.createTextRange) {
  92. var textFeildValue = obj.textAreaSelected;
  93. var len = textFeildValue.length;
  94. var textObj = document.getElementById(id);
  95. var value = textObj.value;
  96. var index = value.indexOf(textFeildValue);
  97. //IE浏览器
  98. var range = textObj.createTextRange();
  99. range.moveEnd("character", -1 * value.length);
  100. range.moveEnd("character", index + len);
  101. range.moveStart("character", index);
  102. range.select();
  103. } else {
  104. textObj.setSelectionRange(obj.selectionStart, obj.selectionEnd);
  105. textObj.focus();
  106. }
  107. };
  108. /**
  109. * 文本框自适应大小
  110. */
  111. $.autoTextarea = function (elem)
  112. {
  113. elem.style.resize = 'none';
  114. minHeight = elem.currentStyle ?
  115. parseFloat(elem.currentStyle['height']) : parseFloat(document.defaultView.getComputedStyle(elem, null)['height']);
  116. var adjust = function () {
  117. if (elem._length === elem.value.length) return;
  118. elem._length = elem.value.length;
  119. elem.style.height = minHeight + 'px';
  120. if (elem.scrollHeight > minHeight)
  121. {
  122. elem.style.overflowY = 'hidden';
  123. elem.style.height = elem.scrollHeight + 'px';
  124. }
  125. };
  126. addEvent = function (type, callback) {
  127. elem.addEventListener ?
  128. elem.addEventListener(type, callback, false) :
  129. elem.attachEvent('on' + type, callback);
  130. };
  131. addEvent('keydown', adjust);
  132. addEvent('keyup', adjust);
  133. addEvent('propertyadjust', adjust);
  134. addEvent('input', adjust);
  135. addEvent('focus', adjust);
  136. adjust();
  137. };
  138. })(jQuery);
  139. //封装jquery公共插件
  140. jQuery.common = {
  141. /**
  142. * 常量
  143. */
  144. CONSTANT:{
  145. /*
  146. * 状态
  147. */
  148. METHOD_STATUS_1:"1",//已上线
  149. METHOD_STATUS_2:"2",//测试中
  150. METHOD_STATUS_F1:"-1",//已停用
  151. /*
  152. * 返回值类型
  153. */
  154. METHOD_RESULT_TYPE_0:"0",//json格式字符串
  155. METHOD_RESULT_TYPE_0_TEXT:"json",
  156. METHOD_RESULT_TYPE_1:"1",//XML格式字符串
  157. METHOD_RESULT_TYPE_1_TEXT:"XML",
  158. },//常量 end
  159. url:$.getWebPath(),//+"/servlet/ActionServlet",//ActionServlet请求地址
  160. urlByBizAction:function (bizAction){
  161. return this.url+"/"+bizAction+".action?ST="+new Date().getTime();
  162. },
  163. urlByJsonParam:function (bizAction,json){
  164. return this.url+"/"+bizAction+".action?"+$.param(json)+"&ST="+new Date().getTime();
  165. },
  166. /**
  167. * session
  168. */
  169. getMySession:function(){
  170. var sessionVar = {
  171. my_session_user : {},
  172. my_session_db : {},
  173. my_session_UserOtherInfo : {
  174. userHostName : '',
  175. userIp : ''
  176. },
  177. my_session_UserPermission : {
  178. menu : [],
  179. fun : []
  180. },
  181. };
  182. var url = $.getWebPath()+"/ActionServlet_doPost.action";
  183. var param = {};
  184. param.bizAction = "mySession!getMySession";
  185. $.ajax({
  186. type: "POST",
  187. url: url,
  188. data: param,
  189. dataType: "json",
  190. cache: false,
  191. async:false,
  192. success: function(data){
  193. if(data.Code==1){
  194. sessionVar = $.extend(sessionVar, data);
  195. }else{
  196. alert('session获取失败!');
  197. }
  198. }
  199. });
  200. return sessionVar;
  201. },
  202. removeMySession:function(fn){
  203. var url = $.getWebPath()+"/ActionServlet_doPost.action";
  204. var param = {};
  205. param.bizAction = "mySession!removeMySession";
  206. $.ajax({
  207. type: "POST",
  208. url: url,
  209. data: param,
  210. dataType: "json",
  211. cache: false,
  212. async:false,
  213. success: function(data){
  214. if(data.Code==1){
  215. if(fn){
  216. fn();
  217. }
  218. }else{
  219. // alert('注销session失败!');
  220. $.common.showMessage(data);
  221. }
  222. }
  223. });
  224. },
  225. showMessage:function(data,str){// error,question,info,warning
  226. $.messager.defaults = { ok: "确定", cancel: "取消" };
  227. if(data.Code == -100){
  228. $.messager.alert("系统提示",(typeof str == "undefined"?"登录已失效或未登录,请重新登录系统!":str),'info',function(){
  229. //top.location.href = $.getWebPath()+"/login.html";
  230. window.top.loginAgain();
  231. });
  232. }else if(data.Code==-1){
  233. $.messager.alert("异常",(typeof str == "undefined"?"系统异常":str)+":"+data.Message,'error');
  234. }else if(data.Code==-2){
  235. $.messager.alert("提示",(typeof str == "undefined"?"系统提示":str)+":"+data.Message,'info');
  236. }else if(data.Code==-3){
  237. $.messager.alert("警告",(typeof str == "undefined"?"系统警告":str)+":"+data.Message,'warning');
  238. }else{
  239. $.messager.alert("",(typeof str == "undefined"?"":str)+":"+data.Message,'question');
  240. }
  241. },
  242. closeAllTabs:function(tabId){//关闭所有选项卡
  243. var object = $('#'+tabId).tabs('tabs');
  244. var length = object.length;
  245. if(length > 0){
  246. $.messager.confirm("操作提示","确定关闭所有选项卡?",function(r){
  247. if (r){
  248. for(var i=0; i<length; i++) {
  249. var onetab = object[0];
  250. var title = onetab.panel('options').title;
  251. //console.info(title);
  252. $('#'+tabId).tabs('close', title);
  253. }
  254. }
  255. });
  256. }
  257. },
  258. /*
  259. * 字典表
  260. */
  261. DICT:{
  262. url:$.getWebPath(),
  263. // loadSelect : function(id, param, defaultValue) {
  264. // $.post(this.url, param, function(result) {
  265. // if(result.result){
  266. // $('#' + id).combobox('loadData', result.result);
  267. // if (defaultValue != null && defaultValue != '') {
  268. // $('#' + id).combobox('setValue', defaultValue);
  269. // }
  270. // }else{
  271. // $.common.showMessage(result);
  272. // }
  273. // }, "json");
  274. // },
  275. // loadDictSelect : function(id, businTypeID, defaultValue) {
  276. // var param = {};
  277. // param.bizAction = "dictAction.getDict";
  278. // param.businTypeID = businTypeID;
  279. // param.emptyText = '--请选择--';
  280. // $.post(this.url, param, function(result) {
  281. // if(result.result){
  282. // $('#' + id).combobox('loadData', result.result);
  283. // if (defaultValue != null && defaultValue != '') {
  284. // $('#' + id).combobox('setValue', defaultValue);
  285. // }
  286. // }else{
  287. // $.common.showMessage(result);
  288. // }
  289. // }, "json");
  290. // },
  291. loadDict : function(businTypeID,actionName) {
  292. var res;
  293. $.ajax( {
  294. url : this.url+"/DictAction_getDict",
  295. data : {
  296. businTypeID : businTypeID
  297. },
  298. cache : false,
  299. async : false,
  300. type : "POST",
  301. dataType : 'json',
  302. success : function(data) {
  303. if(data.Result){
  304. res = data.Result;
  305. }else{
  306. $.common.showMessage(data);
  307. }
  308. }
  309. });
  310. // console.info(res);
  311. return res;
  312. },
  313. loadComboboxByData : function (id, result, defaultValue){
  314. $('#' + id).combobox('loadData', result);
  315. if (defaultValue != null && defaultValue != '') {
  316. $('#' + id).combobox('setValue', defaultValue);
  317. }
  318. },
  319. loadDictToArray : function(result){
  320. var res = new Object;
  321. for ( var iterable_element in result) {
  322. res[result[iterable_element].businID] = result[iterable_element].businName;
  323. }
  324. return res;
  325. }
  326. },
  327. //DICT end
  328. /**
  329. * 下拉框操作
  330. */
  331. Combobox:{
  332. defaults : {
  333. id:"",//下拉ID
  334. value:"",//下拉选择项值名称
  335. text:"",//下拉选择项文本名称
  336. jsonArray:new Array(),//下拉选择项数据:JSON对象组成的数组
  337. key:"",//关系字段
  338. defaultValue:"",//默认选择值
  339. addDefaultRecord:{//添加默认选项卡
  340. value:"",
  341. text:"--请选择--"
  342. },
  343. appendText:"",//在text后追加的内容字符串,该内容支持正则表达式/{this.*}/来匹配jsonArray数组中的每个对象中的某一个属性字段
  344. prependText:"",//在text前追加的内容字符串,同上
  345. },
  346. init: function (combobox){
  347. var c = $.extend({},this.defaults,combobox);
  348. var arr = new Array();
  349. // if(c.value+"" == c.text+""){
  350. var valueField = c.value;
  351. var textField = c.text;
  352. c.value = (valueField + "_V");
  353. c.text = (textField + "_T");
  354. //jsonArray 重组
  355. var regexp = /\{this\.[^{}]+\}/g;
  356. $.each(c.jsonArray,function(i,v){
  357. var value = eval("v."+valueField);
  358. var text = eval("v."+textField);
  359. var str = '{';
  360. str += '"'+c.value+'":"'+value+'","'+c.text+'":"'+text+'"';
  361. if(c.key){
  362. var keyArr = c.key.split(",");
  363. var key = "";
  364. $.each(keyArr,function(ii,keyName){
  365. if(keyName.length>0){
  366. var key = eval("v."+keyName);
  367. str += ','+'"'+keyName+'":"'+key+'"';
  368. }
  369. });
  370. // var key = eval("v."+c.key);
  371. // str += ','+'"'+c.key+'":"'+key+'"';
  372. }
  373. var appendText = c.appendText;
  374. if(typeof(appendText) != "undefined" && appendText != ""){
  375. var exp = appendText.match(regexp);
  376. // console.info(regexp);
  377. // console.info(appendText);
  378. // console.info(exp);
  379. $.each(exp,function(ii,vv){
  380. var temp = vv.replace("\{this","v").replace("\}","");
  381. // console.info(temp);
  382. // console.info(eval(temp));
  383. var t = typeof(eval(temp))=="undefined"?"":eval(temp);
  384. appendText = appendText.replace(vv,t);
  385. // console.info(appendText);
  386. });
  387. str += ','+'"appendText":"'+appendText+'"';
  388. }
  389. if(c.prependText){
  390. var prependText = eval(c.prependText);
  391. if(typeof(prependText) != "undefined"){
  392. str += ','+'"prependText":"'+prependText+'"';
  393. }
  394. }
  395. str += '}';
  396. arr.push($.parseJSON(str));
  397. });
  398. // }
  399. if(typeof(c.addDefaultRecord.value)!="undefined"){
  400. //添加默认选项卡
  401. var str = '{"'+c.value+'":"'+c.addDefaultRecord.value+'","'+c.text+'":"'+c.addDefaultRecord.text+'"}';
  402. arr.unshift($.parseJSON(str));
  403. }
  404. c.jsonArray = arr;
  405. // console.info(c.jsonArray);
  406. return c;
  407. },
  408. //格式化输出
  409. formatterRow : function(thiss,row){
  410. var opts = $(thiss).combobox('options');
  411. var rs = row[opts.textField];
  412. if(typeof(row.appendText)!="undefined" && row.appendText != ""){
  413. rs += row.appendText;
  414. }
  415. if(typeof(row.prependText)!="undefined" && row.prependText != ""){
  416. rs = row.prependText + rs;
  417. }
  418. return rs;
  419. },
  420. //单个下拉杠
  421. load : function(c){
  422. var combobox = this.init(c);
  423. $("#"+combobox.id).combobox({
  424. valueField:combobox.value,
  425. textField:combobox.text,
  426. data:combobox.jsonArray,
  427. formatter: function(row){
  428. return $.common.Combobox.formatterRow(this,row);
  429. }
  430. });
  431. },
  432. //创建 下一级联动下拉框
  433. createNextCombobox : function(key,combobox){
  434. var temp = new Array();
  435. if(typeof(key)!="undefined" && key != ""){
  436. if(typeof(combobox.addDefaultRecord.value)!="undefined"){
  437. //添加默认选项卡
  438. temp.push($.parseJSON('{"'+combobox.value+'":"'+combobox.addDefaultRecord.value+'","'+combobox.text+'":"'+combobox.addDefaultRecord.text+'"}'));
  439. }
  440. $.each(combobox.jsonArray,function(i,v){
  441. if(key+"" == eval("v."+combobox.key)+""){
  442. temp.push(v);
  443. }
  444. });
  445. // console.info(temp);
  446. }else{
  447. temp = combobox.jsonArray;
  448. }
  449. $("#"+combobox.id).combobox({
  450. valueField:combobox.value,
  451. textField:combobox.text,
  452. data:temp,
  453. formatter: function(row){
  454. return $.common.Combobox.formatterRow(this,row);
  455. }
  456. }).combobox('select',combobox.defaultValue);
  457. },
  458. //二级联动
  459. load2 : function (c1,c2){
  460. var combobox1 = this.init(c1);
  461. var combobox2 = this.init(c2);
  462. $("#"+combobox1.id).combobox({
  463. valueField:combobox1.value,
  464. textField:combobox1.text,
  465. data:combobox1.jsonArray,
  466. onSelect:function(record){
  467. var key1 = eval("record."+combobox1.key);
  468. $.common.Combobox.createNextCombobox(key1,combobox2);
  469. },
  470. formatter: function(row){
  471. return $.common.Combobox.formatterRow(this,row);
  472. }
  473. }).combobox('select',combobox1.defaultValue);
  474. var keyValue = "";
  475. if(combobox1.defaultValue){
  476. $.each(combobox1.jsonArray,function(i,v){
  477. var temp = eval("v."+combobox1.value);
  478. if(temp == combobox1.defaultValue){
  479. keyValue = eval("v."+combobox1.key);
  480. return;
  481. }
  482. });
  483. }
  484. this.createNextCombobox(keyValue,combobox2);
  485. },
  486. //三级联动
  487. load3 : function (c1,c2,c3){
  488. var combobox1 = this.init(c1);
  489. var combobox2 = this.init(c2);
  490. var combobox3 = this.init(c3);
  491. $("#"+combobox1.id).combobox({
  492. valueField:combobox1.value,
  493. textField:combobox1.text,
  494. data:combobox1.jsonArray,
  495. onSelect:function(record){
  496. var key1 = eval("record."+combobox1.key);
  497. var temp = new Array();
  498. if(typeof(key1)!="undefined" && key1 != ""){
  499. if(typeof(combobox2.addDefaultRecord.value)!="undefined"){
  500. //添加默认选项卡
  501. temp.push($.parseJSON('{"'+combobox2.value+'":"'+combobox2.addDefaultRecord.value+'","'+combobox2.text+'":"'+combobox2.addDefaultRecord.text+'"}'));
  502. }
  503. $.each(combobox2.jsonArray,function(i,v){
  504. var key2Str = combobox2.key;
  505. var key2Arr = key2Str.split(",");
  506. var key2 = key2Arr[0];
  507. if(key1+"" == eval("v."+key2)+""){
  508. temp.push(v);
  509. }
  510. });
  511. // console.info(temp);
  512. }else{
  513. temp = combobox2.jsonArray;
  514. }
  515. $("#"+combobox2.id).combobox({
  516. valueField:combobox2.value,
  517. textField:combobox2.text,
  518. data:temp,
  519. formatter: function(row){
  520. return $.common.Combobox.formatterRow(this,row);
  521. }
  522. }).combobox('select',combobox2.defaultValue);
  523. $("#"+combobox3.id).combobox({
  524. valueField:combobox3.value,
  525. textField:combobox3.text,
  526. data:combobox3.jsonArray,
  527. formatter: function(row){
  528. return $.common.Combobox.formatterRow(this,row);
  529. }
  530. }).combobox('select',combobox3.defaultValue);
  531. },
  532. formatter: function(row){
  533. return $.common.Combobox.formatterRow(this,row);
  534. }
  535. }).combobox('select',combobox1.defaultValue);
  536. $("#"+combobox2.id).combobox({
  537. valueField:combobox2.value,
  538. textField:combobox2.text,
  539. data:combobox2.jsonArray,
  540. onSelect:function(record){
  541. var key2Str = combobox2.key;
  542. var key2Arr = key2Str.split(",");
  543. var key = key2Arr[1];
  544. var key2 = eval("record."+key);
  545. var temp = new Array();
  546. if(typeof(key2)!="undefined" && key2 != ""){
  547. if(typeof(combobox3.addDefaultRecord.value)!="undefined"){
  548. //添加默认选项卡
  549. temp.push($.parseJSON('{"'+combobox3.value+'":"'+combobox3.addDefaultRecord.value+'","'+combobox3.text+'":"'+combobox3.addDefaultRecord.text+'"}'));
  550. }
  551. $.each(combobox3.jsonArray,function(i,v){
  552. if(key2+"" == eval("v."+combobox3.key)+""){
  553. temp.push(v);
  554. }
  555. });
  556. // console.info(temp);
  557. }else{
  558. temp = combobox3.jsonArray;
  559. }
  560. $("#"+combobox3.id).combobox({
  561. valueField:combobox3.value,
  562. textField:combobox3.text,
  563. data:temp,
  564. formatter: function(row){
  565. return $.common.Combobox.formatterRow(this,row);
  566. }
  567. }).combobox('select',combobox3.defaultValue);
  568. },
  569. formatter: function(row){
  570. return $.common.Combobox.formatterRow(this,row);
  571. }
  572. }).combobox('select',combobox2.defaultValue);
  573. $("#"+combobox3.id).combobox({
  574. valueField:combobox3.value,
  575. textField:combobox3.text,
  576. data:combobox3.jsonArray,
  577. formatter: function(row){
  578. return $.common.Combobox.formatterRow(this,row);
  579. }
  580. }).combobox('select',combobox3.defaultValue);
  581. }
  582. },
  583. //commobox end
  584. /**
  585. * 生成树
  586. */
  587. Tree:{
  588. /*
  589. * 节点
  590. */
  591. treeNode:{
  592. id:"",
  593. text:"",
  594. state:"open",
  595. checked:false,
  596. attributes:"",
  597. children:new Array(),
  598. pid:""
  599. },
  600. init: function(treeNodeArray,checkedArray){
  601. var arr = new Array();
  602. $.each(treeNodeArray,function(i,v){
  603. var node = $.extend({},$.common.Tree.treeNode,v);
  604. if($.inArray(node.id,checkedArray)!=-1){
  605. node.checked = true;
  606. }
  607. if(typeof(node.pid) == "undefined" || node.pid == "" || node.pid == "0"){//根
  608. arr.push(node);
  609. }else{
  610. $.each(treeNodeArray,function(ii,vv){
  611. if(node.pid == vv.id){
  612. arr.push(node);
  613. }
  614. });
  615. }
  616. });
  617. return arr;
  618. },
  619. createChildrenNode:function(treeNodeArray,parentNode){
  620. //找子节点
  621. var childrenArray = new Array();
  622. $.each(treeNodeArray,function(i,v){
  623. if(parentNode.id == v.pid){
  624. $.common.Tree.createChildrenNode(treeNodeArray, v);
  625. childrenArray.push(v);
  626. }
  627. });
  628. parentNode.children = childrenArray;
  629. },
  630. /**
  631. * 构建树的data数据
  632. * @param treeNodeArray 节点数组
  633. */
  634. createData:function(treeNodeArray,checkedArray){
  635. var treeNodeArray = this.init(treeNodeArray,checkedArray);
  636. var treeData = new Array();
  637. $.each(treeNodeArray,function(i,v){
  638. if(typeof(v.pid) == "undefined" || v.pid == "" || v.pid == "0"){//根
  639. $.common.Tree.createChildrenNode(treeNodeArray,v);
  640. treeData.push(v);
  641. }
  642. });
  643. // console.info(treeNodeArray);
  644. // console.info(treeData);
  645. return treeData;
  646. }
  647. },
  648. /**
  649. * 权限控制
  650. */
  651. Permission:{
  652. HAS_INIT_MENU:false,
  653. HAS_INIT_FUN:false,
  654. menuPmssData:new Array(),
  655. funPmssData:new Array(),
  656. //初始化菜单
  657. initMenu:function(){
  658. //菜单权限
  659. var menuPmss={
  660. menuId:-1,
  661. parentsId:-1,//当为1时为一级节点
  662. menuName:"",
  663. uri:"",//"api/index_api.html?INDEX_PAGE=api_release.html"
  664. // isPmss:true,//true:允许
  665. isDefaultPage:false,//false:未设置为默认页
  666. };
  667. if(!this.HAS_INIT_MENU){
  668. //session中取
  669. this.menuPmssData=new Array();
  670. var session = $.common.getMySession();
  671. // console.info(session);
  672. var menu = session.my_session_UserPermission.menuList;
  673. $.each(menu,function(i,v){
  674. var temp = {
  675. menuId:v.menuId,
  676. parentsId:v.parentsID,
  677. menuName:v.menuName,
  678. uri:v.menuAction,
  679. // isPmss:v.isPmss==1?true:false,//true:允许
  680. isDefaultPage:v.isDefaultPage==1?true:false,//false:未设置为默认页
  681. };
  682. temp = $.extend({},menuPmss,temp);
  683. $.common.Permission.menuPmssData.push(temp);
  684. });
  685. this.HAS_INIT_MENU = true;
  686. }
  687. },
  688. //初始功能
  689. initFun:function(){
  690. //功能权限
  691. var funPmss={
  692. funName:"",
  693. uri:"",//bizAction{jQuery选择器表达式}{}{};bizAction{jQuery选择器表达式}
  694. isPmss:true,//true:允许
  695. };
  696. if(!this.HAS_INIT_FUN){
  697. //session中取
  698. this.funPmssData =new Array();
  699. var session = $.common.getMySession();
  700. // console.info(session);
  701. var fun = session.my_session_UserPermission.funList;
  702. $.each(fun,function(i,v){
  703. var temp = {
  704. funName:v.actionName,
  705. uri:v.actionURI,
  706. isPmss:v.isPmss==1?true:false,//true:允许
  707. };
  708. temp = $.extend({},funPmss,temp);
  709. $.common.Permission.funPmssData.push(temp);
  710. });
  711. this.HAS_INIT_FUN = true;
  712. }
  713. },
  714. //获取菜单
  715. getMenuPmssData:function(initFlag){
  716. if(initFlag){
  717. this.HAS_INIT_MENU = false;
  718. }
  719. this.initMenu();
  720. return this.menuPmssData;
  721. },
  722. //根据父ID查找
  723. getMenuPmssDataByParentsId:function(parentsId){
  724. this.initMenu();
  725. var menu = this.menuPmssData;
  726. var data = new Array();
  727. $.each(menu,function(i,v){
  728. if(v.parentsId == parentsId){
  729. data.push(v);
  730. }
  731. });
  732. return data;
  733. },
  734. //获取功能
  735. getFunPmssData:function(initFlag){
  736. if(initFlag){
  737. this.HAS_INIT_FUN = false;
  738. }
  739. this.initFun();
  740. return this.funPmssData;
  741. }
  742. }
  743. };