|
|
|
@ -2,7 +2,8 @@ import { store } from '../index' |
|
|
|
|
import { defineStore } from 'pinia' |
|
|
|
|
import { getAccessToken, removeToken } from '@/utils/auth' |
|
|
|
|
import { CACHE_KEY } from '@/hooks/web/useCache' |
|
|
|
|
import { getInfo, loginOut } from '@/api/login' |
|
|
|
|
import { loginOut } from '@/api/login' |
|
|
|
|
import { getUser as getUserInfo } from '@/api/system/user' |
|
|
|
|
|
|
|
|
|
import cache from '@/plugins/cache' |
|
|
|
|
|
|
|
|
@ -50,11 +51,17 @@ export const useUserStore = defineStore('admin-user', { |
|
|
|
|
return null |
|
|
|
|
} |
|
|
|
|
let userInfo = cache.local.get(CACHE_KEY.USER) |
|
|
|
|
if (!userInfo || !userInfo?.menus || userInfo.menus.length == 0) { |
|
|
|
|
userInfo = await getInfo({}) |
|
|
|
|
// if (!userInfo || !userInfo?.menus || userInfo.menus.length == 0) {
|
|
|
|
|
// userInfo = await getInfo({})
|
|
|
|
|
// }
|
|
|
|
|
if (!userInfo?.user) { |
|
|
|
|
const userId = localStorage.getItem('userId') |
|
|
|
|
userInfo = { |
|
|
|
|
user: await getUserInfo(Number(userId)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
this.permissions = userInfo.permissions |
|
|
|
|
this.roles = userInfo.roles |
|
|
|
|
// this.permissions = userInfo.permissions
|
|
|
|
|
// this.roles = userInfo.roles
|
|
|
|
|
this.user = userInfo.user |
|
|
|
|
this.isSetUser = true |
|
|
|
|
cache.local.set(CACHE_KEY.USER, userInfo) |
|
|
|
|