?
This commit is contained in:
@@ -13,6 +13,9 @@ const axiosInstance = axios.create({
|
||||
timeout: 10000
|
||||
});
|
||||
|
||||
// 并发锁:防止多个 401 同时触发重复 logout
|
||||
let isHandlingUnauthorized = false;
|
||||
|
||||
export function setupInterceptors() {
|
||||
/**
|
||||
* 请求拦截器
|
||||
@@ -50,7 +53,15 @@ export function setupInterceptors() {
|
||||
|
||||
// 如果收到401错误,并且不是来自登录请求本身
|
||||
if (error.response && error.response.status === 401 && originalRequest.url !== '/user/login') {
|
||||
logoutUser(); // 调用简化的logoutUser,它只清除token,不导航
|
||||
if (!isHandlingUnauthorized) {
|
||||
isHandlingUnauthorized = true;
|
||||
try {
|
||||
logoutUser(); // 清除token,路由守卫将处理跳转
|
||||
} finally {
|
||||
// 在短时间后解除锁,避免长时间无法重新登录
|
||||
setTimeout(() => { isHandlingUnauthorized = false; }, 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 不需要额外的console.error,错误会自然地在调用处被捕获或显示在网络请求中
|
||||
return Promise.reject(error);
|
||||
|
||||
@@ -182,19 +182,3 @@ export const resetPassword = async (token, password) => {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户临时权限信息
|
||||
* 路由: /user/temp_privilege
|
||||
* 方法: GET
|
||||
*
|
||||
* 需要登录
|
||||
* @returns {Promise<Object>} 返回一个包含临时权限信息的Promise对象
|
||||
*/
|
||||
export const getTempPrivilege = async () => {
|
||||
try {
|
||||
const response = await axiosInstance.get('/user/temp_privilege');
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,51 +1,5 @@
|
||||
import axiosInstance from './axiosConfig';
|
||||
|
||||
// const API_BASE_URL = 'http://zybdatasupport.online:8000' // 不再需要
|
||||
|
||||
// // 创建 axios 实例 // 不再需要
|
||||
// const axiosInstance = axios.create({
|
||||
// baseURL: API_BASE_URL,
|
||||
// headers: {
|
||||
// 'Content-Type': 'application/json',
|
||||
// 'Accept': 'application/json',
|
||||
// 'X-Requested-With': 'XMLHttpRequest'
|
||||
// },
|
||||
// timeout: 10000
|
||||
// })
|
||||
|
||||
// // 设置请求拦截器,自动添加 token // 不再需要
|
||||
// axiosInstance.interceptors.request.use(
|
||||
// config => {
|
||||
// const token = localStorage.getItem('access_token')
|
||||
// if (token) {
|
||||
// config.headers.Authorization = `Bearer ${token}`
|
||||
// }
|
||||
// return config
|
||||
// },
|
||||
// error => {
|
||||
// return Promise.reject(error)
|
||||
// }
|
||||
// )
|
||||
|
||||
// // 添加响应拦截器 // 不再需要
|
||||
// axiosInstance.interceptors.response.use(
|
||||
// response => response,
|
||||
// error => {
|
||||
// if (error.response) {
|
||||
// console.error('请求错误:', {
|
||||
// status: error.response.status,
|
||||
// data: error.response.data,
|
||||
// config: error.config
|
||||
// })
|
||||
// } else if (error.request) {
|
||||
// console.error('网络错误:', error.request)
|
||||
// } else {
|
||||
// console.error('请求配置错误:', error.message)
|
||||
// }
|
||||
// return Promise.reject(error)
|
||||
// }
|
||||
// )
|
||||
|
||||
/**
|
||||
* 添加赛事
|
||||
* @param {Object} tournamentData - 赛事数据
|
||||
|
||||
Reference in New Issue
Block a user