index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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 == "5") {//指挥部登录
  72. $('#menutree').tree({
  73. url: '/app/whepi/mock/menu5.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 == "6") {//凌云后台菜单
  93. $('#menutree').tree({
  94. url: '/app/whepi/mock/menu6.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 == "7") {//凌云集团管理员
  114. $('#menutree').tree({
  115. url: '/app/whepi/mock/menu7.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 == "8") {//湖北和昌管理员
  135. $('#menutree').tree({
  136. url: '/app/whepi/mock/menu8.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 == "9") {//中建康城管理员
  156. $('#menutree').tree({
  157. url: '/app/whepi/mock/menu9.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. }
  177. $('#mm').menu({
  178. onClick: function (item) {
  179. App.tabMenuOprate(this, item.name);
  180. }
  181. });
  182. $('#tt').tabs({
  183. onContextMenu: function (e, title, index) {
  184. e.preventDefault();
  185. if (index >= 0) {
  186. $('#mm').menu('show', {
  187. left: e.pageX,
  188. top: e.pageY
  189. }).data("tabTitle", title);
  190. }
  191. },
  192. onSelect: function (title, index) {
  193. if (index >= 0) {
  194. var node = $('#tt').tabs('getTab', index).panel('options').node;
  195. if (node && node.id) {
  196. window.location.hash = $.param(node);
  197. node = $('#menutree').tree('find', node.id);
  198. $('#menutree').tree('select', node.target).tree('expandTo', node.target).tree('scrollTo', node.target);
  199. }
  200. }
  201. },
  202. onBeforeClose: function (title, index) {
  203. var tab = $('#tt').tabs('getSelected');
  204. var curTabIndex = $('#tt').tabs('getTabIndex', tab);
  205. if (index === curTabIndex) {
  206. window.location.hash = '';
  207. }
  208. }
  209. });
  210. });
  211. });
  212. var App = {
  213. init: function (success) {
  214. $.yvan.ajax({
  215. url: api("/api/me"),
  216. method: 'get',
  217. loadingMask: false,
  218. success: function (data) {
  219. userRole = data.data.user.userType;
  220. console.log(data.data.user.userType);
  221. if (!$.trim(data.data.userId)) {
  222. top.window.location.href = jumpApi(YJYDLOGINURL);
  223. return;
  224. }
  225. $('#user-name').html(data.data.staffName);
  226. success();
  227. $("#loading").remove();
  228. },
  229. error: function () {
  230. top.window.location.href = jumpApi(YJYDLOGINURL);
  231. }
  232. });
  233. },
  234. //打开Tab窗口
  235. addTab: function (params) {
  236. var $tt = $('#tt');
  237. if ($tt.tabs('exists', params.title)) {
  238. $tt.tabs('select', params.title);
  239. return;
  240. }
  241. var lastMenuClickTime = $.cookie("menuClickTime");
  242. var nowTime = new Date().getTime();
  243. if ((nowTime - lastMenuClickTime) < 500) {
  244. $.yvan.msg('操作过快,请稍后重试');
  245. return;
  246. }
  247. var id = $.yvan.createId('t');
  248. var iframe;
  249. if (params.url.slice(-3) === '.js') {
  250. iframe = $('<div></div>');
  251. iframe.progress();
  252. } else {
  253. iframe = '<iframe src="' + params.url +
  254. '" scrolling="auto" frameborder="0" style="width:100%;height:100%;"></iframe>';
  255. }
  256. $tt.tabs('add', {
  257. id: id,
  258. title: params.title,
  259. closable: true,
  260. iconCls: $.trim(params.iconCls) ? params.iconCls + ' fa-lg' : 'fa fa-file-text-o',
  261. content: iframe,
  262. border: params.border || true,
  263. fit: true,
  264. node: {
  265. url: params.url,
  266. title: params.title,
  267. id: params.id
  268. }
  269. });
  270. if ($.type(iframe) !== 'string') {
  271. seajs.use([params.url], function (powerOpt) {
  272. if ($.type(powerOpt) === 'function') {
  273. powerOpt = powerOpt();
  274. }
  275. console.log(powerOpt);
  276. $.extend(powerOpt, {
  277. class: 'bizWindow'
  278. });
  279. iframe.parent().power(powerOpt);
  280. iframe.progress('close');
  281. });
  282. }
  283. },
  284. closeMe: function () {
  285. var $tt = $('#tt');
  286. var tab = $tt.tabs('getSelected');
  287. var index = $tt.tabs('getTabIndex', tab);
  288. $tt.tabs("close", index);
  289. },
  290. // Tab菜单操作
  291. tabMenuOprate: function (menu, type) {
  292. var $tt = $('#tt');
  293. var allTabs = $tt.tabs('tabs');
  294. var allTabtitle = [];
  295. $.each(allTabs, function (i, n) {
  296. var opt = $(n).panel('options');
  297. if (opt.closable)
  298. allTabtitle.push(opt.title);
  299. });
  300. var curTabTitle = $(menu).data("tabTitle");
  301. var curTabIndex = $tt.tabs("getTabIndex", $tt.tabs("getTab", curTabTitle));
  302. switch (type) {
  303. case "1": //关闭当前
  304. $tt.tabs("close", curTabTitle);
  305. break;
  306. case "2": //全部关闭
  307. for (var i = 0; i < allTabtitle.length; i++) {
  308. $tt.tabs('close', allTabtitle[i]);
  309. }
  310. break;
  311. case "3": //除此之外全部关闭
  312. for (var i = 0; i < allTabtitle.length; i++) {
  313. if (curTabTitle != allTabtitle[i])
  314. $tt.tabs('close', allTabtitle[i]);
  315. }
  316. $tt.tabs('select', curTabTitle);
  317. $tt.tabs('scrollBy', 0);
  318. break;
  319. case "4": //当前侧面右边
  320. for (var i = curTabIndex; i < allTabtitle.length; i++) {
  321. $tt.tabs('close', allTabtitle[i]);
  322. }
  323. $tt.tabs('select', curTabTitle);
  324. break;
  325. case "5": //当前侧面左边
  326. for (var i = 0; i < curTabIndex - 1; i++) {
  327. $tt.tabs('close', allTabtitle[i]);
  328. }
  329. $tt.tabs('select', curTabTitle);
  330. break;
  331. case "6": //刷新
  332. var currentTab = $tt.tabs('getSelected');
  333. var opts = $.data(currentTab[0], 'panel').options;
  334. if (opts.iframe) {
  335. var currentIframe = currentTab.find('iframe')[0];
  336. currentIframe.contentWindow.location.href = currentIframe.src;
  337. } else {
  338. $(currentTab[0]).panel('refresh');
  339. }
  340. break;
  341. case "7": //在新窗口打开
  342. var refresh_tab = $tt.tabs('getSelected');
  343. var refresh_iframe = refresh_tab.find('iframe')[0];
  344. window.open(refresh_iframe.src);
  345. break;
  346. }
  347. },
  348. //退出登录
  349. logout: function () {
  350. $.cookie('auth', null);
  351. top.window.location.href = jumpApi(YJYDLOGINURL);
  352. },
  353. //修改密码
  354. resetPWD: function () {
  355. var me = this;
  356. seajs.use('/user/resetPWD', function (opt) {
  357. $.yvan.showDialog(me, opt());
  358. });
  359. },
  360. //全屏显示
  361. onFullScreen: function () {
  362. //头部全屏显示
  363. var text = $('.full-screen span').text();
  364. if (text === "全屏显示") {
  365. var el = document.documentElement;
  366. var rfs = el.requestFullScreen || el.webkitRequestFullScreen;
  367. if (typeof rfs !== "undefined" && rfs) {
  368. rfs.call(el);
  369. } else if (typeof window.ActiveXObject !== "undefined") {
  370. var wscript = new ActiveXObject("WScript.Shell");
  371. if (wscript != null) {
  372. wscript.SendKeys("{F11}");
  373. }
  374. } else if (el.msRequestFullscreen) {
  375. el.msRequestFullscreen();
  376. } else if (el.oRequestFullscreen) {
  377. el.oRequestFullscreen();
  378. } else {
  379. $.yvan.msg('浏览器不支持全屏调用!请更换浏览器或按F11键切换全屏!');
  380. }
  381. $('.full-screen span').text('退出全屏');
  382. } else {
  383. var el = document;
  384. var cfs = el.cancelFullScreen || el.webkitCancelFullScreen || el.exitFullScreen;
  385. if (typeof cfs !== "undefined" && cfs) {
  386. cfs.call(el);
  387. } else if (typeof window.ActiveXObject !== "undefined") {
  388. var wscript = new ActiveXObject("WScript.Shell");
  389. if (wscript != null) {
  390. wscript.SendKeys("{F11}");
  391. }
  392. } else if (el.msExitFullscreen) {
  393. el.msExitFullscreen();
  394. } else if (el.oRequestFullscreen) {
  395. el.oCancelFullScreen();
  396. } else {
  397. $.yvan.msg('浏览器不支持全屏调用!请更换浏览器或按F11键切换全屏!');
  398. }
  399. $('.full-screen span').text('全屏显示');
  400. }
  401. }
  402. };