2024-09-28 21:18:45 +08:00
|
|
|
|
import type { AxiosRequestConfig, CustomParamsSerializer } from 'axios';
|
|
|
|
|
import { stringify } from 'qs';
|
|
|
|
|
|
|
|
|
|
export const whiteList = ['/refresh-token', '/login'];
|
|
|
|
|
|
|
|
|
|
// 相关配置请参考:www.axios-js.com/zh-cn/docs/#axios-request-config-1
|
|
|
|
|
export const defaultConfig: AxiosRequestConfig = {
|
2025-04-24 13:43:37 +08:00
|
|
|
|
// 默认请求地址
|
2025-04-29 18:18:07 +08:00
|
|
|
|
baseURL: '/api',
|
2025-04-24 13:43:37 +08:00
|
|
|
|
// 设置超时时间
|
2025-05-02 13:18:15 +08:00
|
|
|
|
timeout: 19000,
|
2025-04-24 13:43:37 +08:00
|
|
|
|
// @ts-expect-error
|
2025-04-29 18:18:07 +08:00
|
|
|
|
retry: 3, //设置全局重试请求次数(最多重试几次请求)
|
|
|
|
|
retryDelay: 3000, //设置全局请求间隔
|
2025-04-24 13:43:37 +08:00
|
|
|
|
// 跨域允许携带凭证
|
|
|
|
|
// withCredentials: true,
|
|
|
|
|
headers: {
|
|
|
|
|
Accept: 'application/json, text/plain, */*',
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'X-Requested-With': 'XMLHttpRequest',
|
|
|
|
|
},
|
|
|
|
|
// 数组格式参数序列化(https://github.com/axios/axios/issues/5142)
|
|
|
|
|
paramsSerializer: {
|
|
|
|
|
serialize: stringify as unknown as CustomParamsSerializer,
|
|
|
|
|
},
|
2024-09-28 21:18:45 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 相关配置请参考:www.axios-js.com/zh-cn/docs/#axios-request-config-1
|
|
|
|
|
export const defaultMockConfig: AxiosRequestConfig = {
|
2025-04-24 13:43:37 +08:00
|
|
|
|
timeout: import.meta.env.VITE_BASE_API_TIMEOUT,
|
|
|
|
|
baseURL: import.meta.env.VITE_MOCK_BASE_API || '/mock',
|
|
|
|
|
headers: {
|
|
|
|
|
Accept: 'application/json, text/plain, */*',
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'X-Requested-With': 'XMLHttpRequest',
|
|
|
|
|
},
|
|
|
|
|
// 数组格式参数序列化(https://github.com/axios/axios/issues/5142)
|
|
|
|
|
paramsSerializer: {
|
|
|
|
|
serialize: stringify as unknown as CustomParamsSerializer,
|
|
|
|
|
},
|
2024-09-28 21:18:45 +08:00
|
|
|
|
};
|