fix: #I5KCI6

This commit is contained in:
xingyu
2022-08-03 12:38:58 +08:00
parent 55b63c35c9
commit b64261a293
11 changed files with 94 additions and 91 deletions

View File

@ -1,18 +1,19 @@
import { store } from '../index'
import { defineStore } from 'pinia'
import { getAccessToken } from '@/utils/auth'
import { getAccessToken, removeToken } from '@/utils/auth'
import { useCache } from '@/hooks/web/useCache'
const { wsCache } = useCache()
interface UserVO {
id: number
avatar: string
nickname: string
}
interface UserInfoVO {
permissions: []
roles: []
user: {
avatar: string
id: number
nickname: string
}
permissions: string[]
roles: string[]
user: UserVO
}
export const useUserStore = defineStore({
@ -26,6 +27,17 @@ export const useUserStore = defineStore({
nickname: ''
}
}),
getters: {
getPermissions(): string[] {
return this.permissions
},
getRoles(): string[] {
return this.roles
},
getUser(): UserVO {
return this.user
}
},
actions: {
async getUserInfoAction(userInfo: UserInfoVO) {
if (!getAccessToken()) {
@ -37,6 +49,11 @@ export const useUserStore = defineStore({
this.user = userInfo.user
wsCache.set('user', userInfo)
},
loginOut() {
removeToken()
wsCache.clear()
this.resetState()
},
resetState() {
this.permissions = []
this.roles = []