Feature/0723/zr #9
+6
-5
@@ -18,6 +18,7 @@ export interface AuthData {
|
||||
}
|
||||
|
||||
const AUTH_FETCH_FAIL_MSG = '账户权限获取失败,请重新登录';
|
||||
const AUTH_EMPTY_MSG = '当前账户权限无任何权限,请联系管理员';
|
||||
|
||||
function normalizeAuthData(res: any): AuthData {
|
||||
if (res?.code != null && res.code != 200) {
|
||||
@@ -29,7 +30,7 @@ function normalizeAuthData(res: any): AuthData {
|
||||
const permsList = data.permsList || [];
|
||||
|
||||
if (permsList.length === 0) {
|
||||
throw new Error(AUTH_FETCH_FAIL_MSG);
|
||||
throw new Error(AUTH_EMPTY_MSG);
|
||||
}
|
||||
|
||||
const nickname = data.nickName || '';
|
||||
@@ -46,9 +47,9 @@ function normalizeAuthData(res: any): AuthData {
|
||||
return { roleList, permsList, nickname, phone };
|
||||
}
|
||||
|
||||
function handleAuthFetchFailure() {
|
||||
function handleAuthFetchFailure(msg?: string) {
|
||||
clearAuthDataCache();
|
||||
forceReLogin(AUTH_FETCH_FAIL_MSG);
|
||||
forceReLogin(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,8 +63,8 @@ export function fetchAuthData(): Promise<AuthData> {
|
||||
|
||||
const promise = get('/op/permission')
|
||||
.then((res) => normalizeAuthData(res))
|
||||
.catch((err) => {
|
||||
handleAuthFetchFailure();
|
||||
.catch((err: Error) => {
|
||||
handleAuthFetchFailure(err.message);
|
||||
throw err;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user