var wmsAdmin = new Vue({ el: '#wmsAdmin', mixins: [useAutoHeight], data: { themeColor: "#0183e1",//"#018ffc",//主题色 themeElements: { headerColor: "#23262E",//头部背景色 headerTextColor: "#fff",//头部字体色 asideColor: "#393D49",//左侧背景色 asideTextColor: "#fff"//左侧字体色 }, showLoading: false, firstMenu: [], secondMenu: [], otherMenu: [], defaultIndex: "", secondDefaultIndex: "", currenIndex: "", currentRightMenuIndex: "", currentMenuTab: '1', isCollapse: false, menuTabs: [{ title: "首页", name: "1", url: "/Home/Main", closable: false, icon: "" }], dialogFrame: { title: '', show: false, url: '', dh: 0, height: "50%", width: "80%", btn: false, callBack: function (frame) { }, cb: function () { } }, pageSetList: [], pageSetReadOnly: [], //弹窗table列表属行初始化 dialogList: { title: '', condition: '', show: false, itemCols: [], paging: true, url: null, data: {}, height: 330, single: false, btnSure: function (selections) { } }, //dialog列表为item时查询条件 formItem: { itemCode: '', itemName: '', itemModel: '', itemFigureNo: '' }, formCustomer: { customerName: '' }, formVendor: { vendorName: '' }, }, computed: { dialogFrameHeight: function () { if (this.dialogFrame.dh == 0) return this.dialogFrame.height; return (this.autoHeight - this.dialogFrame.dh) + "px"; }, currentTitle: function () { var $this = this; var title = ""; if ($this.currentMenuTab) { $this.menuTabs.forEach(function (n) { if (n.name == $this.currentMenuTab) title = n.title; }); } return title; } }, watch: { deep: true, isCollapse: function (val) { if (val) { $("#elMain").animate({ left: "64px" }, 350); $("#elAside,#elAside ul").animate({ width: "64px" }, 350); } else { $("#elAside,#elAside ul").animate({ width: "200px" }, 350); $("#elMain").animate({ left: "200px" }, 350); } }, "themeElements.headerColor": function (val) { document.documentElement.style.setProperty("--theme-header-color", val); this.setCookie("headerColor", val); }, "themeElements.headerTextColor": function (val) { document.documentElement.style.setProperty("--theme-header-text-color", val); this.setCookie("headerTextColor", val); }, "themeElements.asideColor": function (val) { document.documentElement.style.setProperty("--theme-aside-color", val); this.setCookie("asideColor", val); }, "themeElements.asideTextColor": function (val) { document.documentElement.style.setProperty("--theme-aside-text-color", val); this.setCookie("asideTextColor", val); }, themeColor: function (val) { document.documentElement.style.setProperty("--theme-color", val); var $content = $('.el-tabs__content'); $content.find('iframe').each(function () { var currentIframeDocument = $(this).context.contentDocument; if (currentIframeDocument) { currentIframeDocument.documentElement.style.setProperty("--theme-color", val); } }); this.setCookie("hhThemeColor", val); //alert(val + '|update'); //alert(this.getCookie("hhThemeColor")+'|aaa'); } }, methods: { fullWindow: function () { var docElm = document.documentElement; //W3C if (docElm.requestFullscreen) { docElm.requestFullscreen(); } //FireFox else if (docElm.mozRequestFullScreen) { docElm.mozRequestFullScreen(); } //Chrome等 else if (docElm.webkitRequestFullScreen) { docElm.webkitRequestFullScreen(); } //IE11 else if (elem.msRequestFullscreen) { elem.msRequestFullscreen(); } this.success('按Esc即可退出全屏'); }, searchItem: function () { var $this = this; this.$refs.parentDialogList.pagingOptions.pageIndex = 1; var searchModel = { itemCode: $this.formItem.itemCode, itemName: $this.formItem.itemName, itemModel: $this.formItem.itemModel, itemFigureNo: $this.formItem.itemFigureNo }; searchModel = $.extend(searchModel, $this.dialogList.data); this.$refs.parentDialogList.loadData(searchModel); }, searchCustomer: function () { var $this = this; this.$refs.parentDialogList.pagingOptions.pageIndex = 1; var searchModel = { customerName: $this.formCustomer.customerName, }; this.$refs.parentDialogList.loadData(searchModel); }, searchVendor: function () { var $this = this; this.$refs.parentDialogList.pagingOptions.pageIndex = 1; var searchModel = { vendorName: $this.formVendor.vendorName, }; this.$refs.parentDialogList.loadData(searchModel); }, //弹窗table列表 showDialogList: function (options) { var $this = this; //每次打开先清空上次选中 this.formItem.itemCode = ''; this.formItem.itemName = ''; this.formItem.itemModel = ''; this.formItem.itemFigureNo = ''; this.formCustomer.customerName = ''; this.formVendor.vendorName = ''; if (options.url == $this.dialogList.url) { this.$refs.parentDialogList.pagingOptions.pageIndex = 1; this.$refs.parentDialogList.param = {}; this.$refs.parentDialogList.loadData(); } $this.dialogList.show = true; $this.dialogList.single = false; $this.dialogList.paging = true; $this.dialogList.condition = ''; $this.dialogList.data = {}; $this.dialogList = $.extend($this.dialogList, options); }, //弹窗table列表确认事件 dialogListBtnSure: function () { //dialog中选中的物料集合 var selections = this.$refs.parentDialogList.selections; //调用确定回调函数 this.dialogList.btnSure(selections); this.dialogList.show = false; }, loading: function (id) { id = id || "#elMain"; this.showLoading = true; var width = $(id).width(); var height = $(id).height(); var left = $(id).offset().left; var top = $(id).offset().top; $("#hhLoading").css({ "position": "fixed", "left": ((width / 2) - 50 + left) + "px", "top": ((height / 2) - 100 + top) + "px", "z-index": 99999 }); }, showDialogFrame: function (options) { var $this = this; $this.loading('#_dialogFrame'); $this.dialogFrame.btn = false; this.dialogFrame.dh = 0; $this.dialogFrame = $.extend($this.dialogFrame, options); if ($this.dialogFrame.url.indexOf("?") > 0) { $this.dialogFrame.url += ("&_t=" + (new Date()).valueOf()); } else { $this.dialogFrame.url += ("?_t=" + (new Date()).valueOf()); } $this.dialogFrame.cb = function () { if ($this.$refs.iframeDialog) { $this.dialogFrame.callBack($this.$refs.iframeDialog.contentWindow); $this.dialogFrame.show = false; } }; $this.dialogFrame.show = true; }, setCookie: function (name, value) {//设置cookie,时间30天 var days = 30; var expires = new Date(); expires.setTime(expires.getTime() + days * 24 * 60 * 60 * 1000); document.cookie = name + "=" + escape(value) + ";expires=" + expires.toGMTString(); }, getCookie: function (name) { if (document.cookie.length > 0) { c_start = document.cookie.indexOf(name + "=") if (c_start != -1) { c_start = c_start + name.length + 1 c_end = document.cookie.indexOf(";", c_start) if (c_end == -1) c_end = document.cookie.length return unescape(document.cookie.substring(c_start, c_end)) } } return "" }, refresh: function (refreshId) { var id = null; if (refreshId) id = 'pane-' + refreshId; else id = this.currentRightMenuIndex; //var id = refreshId || this.currentRightMenuIndex; var iframe = $("#" + id).find('iframe'); var src = iframe.attr('src'); iframe.attr('src', src); this.loading(); }, closeCurrent: function (closeId) { var targetName = closeId || this.currentRightMenuIndex.split('pane-')[1]; this.removeTab(targetName); }, closeOthers: function () { var $this = this; var id = this.currentRightMenuIndex; $('#' + id).siblings().each(function () { var targetName = $(this).attr('id').split('pane-')[1]; $this.removeTab(targetName); }); }, closeAll: function () { this.closeCurrent(); this.closeOthers(); }, removeTab: function (targetName) { if (targetName == "1") return; var tabs = this.menuTabs; var activeName = this.currentMenuTab; if (activeName === targetName) { tabs.forEach(function (tab, index) { if (tab.name === targetName) { var nextTab = tabs[index + 1] || tabs[index - 1]; if (nextTab) { activeName = nextTab.name; } } }); } this.currentMenuTab = activeName; this.menuTabs = tabs.filter(function (tab) { return tab.name !== targetName; }); }, loadThemeColor: function () { //系统elementui控件主题色 var themeColor = this.getCookie("hhThemeColor") || this.themeColor; document.documentElement.style.setProperty("--theme-color", themeColor); this.themeColor = themeColor; //alert(themeColor + '|load'); //框架颜色 var headerColor = this.getCookie("headerColor") || this.themeElements.headerColor; document.documentElement.style.setProperty("--theme-header-color", headerColor); this.themeElements.headerColor = headerColor; var headerTextColor = this.getCookie("headerTextColor") || this.themeElements.headerTextColor; document.documentElement.style.setProperty("--theme-header-text-color", headerTextColor); this.themeElements.headerTextColor = headerTextColor; var asideColor = this.getCookie("asideColor") || this.themeElements.asideColor; document.documentElement.style.setProperty("--theme-aside-color", asideColor); this.themeElements.asideColor = asideColor; var asideTextColor = this.getCookie("asideTextColor") || this.themeElements.asideTextColor; document.documentElement.style.setProperty("--theme-aside-text-color", asideTextColor); this.themeElements.asideTextColor = asideTextColor; }, dropMenuCommand: function (command) { var $this = this; switch (command) { case 'userInfo': this.showDialogFrame({ title: '用户信息', height: "200px", width: "400px", url: "../Home/UserDetail" }); break; case 'updatePassword': $this.showDialogFrame({ title: '修改密码', height: "160px", width: "400px", url: "../Home/UpdatePassword" }); break; case 'onOnLineUser': this.showDialogFrame({ title: '在线用户', height: "300px", width: "895px", url: "../Home/OnLineUser" }); break; case 'subjectElements': $this.showDialogFrame({ title: '主题元素', height: "300px", width: "450px", url: "../Home/SetThemeElements" }); break; case 'exit': $this.confirm("确认退出登录吗?", function () { $.ajax({ type: 'GET', async: false, data: { endType: "hand" }, url: '/Home/Exit', success: function (data) { location.href = 'Login'; } }); }); break; case 'selCN': this.setLanguage("zh_CN"); break; case 'selEN': this.setLanguage("en_US"); break; case 'selJP': this.setLanguage("ja_JP"); break; } }, setLanguage:function(lan){ $.ajax({ type: 'GET', async: false, data: { language: lan }, url: '/Language/LoadLanguangeInfo', success: function (data) { location.reload(); } }); }, confirm: function (confirmMsg, then, catchEvent) { this.$confirm(confirmMsg, '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(function () { if (then) then(); }).catch(function () { if (catchEvent) catchEvent(); }); }, //成功消息 success: function (msg) { this.$message({ showClose: true, message: msg, type: 'success' }); }, //警告消息 warning: function (msg) { this.$message({ showClose: true, message: msg, type: 'warning' }); }, //错误消息 error: function (msg) { this.$message({ showClose: true, message: msg, type: 'error' }); }, loadMenu: function () {//初始化菜单 var $this = this; $.ajax({ type: 'GET', async: false, url: '../Power/GetMenu', success: function (d) { var d_json = (new Function("return " + d))(); var flag = true; if (!d_json.UserMenuList) { $this.error("获取菜单异常!"); location.href = 'Login'; } d_json.UserMenuList.forEach(function (m, n) { var _menu = { id: m.id, title: m.name, open: false, pId: m.pId, icon: "&" + m.iconSkin, url: m.url }; if (m.pId == "-1") { $this.firstMenu.push(_menu); //默认选中第一个 if (flag) { $this.defaultIndex = _menu.id; _menu.open = true; flag = false; } } else $this.otherMenu.push(_menu); }); $this.secondMenu = $this.getSecondMenu($this.defaultIndex); }, error: function (msg) { $this.error("获取菜单异常!"); } }); }, //id获取菜单 getMenuById: function (id) { var menus = []; for (var i = 0; i < this.otherMenu.length; i++) { if (this.otherMenu[i].pId == id) { if (this.otherMenu[i].url.indexOf("?") > 0) { this.otherMenu[i].url += "&menuid=" + this.otherMenu[i].id; } else { this.otherMenu[i].url += "?menuid=" + this.otherMenu[i].id; } var menuEntity = { id: this.otherMenu[i].id, title: this.otherMenu[i].title, icon: this.otherMenu[i].icon, open: false, url: this.otherMenu[i].url }; menus.push(menuEntity); } } return menus; }, //获取当前菜单的所有子菜单 getCurrentMenuChildren: function (menu) { var $this = this; var secondMenu = $this.getMenuById(menu.id); if (secondMenu.length > 0) $this.secondDefaultIndex = secondMenu[0].id;//secondMenu[0].open = true; secondMenu.forEach(function (m) { m.children = $this.getMenuById(m.id); }); return secondMenu; }, getSecondMenu: function (id) { var $this = this; $this.currenIndex = id; var currentMenu = null; $.each($this.firstMenu, function (i, n) { if (n.id == id) { currentMenu = n; n.open = true; } else n.open = false; }); if (currentMenu) return $this.getCurrentMenuChildren(currentMenu); }, setSecondMenu: function (id) { this.secondMenu = this.getSecondMenu(id); }, initRightMenu: function () { var $this = this; setTimeout(function () { $(".el-tabs__nav div").contextmenu(function (e) { $this.currentRightMenuIndex = $(this).attr('aria-controls'); var winWidth = $(document).width(); var winHeight = $(document).height(); var posX = e.pageX; var posY = e.pageY; var menuWidth = $(".contextmenu").width(); var menuHeight = $(".contextmenu").height(); var secMargin = 10; if (posX + menuWidth + secMargin >= winWidth && posY + menuHeight + secMargin >= winHeight) { posLeft = posX - menuWidth - secMargin + "px"; posTop = posY - menuHeight - secMargin + "px"; } else if (posX + menuWidth + secMargin >= winWidth) { posLeft = posX - menuWidth - secMargin + "px"; posTop = posY + secMargin + "px"; } else if (posY + menuHeight + secMargin >= winHeight) { posLeft = posX + secMargin + "px"; posTop = posY - menuHeight - secMargin + "px"; } else { posLeft = posX + secMargin + "px"; posTop = posY + secMargin + "px"; }; $(".contextmenu").css({ "left": posLeft, "top": posTop }).show(); return false; }); $(document).click(function () { $(".contextmenu").hide(); }); }, 100); }, addCustomTab: function (option) { var id = null; this.menuTabs.forEach(function (n) { if (n.title == option.title) id = n.name; }); if (!id) { id = guid(); this.initRightMenu(); this.loading(); this.menuTabs.push({ title: option.title, name: id, url: option.href, closable: true, }); this.currentMenuTab = id; this.resizeIframe(); } else { this.currentMenuTab = id; } }, addTab: function (menu, secondIndex) { if (secondIndex) this.secondDefaultIndex = secondIndex; var id = null; this.menuTabs.forEach(function (n) { if (n.name == menu.id) id = n.name; }); if (!id) { this.initRightMenu(); this.currentMenuTab = menu.id; this.loading(); this.menuTabs.push({ title: menu.title, name: menu.id, url: menu.url, closable: true, icon: menu.icon }); this.resizeIframe(); } else { this.currentMenuTab = menu.id; } }, resizeIframe: function () { var $content = $('.el-tabs__content'); $content.height($(window).height() - 95); setTimeout(function () { $content.find('iframe').each(function () { $(this).css("height", $content.height() + "px"); }); }, 10); }, //根据OperateResult实体弹出消息 showMsg: function (data, successCallBack, errorCallBack, warningCallBack) { if (data) { if (data.Success) { if (successCallBack) successCallBack(); else { this.success("保存成功"); } } else { switch (data.Status) { case 0: this.error(data.Msg); break; case 2: this.warning(data.Msg); break; default: this.error(data.Msg); } if (errorCallBack) errorCallBack(); if (warningCallBack) warningCallBack(); } } else this.error("系统错误"); }, loadPageSetList: function () { var $this = this; if (this.pageSetList.length == 0) { $.ajax({ type: 'GET', async: false, dataType: 'json', url: "/Sys/PageSet/GetPageSetList", success: function (data) { $this.showMsg(data, function () { var readonlyData = Enumerable.From(data.Data).Where("x=>x.CN_B_READONLY").ToArray(); $this.pageSetReadOnly = readonlyData.map(function (n) { return $.trim(n.CN_S_POWER_CODE); }); $this.pageSetList = Enumerable.From(data.Data).Where("x=>!x.CN_B_READONLY").ToArray(); }); } }); } }, }, mounted: function () { var $this = this; this.loadThemeColor(); this.loadMenu(); //初始化功能配置数据 this.loadPageSetList(); this.$nextTick(function () { $this.initRightMenu(); $(window).on('resize', function () { $this.resizeIframe(); }).resize(); if ($this.menuTabs.length > 0) $this.loading(); }); } }); var tab = { tabAdd: function (option) { wmsAdmin.addCustomTab(option); }, tabDeleteRefresh: function (deleteTitle, refreshTitle) { var deleteId = null; var refreshId = null; wmsAdmin.menuTabs.forEach(function (n) { if (n.title == deleteTitle) deleteId = n.name; if (n.title == refreshTitle) refreshId = n.name; }); if (deleteId) { wmsAdmin.closeCurrent(deleteId); } if (refreshId) { wmsAdmin.refresh(refreshId); } } }; $(function(){ $(window).on('resize', function () { resize(); }).resize(); $(document).on('click', '.pf-nav-next', function () { if ($('.pf-nav-more').css('display') == 'none') { $('.pf-nav-more').slideDown(200); } else { $('.pf-nav-more').slideUp(200); } }); }); function resize() { //设置高度 var height = $("#pf-page").height(); //设置宽度 var width = $("#pf-page").width(); //获得放置区域宽度 var top_width = $("#pf-hd").width() - 600; //获得当前宽度可放置的数量 var set_len = Math.floor(top_width / 100); //获得已存在的数量 var now_len = $("#menu_top>li").length; //如果可放置数量小于已存在的数据 //说明此时需要进行移动 if (set_len < now_len) { //可移动下去的数量 var moveLen = now_len - set_len; var eq1 = now_len - moveLen; var eq2 = now_len; var $li = $("#div_top_menu>ul>li").slice(eq1, eq2); $li.prependTo("#div_left_menu>ul"); } else if (set_len > now_len) { //可移动上去的数量 var moveLen = set_len - now_len; var eq1 = 0; var eq2 = moveLen; var $li = $("#div_left_menu>ul>li").slice(eq1, eq2); $li.appendTo("#div_top_menu>ul"); } //设置头部菜单宽度 $(".pf-nav-wrap").find("div").width(set_len * 100); //判断扩展的菜单DIV中是否有菜单 var len = $("#div_left_menu>ul>li").length; //没有则隐藏下拉箭头和div if (len == 0) { $("#first_menu_all").hide(); } else { $("#first_menu_all").show(); } }