fix(登录):token 过期直接跳转登录页,不再弹确认框
后端 CommonResult 包装设计保留原样,不引入自定义业务码。
改法:handleError 中检测到 401 后直接清除 localStorage
并 router.push('/login'),移除 ElMessageBox.confirm 确认框。
This commit is contained in:
+4
-16
@@ -1,5 +1,5 @@
|
||||
import axios from 'axios';
|
||||
import { ElMessage, ElMessageBox } from "element-plus";
|
||||
import { ElMessage } from "element-plus";
|
||||
import router from "@/router";
|
||||
|
||||
const basic_url = import.meta.env.VITE_BASE_URL;
|
||||
@@ -13,22 +13,10 @@ const axiosInstance = axios.create({
|
||||
const handleError = (error: any) => {
|
||||
console.log(error);
|
||||
|
||||
// 401 未授权:token 过期或未登录(优先检查,避免被后续逻辑拦截)
|
||||
// 401 未授权:token 过期或未登录,直接跳转登录页
|
||||
if (error?.response?.status === 401) {
|
||||
ElMessageBox.confirm(
|
||||
'登录已过期,请重新登录',
|
||||
'提示',
|
||||
{
|
||||
confirmButtonText: '重新登录',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
}
|
||||
).then(() => {
|
||||
localStorage.removeItem("isLoggedIn");
|
||||
router.push("/login");
|
||||
}).catch(() => {
|
||||
// 用户点击取消,不做处理
|
||||
});
|
||||
localStorage.removeItem("isLoggedIn");
|
||||
router.push("/login");
|
||||
return Promise.reject(error);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user