fix: 新用户第一次未设置角色无法登录 bug

This commit is contained in:
xingyu4j 2022-12-07 17:46:30 +08:00
parent c3560a52e2
commit cbeee0f744
2 changed files with 8 additions and 1 deletions

View File

@ -55,7 +55,7 @@ router.beforeEach(async (to, from, next) => {
const res = await listSimpleDictDataApi() const res = await listSimpleDictDataApi()
dictStore.setDictMap(res) dictStore.setDictMap(res)
} }
if (userStore.getRoles.length === 0) { if (!userStore.getIsSetUser) {
isRelogin.show = true isRelogin.show = true
const res = await getInfoApi() const res = await getInfoApi()
await userStore.setUserInfoAction(res) await userStore.setUserInfoAction(res)

View File

@ -13,6 +13,7 @@ interface UserVO {
interface UserInfoVO { interface UserInfoVO {
permissions: string[] permissions: string[]
roles: string[] roles: string[]
isSetUser: boolean
user: UserVO user: UserVO
} }
@ -20,6 +21,7 @@ export const useUserStore = defineStore('admin-user', {
state: (): UserInfoVO => ({ state: (): UserInfoVO => ({
permissions: [], permissions: [],
roles: [], roles: [],
isSetUser: false,
user: { user: {
id: 0, id: 0,
avatar: '', avatar: '',
@ -33,6 +35,9 @@ export const useUserStore = defineStore('admin-user', {
getRoles(): string[] { getRoles(): string[] {
return this.roles return this.roles
}, },
getIsSetUser(): boolean {
return this.isSetUser
},
getUser(): UserVO { getUser(): UserVO {
return this.user return this.user
} }
@ -46,6 +51,7 @@ export const useUserStore = defineStore('admin-user', {
this.permissions = userInfo.permissions this.permissions = userInfo.permissions
this.roles = userInfo.roles this.roles = userInfo.roles
this.user = userInfo.user this.user = userInfo.user
this.isSetUser = true
wsCache.set(CACHE_KEY.USER, userInfo) wsCache.set(CACHE_KEY.USER, userInfo)
}, },
loginOut() { loginOut() {
@ -56,6 +62,7 @@ export const useUserStore = defineStore('admin-user', {
resetState() { resetState() {
this.permissions = [] this.permissions = []
this.roles = [] this.roles = []
this.isSetUser = false
this.user = { this.user = {
id: 0, id: 0,
avatar: '', avatar: '',