mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-27 09:25:09 +08:00
fix: #I5KCI6
This commit is contained in:
@ -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 = []
|
||||
|
Reference in New Issue
Block a user