index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. var userRole = 0;
  2. $(function () {
  3. //隐藏角色上的提示红点
  4. $('#role-name-num').hide();
  5. function doSearch(text) {
  6. $('#menutree').tree('search', text);
  7. }
  8. App.init(function () {
  9. document.onkeydown = function (event) {
  10. if (event.ctrlKey && event.keyCode === 191) {
  11. console.log($(document.activeElement));
  12. }
  13. };
  14. $('#body').layout();
  15. $('#treesearch').searchbox({
  16. prompt: '搜索',
  17. searcher: doSearch,
  18. icons: [
  19. {
  20. iconCls: 'icon-clear',
  21. handler: function (e) {
  22. $(e.data.target).textbox('clear').textbox('textbox').focus();
  23. doSearch('');
  24. }
  25. }]
  26. });
  27. $('.easyui-menubutton').menubutton();
  28. // 根据userRole读取不同的菜单
  29. if (userRole == "1") {
  30. $('#menutree').tree({
  31. url: '/app/whepi/mock/menu.json', //api('/menu_tree'),
  32. onDblClick: function (node) {
  33. var $this = $(this);
  34. if (!$this.tree('isLeaf', node.target)) {
  35. $this.tree(node.state === 'closed' ? 'expand' : 'collapse', node.target);
  36. }
  37. },
  38. onSelect: function () {
  39. return false;
  40. },
  41. onClick: function (node) {
  42. var href = node.href;
  43. if ($.trim(href)) {
  44. App.addTab({title: node.text, url: node.href, id: node.id, iconCls: node.iconCls});
  45. }
  46. },
  47. onLoadSuccess: function (node, data) {
  48. }
  49. });
  50. } else if (userRole == "2") {
  51. $('#menutree').tree({
  52. url: '/app/whepi/mock/menu2.json', //api('/menu_tree'),
  53. onDblClick: function (node) {
  54. var $this = $(this);
  55. if (!$this.tree('isLeaf', node.target)) {
  56. $this.tree(node.state === 'closed' ? 'expand' : 'collapse', node.target);
  57. }
  58. },
  59. onSelect: function () {
  60. return false;
  61. },
  62. onClick: function (node) {
  63. var href = node.href;
  64. if ($.trim(href)) {
  65. App.addTab({title: node.text, url: node.href, id: node.id, iconCls: node.iconCls});
  66. }
  67. },
  68. onLoadSuccess: function (node, data) {
  69. }
  70. });
  71. } else if (userRole == "3") {
  72. $('#menutree').tree({
  73. url: '/app/whepi/mock/menu3.json', // 人力资源账户
  74. onDblClick: function (node) {
  75. var $this = $(this);
  76. if (!$this.tree('isLeaf', node.target)) {
  77. $this.tree(node.state === 'closed' ? 'expand' : 'collapse', node.target);
  78. }
  79. },
  80. onSelect: function () {
  81. return false;
  82. },
  83. onClick: function (node) {
  84. var href = node.href;
  85. if ($.trim(href)) {
  86. App.addTab({title: node.text, url: node.href, id: node.id, iconCls: node.iconCls});
  87. }
  88. },
  89. onLoadSuccess: function (node, data) {
  90. }
  91. });
  92. } else if (userRole == "5") {//指挥部登录
  93. $('#menutree').tree({
  94. url: '/app/whepi/mock/menu5.json',
  95. onDblClick: function (node) {
  96. var $this = $(this);
  97. if (!$this.tree('isLeaf', node.target)) {
  98. $this.tree(node.state === 'closed' ? 'expand' : 'collapse', node.target);
  99. }
  100. },
  101. onSelect: function () {
  102. return false;
  103. },
  104. onClick: function (node) {
  105. var href = node.href;
  106. if ($.trim(href)) {
  107. App.addTab({title: node.text, url: node.href, id: node.id, iconCls: node.iconCls});
  108. }
  109. },
  110. onLoadSuccess: function (node, data) {
  111. }
  112. });
  113. } else if (userRole == "6") {//凌云后台菜单
  114. $('#menutree').tree({
  115. url: '/app/whepi/mock/menu6.json',
  116. onDblClick: function (node) {
  117. var $this = $(this);
  118. if (!$this.tree('isLeaf', node.target)) {
  119. $this.tree(node.state === 'closed' ? 'expand' : 'collapse', node.target);
  120. }
  121. },
  122. onSelect: function () {
  123. return false;
  124. },
  125. onClick: function (node) {
  126. var href = node.href;
  127. if ($.trim(href)) {
  128. App.addTab({title: node.text, url: node.href, id: node.id, iconCls: node.iconCls});
  129. }
  130. },
  131. onLoadSuccess: function (node, data) {
  132. }
  133. });
  134. } else if (userRole == "7") {//凌云集团管理员
  135. $('#menutree').tree({
  136. url: '/app/whepi/mock/menu7.json',
  137. onDblClick: function (node) {
  138. var $this = $(this);
  139. if (!$this.tree('isLeaf', node.target)) {
  140. $this.tree(node.state === 'closed' ? 'expand' : 'collapse', node.target);
  141. }
  142. },
  143. onSelect: function () {
  144. return false;
  145. },
  146. onClick: function (node) {
  147. var href = node.href;
  148. if ($.trim(href)) {
  149. App.addTab({title: node.text, url: node.href, id: node.id, iconCls: node.iconCls});
  150. }
  151. },
  152. onLoadSuccess: function (node, data) {
  153. }
  154. });
  155. } else if (userRole == "8") {//湖北和昌管理员
  156. $('#menutree').tree({
  157. url: '/app/whepi/mock/menu8.json',
  158. onDblClick: function (node) {
  159. var $this = $(this);
  160. if (!$this.tree('isLeaf', node.target)) {
  161. $this.tree(node.state === 'closed' ? 'expand' : 'collapse', node.target);
  162. }
  163. },
  164. onSelect: function () {
  165. return false;
  166. },
  167. onClick: function (node) {
  168. var href = node.href;
  169. if ($.trim(href)) {
  170. App.addTab({title: node.text, url: node.href, id: node.id, iconCls: node.iconCls});
  171. }
  172. },
  173. onLoadSuccess: function (node, data) {
  174. }
  175. });
  176. } else if (userRole == "9") {//中建康城管理员
  177. $('#menutree').tree({
  178. url: '/app/whepi/mock/menu9.json',
  179. onDblClick: function (node) {
  180. var $this = $(this);
  181. if (!$this.tree('isLeaf', node.target)) {
  182. $this.tree(node.state === 'closed' ? 'expand' : 'collapse', node.target);
  183. }
  184. },
  185. onSelect: function () {
  186. return false;
  187. },
  188. onClick: function (node) {
  189. var href = node.href;
  190. if ($.trim(href)) {
  191. App.addTab({title: node.text, url: node.href, id: node.id, iconCls: node.iconCls});
  192. }
  193. },
  194. onLoadSuccess: function (node, data) {
  195. }
  196. });
  197. }
  198. $('#mm').menu({
  199. onClick: function (item) {
  200. App.tabMenuOprate(this, item.name);
  201. }
  202. });
  203. $('#tt').tabs({
  204. onContextMenu: function (e, title, index) {
  205. e.preventDefault();
  206. if (index >= 0) {
  207. $('#mm').menu('show', {
  208. left: e.pageX,
  209. top: e.pageY
  210. }).data("tabTitle", title);
  211. }
  212. },
  213. onSelect: function (title, index) {
  214. if (index >= 0) {
  215. var node = $('#tt').tabs('getTab', index).panel('options').node;
  216. if (node && node.id) {
  217. window.location.hash = $.param(node);
  218. node = $('#menutree').tree('find', node.id);
  219. $('#menutree').tree('select', node.target).tree('expandTo', node.target).tree('scrollTo', node.target);
  220. }
  221. }
  222. },
  223. onBeforeClose: function (title, index) {
  224. var tab = $('#tt').tabs('getSelected');
  225. var curTabIndex = $('#tt').tabs('getTabIndex', tab);
  226. if (index === curTabIndex) {
  227. window.location.hash = '';
  228. }
  229. }
  230. });
  231. });
  232. });
  233. var App = {
  234. init: function (success) {
  235. $.yvan.ajax({
  236. url: api("/api/me"),
  237. method: 'get',
  238. loadingMask: false,
  239. success: function (data) {
  240. if(data.data.user){
  241. userRole = data.data.user.userType;
  242. console.log(data.data.user.userType);
  243. }else{
  244. userRole = 0
  245. }
  246. console.log(userRole);
  247. if (!$.trim(data.data.userId)) {
  248. top.window.location.href = jumpApi(YJYDLOGINURL);
  249. return;
  250. }
  251. $('#user-name').html(data.data.staffName);
  252. success();
  253. $("#loading").remove();
  254. },
  255. error: function () {
  256. top.window.location.href = jumpApi(YJYDLOGINURL);
  257. }
  258. });
  259. },
  260. //打开Tab窗口
  261. addTab: function (params) {
  262. var $tt = $('#tt');
  263. if ($tt.tabs('exists', params.title)) {
  264. $tt.tabs('select', params.title);
  265. return;
  266. }
  267. var lastMenuClickTime = $.cookie("menuClickTime");
  268. var nowTime = new Date().getTime();
  269. if ((nowTime - lastMenuClickTime) < 500) {
  270. $.yvan.msg('操作过快,请稍后重试');
  271. return;
  272. }
  273. var id = $.yvan.createId('t');
  274. var iframe;
  275. if (params.url.slice(-3) === '.js') {
  276. iframe = $('<div></div>');
  277. iframe.progress();
  278. } else {
  279. iframe = '<iframe src="' + params.url +
  280. '" scrolling="auto" frameborder="0" style="width:100%;height:100%;"></iframe>';
  281. }
  282. $tt.tabs('add', {
  283. id: id,
  284. title: params.title,
  285. closable: true,
  286. iconCls: $.trim(params.iconCls) ? params.iconCls + ' fa-lg' : 'fa fa-file-text-o',
  287. content: iframe,
  288. border: params.border || true,
  289. fit: true,
  290. node: {
  291. url: params.url,
  292. title: params.title,
  293. id: params.id
  294. }
  295. });
  296. if ($.type(iframe) !== 'string') {
  297. seajs.use([params.url], function (powerOpt) {
  298. if ($.type(powerOpt) === 'function') {
  299. powerOpt = powerOpt();
  300. }
  301. console.log(powerOpt);
  302. $.extend(powerOpt, {
  303. class: 'bizWindow'
  304. });
  305. iframe.parent().power(powerOpt);
  306. iframe.progress('close');
  307. });
  308. }
  309. },
  310. closeMe: function () {
  311. var $tt = $('#tt');
  312. var tab = $tt.tabs('getSelected');
  313. var index = $tt.tabs('getTabIndex', tab);
  314. $tt.tabs("close", index);
  315. },
  316. // Tab菜单操作
  317. tabMenuOprate: function (menu, type) {
  318. var $tt = $('#tt');
  319. var allTabs = $tt.tabs('tabs');
  320. var allTabtitle = [];
  321. $.each(allTabs, function (i, n) {
  322. var opt = $(n).panel('options');
  323. if (opt.closable)
  324. allTabtitle.push(opt.title);
  325. });
  326. var curTabTitle = $(menu).data("tabTitle");
  327. var curTabIndex = $tt.tabs("getTabIndex", $tt.tabs("getTab", curTabTitle));
  328. switch (type) {
  329. case "1": //关闭当前
  330. $tt.tabs("close", curTabTitle);
  331. break;
  332. case "2": //全部关闭
  333. for (var i = 0; i < allTabtitle.length; i++) {
  334. $tt.tabs('close', allTabtitle[i]);
  335. }
  336. break;
  337. case "3": //除此之外全部关闭
  338. for (var i = 0; i < allTabtitle.length; i++) {
  339. if (curTabTitle != allTabtitle[i])
  340. $tt.tabs('close', allTabtitle[i]);
  341. }
  342. $tt.tabs('select', curTabTitle);
  343. $tt.tabs('scrollBy', 0);
  344. break;
  345. case "4": //当前侧面右边
  346. for (var i = curTabIndex; i < allTabtitle.length; i++) {
  347. $tt.tabs('close', allTabtitle[i]);
  348. }
  349. $tt.tabs('select', curTabTitle);
  350. break;
  351. case "5": //当前侧面左边
  352. for (var i = 0; i < curTabIndex - 1; i++) {
  353. $tt.tabs('close', allTabtitle[i]);
  354. }
  355. $tt.tabs('select', curTabTitle);
  356. break;
  357. case "6": //刷新
  358. var currentTab = $tt.tabs('getSelected');
  359. var opts = $.data(currentTab[0], 'panel').options;
  360. if (opts.iframe) {
  361. var currentIframe = currentTab.find('iframe')[0];
  362. currentIframe.contentWindow.location.href = currentIframe.src;
  363. } else {
  364. $(currentTab[0]).panel('refresh');
  365. }
  366. break;
  367. case "7": //在新窗口打开
  368. var refresh_tab = $tt.tabs('getSelected');
  369. var refresh_iframe = refresh_tab.find('iframe')[0];
  370. window.open(refresh_iframe.src);
  371. break;
  372. }
  373. },
  374. //退出登录
  375. logout: function () {
  376. $.cookie('auth', null);
  377. top.window.location.href = jumpApi(YJYDLOGINURL);
  378. },
  379. //修改密码
  380. resetPWD: function () {
  381. var me = this;
  382. seajs.use('/user/resetPWD', function (opt) {
  383. $.yvan.showDialog(me, opt());
  384. });
  385. },
  386. //全屏显示
  387. onFullScreen: function () {
  388. //头部全屏显示
  389. var text = $('.full-screen span').text();
  390. if (text === "全屏显示") {
  391. var el = document.documentElement;
  392. var rfs = el.requestFullScreen || el.webkitRequestFullScreen;
  393. if (typeof rfs !== "undefined" && rfs) {
  394. rfs.call(el);
  395. } else if (typeof window.ActiveXObject !== "undefined") {
  396. var wscript = new ActiveXObject("WScript.Shell");
  397. if (wscript != null) {
  398. wscript.SendKeys("{F11}");
  399. }
  400. } else if (el.msRequestFullscreen) {
  401. el.msRequestFullscreen();
  402. } else if (el.oRequestFullscreen) {
  403. el.oRequestFullscreen();
  404. } else {
  405. $.yvan.msg('浏览器不支持全屏调用!请更换浏览器或按F11键切换全屏!');
  406. }
  407. $('.full-screen span').text('退出全屏');
  408. } else {
  409. var el = document;
  410. var cfs = el.cancelFullScreen || el.webkitCancelFullScreen || el.exitFullScreen;
  411. if (typeof cfs !== "undefined" && cfs) {
  412. cfs.call(el);
  413. } else if (typeof window.ActiveXObject !== "undefined") {
  414. var wscript = new ActiveXObject("WScript.Shell");
  415. if (wscript != null) {
  416. wscript.SendKeys("{F11}");
  417. }
  418. } else if (el.msExitFullscreen) {
  419. el.msExitFullscreen();
  420. } else if (el.oRequestFullscreen) {
  421. el.oCancelFullScreen();
  422. } else {
  423. $.yvan.msg('浏览器不支持全屏调用!请更换浏览器或按F11键切换全屏!');
  424. }
  425. $('.full-screen span').text('全屏显示');
  426. }
  427. }
  428. };