var $url = '/index'; var $sidebarwidth = 200; var $collapsewidth = 60; var data = utils.init({ homelogourl: null, hometitle: null, menus: [], user: null, menu: null, defaultopeneds: [], defaultactive: null, tabname: null, tabs: [], winheight: 0, winwidth: 0, iscollapse: false, isdesktop: true, ismobilemenu: false, dialoghtml:'', dialogtitle:'', dialogformvisible:false, noticeid:0, contextmenuvisible: false, contexttabname: null, contextleft: 0, contexttop: 0 }); var methods = { nevernotice:function(){ var $this = this; $api.post('/notice?noticeid=' + $this.noticeid ).then(function (response) { $this.dialogformvisible = false; }) console.log($this.noticeid) }, apiget: function () { var $this = this; $api.get($url).then(function (response) { var res = response.data; if (res.user) { if (res.notice) { // $this.$alert(res.notice.body.replace(/@upload/g,"/upload"), res.notice.title, { // dangerouslyusehtmlstring: true, // customclass:'msgbox' // }); $this.noticeid = res.notice.id; $this.dialoghtml = res.notice.body.replace(/@upload/g,"/upload"); $this.dialogtitle = res.notice.title; $this.dialogformvisible = true; } $this.user = res.user; $this.homelogourl = res.homelogourl || utils.getassetsurl('images/logo.png'); $this.hometitle = res.hometitle || '用户中心'; $this.menus = res.menus; var sidemenuids = []; if (location.hash) { var ids = location.hash.substr(1).split('/'); var topmenuid = ids[0]; $this.menu = _.find($this.menus, function (x) { return x.id == topmenuid; }); for (var i = 1; i < ids.length; i++) { if (!ids[i]) break; sidemenuids.push(ids[i]); } } if (!$this.menu && $this.menus.length > 0) { $this.menu = $this.menus[0]; } if ($this.menu) { $this.btntopmenuclick($this.menu); if (sidemenuids.length > 0) { $this.btnsidemenuclick(sidemenuids.join('/')); } } document.title = $this.hometitle; settimeout($this.ready, 100); } else { location.href = utils.getrooturl('login'); } }).catch(function (error) { utils.error(error); }); }, ready: function () { window.onresize = this.winresize; window.onresize(); utils.loading(this, false); }, opencontextmenu: function(e) { if (e.srcelement.id && _.startswith(e.srcelement.id, 'tab-')) { this.contexttabname = _.trimstart(e.srcelement.id, 'tab-'); this.contextmenuvisible = true; this.contextleft = e.clientx; this.contexttop = e.clienty; } }, closecontextmenu: function() { this.contextmenuvisible = false; }, btncontextclick: function(command) { var $this = this; if (command === 'this') { this.tabs = this.tabs.filter(function(tab) { return tab.name !== $this.contexttabname; }); } else if (command === 'others') { this.tabs = this.tabs.filter(function(tab) { return tab.name === $this.contexttabname; }); utils.opentab($this.contexttabname); } else if (command === 'left') { var istab = false; this.tabs = this.tabs.filter(function(tab) { if (tab.name === $this.contexttabname) { istab = true; } return tab.name === $this.contexttabname || istab; }); } else if (command === 'right') { var istab = false; this.tabs = this.tabs.filter(function(tab) { if (tab.name === $this.contexttabname) { istab = true; } return tab.name === $this.contexttabname || !istab; }); } else if (command === 'all') { this.tabs = []; } this.closecontextmenu(); }, winresize: function () { this.winheight = $(window).height(); this.winwidth = $(window).width(); this.isdesktop = this.winwidth > 992; }, getindex: function (level1, level2, level3) { if (level3) return level1.id + '/' + level2.id + '/' + level3.id; else if (level2) return level1.id + '/' + level2.id; else if (level1) return level1.id; return ''; }, btntopmenuclick: function (menu) { if (menu.children && menu.children.length > 0) { for(var i = 0; i < menu.children.length; i++) { var child = menu.children[i]; if (child.children) { this.defaultopeneds = [child.id]; break; } } } else { this.btnmenuclick(menu); } this.menu = menu; }, btnsidemenuclick: function(sidemenuids) { var ids = sidemenuids.split('/'); var menus = this.menu.children; var menu = null; var defaultopeneds = []; for (var i = 0; i < ids.length; i++) { menu = _.find(menus, function(x){ return x.id == ids[i]; }); menus = menu.children; defaultopeneds.push(menu.id); } this.defaultopeneds = defaultopeneds; if (menu) { this.btnmenuclick(menu); } location.hash = this.menu.id + '/' + sidemenuids; }, btnmenuclick: function(menu) { this.defaultactive = this.defaultopeneds.join('/'); this.ismobilemenu = false; if (menu.target == '_layer') { utils.openlayer({ title: menu.text, url: menu.link, full: true }); } else if (menu.target == '_self') { location.href = menu.link; } else if (menu.target == '_parent') { parent.location.href = menu.link; } else if (menu.target == '_top') { top.location.href = menu.link; } else if (menu.target == '_blank') { window.open(menu.link); } else { utils.addtab(menu.text, menu.link); } }, btnmobilemenuclick: function () { this.iscollapse = false; this.ismobilemenu = !this.ismobilemenu; }, btnusermenuclick: function (command) { if (command === 'profile') { utils.addtab('修改资料', utils.getpageurl(null, 'profile')); } else if (command === 'password') { utils.addtab('更改密码', utils.getpageurl(null, 'password')); } else if (command === 'logout') { location.href = utils.getrooturl('logout'); } } }; var $vue = new vue({ el: "#main", data: data, methods: methods, created: function () { this.apiget(); }, computed: { leftwidth: function () { if (this.isdesktop) { return this.iscollapse ? $collapsewidth : $sidebarwidth; } return this.ismobilemenu ? this.winwidth : 0; } } });