This commit is contained in:
qsh
2024-08-01 18:41:37 +08:00
parent feccb2a1fa
commit 605151c5c8
17 changed files with 143 additions and 137 deletions

View File

@@ -1,10 +1,9 @@
import { store } from '../index'
import { defineStore } from 'pinia'
import { getAccessToken, removeToken } from '@/utils/auth'
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
import { CACHE_KEY } from '@/hooks/web/useCache'
import { getInfo, loginOut } from '@/api/login'
const { wsCache } = useCache()
import cache from '@/plugins/cache'
interface UserVO {
id: number
@@ -49,7 +48,7 @@ export const useUserStore = defineStore('admin-user', {
this.resetState()
return null
}
let userInfo = wsCache.get(CACHE_KEY.USER)
let userInfo = cache.local.get(CACHE_KEY.USER)
if (!userInfo) {
userInfo = await getInfo({})
}
@@ -57,13 +56,13 @@ export const useUserStore = defineStore('admin-user', {
this.roles = userInfo.roles
this.user = userInfo.user
this.isSetUser = true
wsCache.set(CACHE_KEY.USER, userInfo)
wsCache.set(CACHE_KEY.ROLE_ROUTERS, userInfo.menus)
cache.local.set(CACHE_KEY.USER, userInfo)
cache.local.set(CACHE_KEY.ROLE_ROUTERS, userInfo.menus)
},
async loginOut() {
await loginOut()
removeToken()
wsCache.clear()
cache.local.clear()
this.resetState()
},
resetState() {
@@ -77,7 +76,7 @@ export const useUserStore = defineStore('admin-user', {
}
},
refresh() {
wsCache.delete(CACHE_KEY.USER)
cache.local.delete(CACHE_KEY.USER)
this.resetState()
window.location.href = ''
}