Przeglądaj źródła

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

xingyu4j 2 lat temu
rodzic
commit
cbeee0f744

+ 1 - 1
yudao-ui-admin-vue3/src/router/index.ts

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

+ 7 - 0
yudao-ui-admin-vue3/src/store/modules/user.ts

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