123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448 |
- 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 = $('<div></div>');
- iframe.progress();
- } else {
- iframe = '<iframe src="' + params.url +
- '" scrolling="auto" frameborder="0" style="width:100%;height:100%;"></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('全屏显示');
- }
- }
- };
|