var userRole = 0; $(function () { //隐藏角色上的提示红点 $('#role-name-num').hide(); function doSearch(text) { $('#menutree').tree('search', text); } App.init(function () { document.onkeydown = function (event) { if (event.ctrlKey && event.keyCode === 191) { console.log($(document.activeElement)); } }; $('#body').layout(); $('#treesearch').searchbox({ prompt: '搜索', searcher: doSearch, icons: [ { iconCls: 'icon-clear', handler: function (e) { $(e.data.target).textbox('clear').textbox('textbox').focus(); doSearch(''); } }] }); $('.easyui-menubutton').menubutton(); // 根据userRole读取不同的菜单 if (userRole == "1") { $('#menutree').tree({ url: '/app/whepi/mock/menu.json', //api('/menu_tree'), onDblClick: function (node) { var $this = $(this); if (!$this.tree('isLeaf', node.target)) { $this.tree(node.state === 'closed' ? 'expand' : 'collapse', node.target); } }, onSelect: function () { return false; }, onClick: function (node) { var href = node.href; if ($.trim(href)) { App.addTab({title: node.text, url: node.href, id: node.id, iconCls: node.iconCls}); } }, onLoadSuccess: function (node, data) { } }); } else if (userRole == "2") { $('#menutree').tree({ url: '/app/whepi/mock/menu2.json', //api('/menu_tree'), onDblClick: function (node) { var $this = $(this); if (!$this.tree('isLeaf', node.target)) { $this.tree(node.state === 'closed' ? 'expand' : 'collapse', node.target); } }, onSelect: function () { return false; }, onClick: function (node) { var href = node.href; if ($.trim(href)) { App.addTab({title: node.text, url: node.href, id: node.id, iconCls: node.iconCls}); } }, onLoadSuccess: function (node, data) { } }); } else if (userRole == "3") { $('#menutree').tree({ url: '/app/whepi/mock/menu3.json', // 人力资源账户 onDblClick: function (node) { var $this = $(this); if (!$this.tree('isLeaf', node.target)) { $this.tree(node.state === 'closed' ? 'expand' : 'collapse', node.target); } }, onSelect: function () { return false; }, onClick: function (node) { var href = node.href; if ($.trim(href)) { App.addTab({title: node.text, url: node.href, id: node.id, iconCls: node.iconCls}); } }, onLoadSuccess: function (node, data) { } }); } else if (userRole == "5") {//指挥部登录 $('#menutree').tree({ url: '/app/whepi/mock/menu5.json', onDblClick: function (node) { var $this = $(this); if (!$this.tree('isLeaf', node.target)) { $this.tree(node.state === 'closed' ? 'expand' : 'collapse', node.target); } }, onSelect: function () { return false; }, onClick: function (node) { var href = node.href; if ($.trim(href)) { App.addTab({title: node.text, url: node.href, id: node.id, iconCls: node.iconCls}); } }, onLoadSuccess: function (node, data) { } }); } else if (userRole == "6") {//凌云后台菜单 $('#menutree').tree({ url: '/app/whepi/mock/menu6.json', onDblClick: function (node) { var $this = $(this); if (!$this.tree('isLeaf', node.target)) { $this.tree(node.state === 'closed' ? 'expand' : 'collapse', node.target); } }, onSelect: function () { return false; }, onClick: function (node) { var href = node.href; if ($.trim(href)) { App.addTab({title: node.text, url: node.href, id: node.id, iconCls: node.iconCls}); } }, onLoadSuccess: function (node, data) { } }); } else if (userRole == "7") {//凌云集团管理员 $('#menutree').tree({ url: '/app/whepi/mock/menu7.json', onDblClick: function (node) { var $this = $(this); if (!$this.tree('isLeaf', node.target)) { $this.tree(node.state === 'closed' ? 'expand' : 'collapse', node.target); } }, onSelect: function () { return false; }, onClick: function (node) { var href = node.href; if ($.trim(href)) { App.addTab({title: node.text, url: node.href, id: node.id, iconCls: node.iconCls}); } }, onLoadSuccess: function (node, data) { } }); } else if (userRole == "8") {//湖北和昌管理员 $('#menutree').tree({ url: '/app/whepi/mock/menu8.json', onDblClick: function (node) { var $this = $(this); if (!$this.tree('isLeaf', node.target)) { $this.tree(node.state === 'closed' ? 'expand' : 'collapse', node.target); } }, onSelect: function () { return false; }, onClick: function (node) { var href = node.href; if ($.trim(href)) { App.addTab({title: node.text, url: node.href, id: node.id, iconCls: node.iconCls}); } }, onLoadSuccess: function (node, data) { } }); } else if (userRole == "9") {//中建康城管理员 $('#menutree').tree({ url: '/app/whepi/mock/menu9.json', onDblClick: function (node) { var $this = $(this); if (!$this.tree('isLeaf', node.target)) { $this.tree(node.state === 'closed' ? 'expand' : 'collapse', node.target); } }, onSelect: function () { return false; }, onClick: function (node) { var href = node.href; if ($.trim(href)) { App.addTab({title: node.text, url: node.href, id: node.id, iconCls: node.iconCls}); } }, onLoadSuccess: function (node, data) { } }); } $('#mm').menu({ onClick: function (item) { App.tabMenuOprate(this, item.name); } }); $('#tt').tabs({ onContextMenu: function (e, title, index) { e.preventDefault(); if (index >= 0) { $('#mm').menu('show', { left: e.pageX, top: e.pageY }).data("tabTitle", title); } }, onSelect: function (title, index) { if (index >= 0) { var node = $('#tt').tabs('getTab', index).panel('options').node; if (node && node.id) { window.location.hash = $.param(node); node = $('#menutree').tree('find', node.id); $('#menutree').tree('select', node.target).tree('expandTo', node.target).tree('scrollTo', node.target); } } }, onBeforeClose: function (title, index) { var tab = $('#tt').tabs('getSelected'); var curTabIndex = $('#tt').tabs('getTabIndex', tab); if (index === curTabIndex) { window.location.hash = ''; } } }); }); }); var App = { init: function (success) { $.yvan.ajax({ url: api("/api/me"), method: 'get', loadingMask: false, success: function (data) { if(data.data.user){ userRole = data.data.user.userType; console.log(data.data.user.userType); }else{ userRole = 0 } console.log(userRole); if (!$.trim(data.data.userId)) { top.window.location.href = jumpApi(YJYDLOGINURL); return; } $('#user-name').html(data.data.staffName); success(); $("#loading").remove(); }, error: function () { top.window.location.href = jumpApi(YJYDLOGINURL); } }); }, //打开Tab窗口 addTab: function (params) { var $tt = $('#tt'); if ($tt.tabs('exists', params.title)) { $tt.tabs('select', params.title); return; } var lastMenuClickTime = $.cookie("menuClickTime"); var nowTime = new Date().getTime(); if ((nowTime - lastMenuClickTime) < 500) { $.yvan.msg('操作过快,请稍后重试'); return; } var id = $.yvan.createId('t'); var iframe; if (params.url.slice(-3) === '.js') { iframe = $('
'); iframe.progress(); } else { iframe = ''; } $tt.tabs('add', { id: id, title: params.title, closable: true, iconCls: $.trim(params.iconCls) ? params.iconCls + ' fa-lg' : 'fa fa-file-text-o', content: iframe, border: params.border || true, fit: true, node: { url: params.url, title: params.title, id: params.id } }); if ($.type(iframe) !== 'string') { seajs.use([params.url], function (powerOpt) { if ($.type(powerOpt) === 'function') { powerOpt = powerOpt(); } console.log(powerOpt); $.extend(powerOpt, { class: 'bizWindow' }); iframe.parent().power(powerOpt); iframe.progress('close'); }); } }, closeMe: function () { var $tt = $('#tt'); var tab = $tt.tabs('getSelected'); var index = $tt.tabs('getTabIndex', tab); $tt.tabs("close", index); }, // Tab菜单操作 tabMenuOprate: function (menu, type) { var $tt = $('#tt'); var allTabs = $tt.tabs('tabs'); var allTabtitle = []; $.each(allTabs, function (i, n) { var opt = $(n).panel('options'); if (opt.closable) allTabtitle.push(opt.title); }); var curTabTitle = $(menu).data("tabTitle"); var curTabIndex = $tt.tabs("getTabIndex", $tt.tabs("getTab", curTabTitle)); switch (type) { case "1": //关闭当前 $tt.tabs("close", curTabTitle); break; case "2": //全部关闭 for (var i = 0; i < allTabtitle.length; i++) { $tt.tabs('close', allTabtitle[i]); } break; case "3": //除此之外全部关闭 for (var i = 0; i < allTabtitle.length; i++) { if (curTabTitle != allTabtitle[i]) $tt.tabs('close', allTabtitle[i]); } $tt.tabs('select', curTabTitle); $tt.tabs('scrollBy', 0); break; case "4": //当前侧面右边 for (var i = curTabIndex; i < allTabtitle.length; i++) { $tt.tabs('close', allTabtitle[i]); } $tt.tabs('select', curTabTitle); break; case "5": //当前侧面左边 for (var i = 0; i < curTabIndex - 1; i++) { $tt.tabs('close', allTabtitle[i]); } $tt.tabs('select', curTabTitle); break; case "6": //刷新 var currentTab = $tt.tabs('getSelected'); var opts = $.data(currentTab[0], 'panel').options; if (opts.iframe) { var currentIframe = currentTab.find('iframe')[0]; currentIframe.contentWindow.location.href = currentIframe.src; } else { $(currentTab[0]).panel('refresh'); } break; case "7": //在新窗口打开 var refresh_tab = $tt.tabs('getSelected'); var refresh_iframe = refresh_tab.find('iframe')[0]; window.open(refresh_iframe.src); break; } }, //退出登录 logout: function () { $.cookie('auth', null); top.window.location.href = jumpApi(YJYDLOGINURL); }, //修改密码 resetPWD: function () { var me = this; seajs.use('/user/resetPWD', function (opt) { $.yvan.showDialog(me, opt()); }); }, //全屏显示 onFullScreen: function () { //头部全屏显示 var text = $('.full-screen span').text(); if (text === "全屏显示") { var el = document.documentElement; var rfs = el.requestFullScreen || el.webkitRequestFullScreen; if (typeof rfs !== "undefined" && rfs) { rfs.call(el); } else if (typeof window.ActiveXObject !== "undefined") { var wscript = new ActiveXObject("WScript.Shell"); if (wscript != null) { wscript.SendKeys("{F11}"); } } else if (el.msRequestFullscreen) { el.msRequestFullscreen(); } else if (el.oRequestFullscreen) { el.oRequestFullscreen(); } else { $.yvan.msg('浏览器不支持全屏调用!请更换浏览器或按F11键切换全屏!'); } $('.full-screen span').text('退出全屏'); } else { var el = document; var cfs = el.cancelFullScreen || el.webkitCancelFullScreen || el.exitFullScreen; if (typeof cfs !== "undefined" && cfs) { cfs.call(el); } else if (typeof window.ActiveXObject !== "undefined") { var wscript = new ActiveXObject("WScript.Shell"); if (wscript != null) { wscript.SendKeys("{F11}"); } } else if (el.msExitFullscreen) { el.msExitFullscreen(); } else if (el.oRequestFullscreen) { el.oCancelFullScreen(); } else { $.yvan.msg('浏览器不支持全屏调用!请更换浏览器或按F11键切换全屏!'); } $('.full-screen span').text('全屏显示'); } } };