| | |
| | | import { removeRouteListener } from '@/utils/route-listener'; |
| | | import { UserState } from './types'; |
| | | import useAppStore from '../app'; |
| | | import router from "@/router"; |
| | | |
| | | |
| | | const useUserStore = defineStore('user', { |
| | |
| | | certification: undefined, |
| | | role: '', |
| | | resources:undefined, |
| | | hrefUrl:undefined |
| | | }), |
| | | |
| | | getters: { |
| | |
| | | async login(loginForm: LoginData):string { |
| | | try { |
| | | const res = await userLogin(loginForm); |
| | | |
| | | setToken(res.data.access_token); |
| | | |
| | | const userInfo = { |
| | | avatar: res.data.avatar, |
| | | name: res.data.nickname, |
| | | name: res.data.userName, |
| | | email: res.data.email, |
| | | role: res.data.roles[0].roleKey, |
| | | }; |
| | | this.resources=res.data.resources; |
| | | setUserInfo(JSON.stringify(userInfo)); |
| | | setUserResources(JSON.stringify(this.resources)) |
| | | this.name=res.data.userName |
| | | |
| | | if(res.data?.roles.length>0) |
| | | //遍历roles |
| | | for (const r of res.data.roles) { |
| | | if (!(this.resources)) { |
| | | this.resources = []; |
| | | } |
| | | this.resources = this.resources.concat(r.resources); |
| | | } |
| | | setUserInfo(JSON.stringify(userInfo)); |
| | | setUserResources(JSON.stringify(this.resources)) |
| | | for (const r of this.resources) { |
| | | if (r.menuType == 0) { |
| | | |
| | | return r.component |
| | | } |
| | | } |
| | |
| | | try { |
| | | await userLogout(); |
| | | } finally { |
| | | router.push({ |
| | | name: "login", |
| | | }); |
| | | this.logoutCallBack(); |
| | | } |
| | | }, |
| | | |
| | | |
| | | getHreFurl(url: string) { |
| | | this.hrefUrl=url |
| | | }, |
| | | }, |
| | | }); |
| | | |