|
@@ -17,11 +17,13 @@ type customOptionsType = {
|
|
|
code_message_show?: boolean; // 是否开启code不为0时的信息提示, 默认为false
|
|
|
is_need_token?: boolean; // 是否需要token
|
|
|
};
|
|
|
+// 请求超时时间
|
|
|
+const TIMEOUT = 60 * 1000; // 60s
|
|
|
export default function myAxios(axiosConfig: any, customOptions?: customOptionsType, loadingOptions?: LoadingOptionsResolved) {
|
|
|
// 配置新建一个 axios 实例
|
|
|
const service: AxiosInstance = axios.create({
|
|
|
baseURL: import.meta.env.VITE_API_URL,
|
|
|
- timeout: 60000,
|
|
|
+ timeout: TIMEOUT,
|
|
|
headers: { 'Content-Type': 'application/json' },
|
|
|
});
|
|
|
|
|
@@ -52,7 +54,7 @@ export default function myAxios(axiosConfig: any, customOptions?: customOptionsT
|
|
|
}
|
|
|
// 在发送请求之前做些什么 token
|
|
|
if (Cookie.get('token')) {
|
|
|
- if(custom_options.is_need_token){
|
|
|
+ if (custom_options.is_need_token) {
|
|
|
(<any>config.headers)['Authorization'] = `Bearer ${Cookie.get('token')}`;
|
|
|
}
|
|
|
}
|
|
@@ -93,7 +95,7 @@ export default function myAxios(axiosConfig: any, customOptions?: customOptionsT
|
|
|
* @param {*} error
|
|
|
*/
|
|
|
// 设置一个变量 处理同一时间多个错误重复弹窗口
|
|
|
-let hasShown401 = false; // 用于判断是否已经弹出过401提示
|
|
|
+let hasShown401 = false; // 用于判断是否已经弹出过401提示
|
|
|
function httpErrorStatusHandle(error: any) {
|
|
|
// 处理被取消的请求
|
|
|
if (axios.isCancel(error)) return;
|
|
@@ -177,7 +179,7 @@ function httpErrorStatusHandle(error: any) {
|
|
|
ElMessage({
|
|
|
type: 'error',
|
|
|
message,
|
|
|
- grouping:true
|
|
|
+ grouping: true,
|
|
|
});
|
|
|
}
|
|
|
}
|