From 1ddfc31c3c4c792c5f741f6d0f0754ffc9a6613c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A0=E6=9C=A8?= Date: Thu, 26 Aug 2021 21:20:26 +0800 Subject: [PATCH] fix: `getUserinfo` is compatible with empty roles data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复getUserinfo接口数据未携带roles字段时登录失败的问题 --- src/store/modules/user.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index 285047d0..7f7226e6 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -14,6 +14,7 @@ import { router } from '/@/router'; import { usePermissionStore } from '/@/store/modules/permission'; import { RouteRecordRaw } from 'vue-router'; import { PAGE_NOT_FOUND_ROUTE } from '/@/router/routes/basic'; +import { isArray } from '/@/utils/is'; interface UserState { userInfo: Nullable; @@ -118,10 +119,15 @@ export const useUserStore = defineStore({ }, async getUserInfoAction(): Promise { const userInfo = await getUserInfo(); - const { roles } = userInfo; - const roleList = roles.map((item) => item.value) as RoleEnum[]; + const { roles = [] } = userInfo; + if (isArray(roles)) { + const roleList = roles.map((item) => item.value) as RoleEnum[]; + this.setRoleList(roleList); + } else { + userInfo.roles = []; + this.setRoleList([]); + } this.setUserInfo(userInfo); - this.setRoleList(roleList); return userInfo; }, /**