fix: 优化用户信息展示
This commit is contained in:
+18
-3
@@ -3,6 +3,7 @@ import type { MenuNode, PermissionCode } from '@/types';
|
||||
import { FALLBACK_MENU_NODES } from '@/config/fallbackRoutes';
|
||||
import { getAuthDataPromise, setAuthDataPromise, clearAuthDataCache } from '@/api/authCache';
|
||||
import { forceReLogin } from '@/hooks/useAuth';
|
||||
import { useUserStore } from '@/stores/userStore';
|
||||
|
||||
export { clearAuthDataCache } from '@/api/authCache';
|
||||
|
||||
@@ -12,6 +13,8 @@ export { clearAuthDataCache } from '@/api/authCache';
|
||||
export interface AuthData {
|
||||
roleList: string[];
|
||||
permsList: string[];
|
||||
nickname: string;
|
||||
phone: string;
|
||||
}
|
||||
|
||||
const AUTH_FETCH_FAIL_MSG = '账户权限获取失败,请重新登录';
|
||||
@@ -21,14 +24,26 @@ function normalizeAuthData(res: any): AuthData {
|
||||
throw new Error(res.msg || AUTH_FETCH_FAIL_MSG);
|
||||
}
|
||||
|
||||
const roleList = res?.data?.roleList || [];
|
||||
const permsList = res?.data?.permsList || [];
|
||||
const data = res?.data || {};
|
||||
const roleList = data.roleList || [];
|
||||
const permsList = data.permsList || [];
|
||||
|
||||
if (permsList.length === 0) {
|
||||
throw new Error(AUTH_FETCH_FAIL_MSG);
|
||||
}
|
||||
|
||||
return { roleList, permsList };
|
||||
const nickname = data.nickName || '';
|
||||
const phone = typeof data.phone === 'string' ? data.phone : '';
|
||||
|
||||
if (nickname || phone) {
|
||||
const { setUser } = useUserStore();
|
||||
setUser({
|
||||
...(nickname ? { nickname } : {}),
|
||||
...(phone ? { phone } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
return { roleList, permsList, nickname, phone };
|
||||
}
|
||||
|
||||
function handleAuthFetchFailure() {
|
||||
|
||||
Reference in New Issue
Block a user