fix: 修复重复跳转登录页面问题及优化接口配置
This commit is contained in:
@@ -65,16 +65,26 @@ export function hasPerm(value: string | string[], type: "button" | "role" = "but
|
||||
: value.some((perm) => auths.includes(perm));
|
||||
}
|
||||
|
||||
let redirectingToLogin = false;
|
||||
|
||||
/**
|
||||
* 重定向到登录页面
|
||||
*/
|
||||
export async function redirectToLogin(message: string = "请重新登录"): Promise<void> {
|
||||
ElNotification({
|
||||
title: "提示",
|
||||
message,
|
||||
type: "warning",
|
||||
duration: 3000,
|
||||
});
|
||||
export async function redirectToLogin(
|
||||
message: string = "请重新登录",
|
||||
notify: boolean = true
|
||||
): Promise<void> {
|
||||
if (redirectingToLogin) return;
|
||||
redirectingToLogin = true;
|
||||
|
||||
if (notify) {
|
||||
ElNotification({
|
||||
title: "提示",
|
||||
message,
|
||||
type: "warning",
|
||||
duration: 3000,
|
||||
});
|
||||
}
|
||||
|
||||
await useUserStoreHook().resetAllState();
|
||||
|
||||
@@ -86,5 +96,7 @@ export async function redirectToLogin(message: string = "请重新登录"): Prom
|
||||
console.error("Redirect to login error:", error);
|
||||
// 强制跳转,即使路由重定向失败
|
||||
window.location.href = "/login";
|
||||
} finally {
|
||||
redirectingToLogin = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,8 +90,8 @@ http.interceptors.response.use(
|
||||
|
||||
// Refresh token 失效:无法续期,跳转登录
|
||||
if (code === ApiCodeEnum.REFRESH_TOKEN_INVALID) {
|
||||
await redirectToLogin("登录已过期,请重新登录");
|
||||
return Promise.reject(new Error(msg || "Token Invalid"));
|
||||
await redirectToLogin("登录已过期,请重新登录", false);
|
||||
return Promise.reject(new Error("Token Invalid"));
|
||||
}
|
||||
|
||||
// 权限不足:刷新权限快照后提示
|
||||
|
||||
Reference in New Issue
Block a user