(function () { window.getLanuage = function (key) { if (!window.Lanuages) { return ""; } var val = Lanuages[key]; if (!val || val == "") { val = key; } return val } new Vue({ el: '#main', data: { height: 1000, fold: false, zoom: false, timeline: true, tabs: [home], tabModel: 0, tabIndex: 0, menus: [], menuActive: '1', breadcrumbs: [], language: window.language, pwdDialog: {}, themeDialogVisible: false, small: false, themes: SimpleuiThemes, theme: "", themeName: "", popup: { left: 0, top: 0, show: false, tab: null, menus: [{ text: getLanuage('Refresh'), icon: 'el-icon-refresh', handler: function (tab, item) { try { document.getElementById(tab.id).contentWindow.location.reload(true); } catch (e) { console.log(e) var url = tab.url.split('?')[0]; tab.url = url + '?_=' + new Date().getTime() } } }, { text: getLanuage('Close current'), icon: 'el-icon-circle-close-outline', handler: function (tab, item) { app.handleTabsEdit(tab.id, 'remove'); } }, { text: getLanuage('Close other'), icon: 'far fa-copy', handler: function (tab) { app.tabs.forEach(item => { if (item.id != tab.id) { app.handleTabsEdit(item.id, 'remove'); } }) } }, { text: getLanuage('Close all'), icon: 'el-icon-close', handler: function (tab, item) { app.$confirm(Lanuages["Are you sure you want them all closed"], Lanuages.Tips, { confirmButtonText: Lanuages.ConfirmYes, cancelButtonText: Lanuages.ConfirmNo, type: 'warning' }).then(function () { app.tabs.forEach((tab, index) => { if (index != 0) { app.handleTabsEdit(tab.id, 'remove'); } }); app.menuActive = '1'; }).catch(function () { }); } }, { text: getLanuage('Open in a new page'), icon: 'el-icon-news', handler: function (tab, item) { window.open(tab.url); } }] } }, created: function () { var self = this; window.onload = window.onresize = function () { self.height = document.documentElement.clientHeight || document.body.clientHeight var width = document.documentElement.clientWidth || document.body.clientWidth; self.fold = width < 800; self.small = width < 800; } window.app = this; this.menus = window.menus this.theme = getCookie('theme'); this.themeName = getCookie('theme_name'); //接收子页面的事件注册 window.themeEvents = []; window.addThemeEvent = function (handler) { themeEvents.push(handler); } }, methods: { setTheme: function (item) { var url = window.themeUrl; if (item.file && item.file != '') { this.theme = url + item.file; } else { this.theme = ''; } this.themeName = item.text; setCookie('theme', this.theme); setCookie('theme_name', item.text); var self = this; //通知子页面 window.themeEvents.forEach(handler => { handler(self.theme) }); }, openUrl: function (url) { window.open(url); }, contextmenu: function (item, e) { //home没有popup menu if (item.index == '1') { return; } this.popup.tab = item; this.popup.left = e.clientX; this.popup.top = e.clientY; this.popup.show = true; }, mainClick: function (e) { this.popup.show = false; }, tabClick: function (tab) { var item = this.tabs[tab.index]; var index = item.index; this.menuActive = index; this.breadcrumbs = item.breadcrumbs; }, handleTabsEdit: function (targetName, action) { var self = this; if (action === 'remove') { var next = '0'; this.tabs.forEach((tab, index) => { if (tab.id == targetName) { var temp = self.tabs[index + 1] || self.tabs[index - 1]; if (temp) { next = temp.id; self.menuActive = temp.index; self.breadcrumbs = temp.breadcrumbs; } } }); this.tabModel = next; if (targetName != 0) { this.tabs = this.tabs.filter(tab => tab.id !== targetName); } } } , openTab: function (data, index) { this.breadcrumbs = data.breadcrumbs; var exists = null; //判断是否存在,存在就直接打开 for (var i = 0; i < this.tabs.length; i++) { var tab = this.tabs[i]; if (tab.name == data.name) { exists = tab; continue; } } if (exists) { this.tabModel = exists.id; } else { data.id = new Date().getTime() + "" + Math.random(); data.index = index; this.tabs.push(data); this.tabModel = data.id; } } , foldClick: function () { console.log('11') if (this.fold) { this.fold = false; } else { this.fold = true; } } , changePassword: function () { var width = document.documentElement.clientWidth || document.body.clientWidth; if (width > 800) { this.pwdDialog = { url: window.urls.changePassword, name: language.change_password, show: true }; } else { this.openTab({url: window.urls.changePassword, icon: 'far fa-edit', name: language.change_password}) app.breadcrumbs = [language.change_password]; } } , logout: function () { this.$confirm(language.confirm, Lanuages.Tips, { confirmButtonText: language.yes, cancelButtonText: language.no, type: 'warning' }).then(function () { window.location.href = window.urls.logout; }).catch(function () { }); } , goIndex: function () { window.open('/'); } , getLanuage: getLanuage, goZoom: function () { var el = window.document.body; if (!this.zoom) { var isFullscreen = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen; if (!isFullscreen) {//进入全屏,多重短路表达式 (el.requestFullscreen && el.requestFullscreen()) || (el.mozRequestFullScreen && el.mozRequestFullScreen()) || (el.webkitRequestFullscreen && el.webkitRequestFullscreen()) || (el.msRequestFullscreen && el.msRequestFullscreen()); } this.zoom = true; } else { document.exitFullscreen ? document.exitFullscreen() : document.mozCancelFullScreen ? document.mozCancelFullScreen() : document.webkitExitFullscreen ? document.webkitExitFullscreen() : ''; this.zoom = false; } } , displayTimeline: function () { this.timeline = !this.timeline; }, report: function () { window.open('https://github.com/newpanjing/simpleui/issues') } } }) })();