index-e65d7b06.js 2.3 KB

1
  1. import{a4 as s,d as n,ae as u,af as a,T as l,ag as d}from"./index-1bac2251.js";import{c as h,s as f,b as g,d as m,e as i}from"./auth-54229761.js";function v(e){return s.post("/base/login",e)}function p(){return s.post("/base/logout")}function y(){return s.post("/api/user/info")}function b(){return s.post("/api/user/menu")}const S=n("app",{state:()=>({...u}),getters:{appCurrentSetting(e){return{...e}},appDevice(e){return e.device},appAsyncMenus(e){return e.serverMenu}},actions:{updateSettings(e){this.$patch(e)},toggleTheme(e){e?(this.theme="dark",document.body.setAttribute("arco-theme","dark")):(this.theme="light",document.body.removeAttribute("arco-theme"))},toggleDevice(e){this.device=e},toggleMenu(e){this.hideMenu=e},async fetchServerMenuConfig(){let e=null;try{e=a.info({id:"menuNotice",content:"loading",closable:!0});const{data:o}=await b();this.serverMenu=o,e=a.success({id:"menuNotice",content:"success",closable:!0})}catch{e=a.error({id:"menuNotice",content:"error",closable:!0})}},clearServerMenu(){this.serverMenu=[]}}}),M=n("user",{state:()=>({name:void 0,avatar:void 0,job:void 0,organization:void 0,location:void 0,email:void 0,introduction:void 0,personalWebsite:void 0,jobName:void 0,organizationName:void 0,locationName:void 0,phone:void 0,registrationDate:void 0,accountId:void 0,certification:void 0,role:"",resources:void 0,hrefUrl:void 0}),getters:{userInfo(e){return{...e}}},actions:{switchRoles(){return new Promise(e=>{this.role=this.role==="user"?"admin":"user",e(this.role)})},setInfo(e){this.$patch(e)},resetInfo(){h(),this.$reset()},async info(){const e=await y();this.setInfo(e.data)},async login(e){var o;try{const t=await v(e);f(t.data.access_token);const c={avatar:t.data.avatar,name:t.data.loginName,email:t.data.email,role:t.data.roles[0].roleKey};if(this.name=t.data.userName,((o=t.data)==null?void 0:o.roles.length)>0)for(const r of t.data.roles)this.resources||(this.resources=[]),this.resources=this.resources.concat(r.resources);g(JSON.stringify(c)),m(JSON.stringify(this.resources));for(const r of this.resources)if(r.menuType==0)return r.component}catch(t){throw i(),t}},logoutCallBack(){const e=S();this.resetInfo(),i(),l(),e.clearServerMenu()},async logout(){try{await p()}finally{d.push({name:"login"}),this.logoutCallBack()}},getHreFurl(e){this.hrefUrl=e}}});export{S as a,M as u};