Commit cbeee0f7440e5f440c487155018aac547434b1c2
1 parent
c3560a52
fix: 新用户第一次未设置角色无法登录 bug
Showing
2 changed files
with
8 additions
and
1 deletions
yudao-ui-admin-vue3/src/router/index.ts
| @@ -55,7 +55,7 @@ router.beforeEach(async (to, from, next) => { | @@ -55,7 +55,7 @@ router.beforeEach(async (to, from, next) => { | ||
| 55 | const res = await listSimpleDictDataApi() | 55 | const res = await listSimpleDictDataApi() |
| 56 | dictStore.setDictMap(res) | 56 | dictStore.setDictMap(res) |
| 57 | } | 57 | } |
| 58 | - if (userStore.getRoles.length === 0) { | 58 | + if (!userStore.getIsSetUser) { |
| 59 | isRelogin.show = true | 59 | isRelogin.show = true |
| 60 | const res = await getInfoApi() | 60 | const res = await getInfoApi() |
| 61 | await userStore.setUserInfoAction(res) | 61 | await userStore.setUserInfoAction(res) |
yudao-ui-admin-vue3/src/store/modules/user.ts
| @@ -13,6 +13,7 @@ interface UserVO { | @@ -13,6 +13,7 @@ interface UserVO { | ||
| 13 | interface UserInfoVO { | 13 | interface UserInfoVO { |
| 14 | permissions: string[] | 14 | permissions: string[] |
| 15 | roles: string[] | 15 | roles: string[] |
| 16 | + isSetUser: boolean | ||
| 16 | user: UserVO | 17 | user: UserVO |
| 17 | } | 18 | } |
| 18 | 19 | ||
| @@ -20,6 +21,7 @@ export const useUserStore = defineStore('admin-user', { | @@ -20,6 +21,7 @@ export const useUserStore = defineStore('admin-user', { | ||
| 20 | state: (): UserInfoVO => ({ | 21 | state: (): UserInfoVO => ({ |
| 21 | permissions: [], | 22 | permissions: [], |
| 22 | roles: [], | 23 | roles: [], |
| 24 | + isSetUser: false, | ||
| 23 | user: { | 25 | user: { |
| 24 | id: 0, | 26 | id: 0, |
| 25 | avatar: '', | 27 | avatar: '', |
| @@ -33,6 +35,9 @@ export const useUserStore = defineStore('admin-user', { | @@ -33,6 +35,9 @@ export const useUserStore = defineStore('admin-user', { | ||
| 33 | getRoles(): string[] { | 35 | getRoles(): string[] { |
| 34 | return this.roles | 36 | return this.roles |
| 35 | }, | 37 | }, |
| 38 | + getIsSetUser(): boolean { | ||
| 39 | + return this.isSetUser | ||
| 40 | + }, | ||
| 36 | getUser(): UserVO { | 41 | getUser(): UserVO { |
| 37 | return this.user | 42 | return this.user |
| 38 | } | 43 | } |
| @@ -46,6 +51,7 @@ export const useUserStore = defineStore('admin-user', { | @@ -46,6 +51,7 @@ export const useUserStore = defineStore('admin-user', { | ||
| 46 | this.permissions = userInfo.permissions | 51 | this.permissions = userInfo.permissions |
| 47 | this.roles = userInfo.roles | 52 | this.roles = userInfo.roles |
| 48 | this.user = userInfo.user | 53 | this.user = userInfo.user |
| 54 | + this.isSetUser = true | ||
| 49 | wsCache.set(CACHE_KEY.USER, userInfo) | 55 | wsCache.set(CACHE_KEY.USER, userInfo) |
| 50 | }, | 56 | }, |
| 51 | loginOut() { | 57 | loginOut() { |
| @@ -56,6 +62,7 @@ export const useUserStore = defineStore('admin-user', { | @@ -56,6 +62,7 @@ export const useUserStore = defineStore('admin-user', { | ||
| 56 | resetState() { | 62 | resetState() { |
| 57 | this.permissions = [] | 63 | this.permissions = [] |
| 58 | this.roles = [] | 64 | this.roles = [] |
| 65 | + this.isSetUser = false | ||
| 59 | this.user = { | 66 | this.user = { |
| 60 | id: 0, | 67 | id: 0, |
| 61 | avatar: '', | 68 | avatar: '', |