| 1 |
- import{z as o,C as c,S as i,aj as m,al as d}from"./index-DwHkT46H.js";function g(t){return o({url:"/api/auth/v2/login",method:"post",data:t})}function f(t){return o({url:"/api/auth/v2/register",method:"post",data:t})}function k(t){return o({url:`/api/auth/v2/sync?userFlag=${t}`,method:"get"})}function h(){return o({url:"/api/user/user_info",method:"get"})}function l(){return o({url:"/api/user/user_routers",method:"get"})}const y=c("current_user",{persist:{enabled:!0,strategies:[{key:"info",storage:localStorage,paths:["username"]}]},state:()=>({name:"Jack",token_type:"",token:i.get(),username:"",nickname:"",dept:[],roles:[],permissions:[],user:{}}),actions:{updateName(t){this.name=t},toLogin(t){const{username:s,password:r}=t;return new Promise((n,a)=>{g({username:s,password:r}).then(e=>{e.code==200&&e.data.access_token.length?(this.token=e.data.access_token,this.token_type=e.data.token_type,this.username=e.data.username,this.nickname=e.data.nickname,i.set(e.data.access_token),n(e.msg),this.getInfo()):a(e.msg)}).catch(e=>{a(e)})})},async getRoutesList(){const{code:t,data:{routers:s}}=await l();t===200&&await new Promise((r,n)=>{try{m.setItem(JSON.stringify(s)),r()}catch(a){n(a)}})},async getUserInfo(){const{code:t,data:{permissions:s,dept:r,roles:n}}=await h();t===200&&await new Promise((a,e)=>{try{d.setItem(JSON.stringify({permissions:s,dept:r,roles:n})),a()}catch(u){e(u)}})}}});export{k as a,f as r,y as u};
|