refactor: router

This commit is contained in:
xingyu
2023-01-13 20:18:46 +08:00
parent 81595f81db
commit 3a8cd9afe9
4 changed files with 78 additions and 72 deletions

View File

@@ -2,6 +2,7 @@ import { store } from '../index'
import { defineStore } from 'pinia'
import { getAccessToken, removeToken } from '@/utils/auth'
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
import { getInfoApi } from '@/api/login'
const { wsCache } = useCache()
@@ -43,11 +44,15 @@ export const useUserStore = defineStore('admin-user', {
}
},
actions: {
async setUserInfoAction(userInfo: UserInfoVO) {
async setUserInfoAction() {
if (!getAccessToken()) {
this.resetState()
return null
}
let userInfo = wsCache.get(CACHE_KEY.USER)
if (!userInfo) {
userInfo = await getInfoApi()
}
this.permissions = userInfo.permissions
this.roles = userInfo.roles
this.user = userInfo.user