index.js 12 KB

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