|
|
|
@ -1,4 +1,10 @@ |
|
|
|
import type { AxiosRequestConfig, AxiosInstance, AxiosResponse, AxiosError } from 'axios'; |
|
|
|
import type { |
|
|
|
AxiosRequestConfig, |
|
|
|
AxiosInstance, |
|
|
|
AxiosResponse, |
|
|
|
AxiosError, |
|
|
|
InternalAxiosRequestConfig, |
|
|
|
} from 'axios'; |
|
|
|
import type { RequestOptions, Result, UploadFileParams } from '/#/axios'; |
|
|
|
import type { CreateAxiosOptions } from './axiosTransform'; |
|
|
|
import axios from 'axios'; |
|
|
|
@ -63,7 +69,11 @@ export class VAxios { |
|
|
|
* @description: Interceptor configuration 拦截器配置 |
|
|
|
*/ |
|
|
|
private setupInterceptors() { |
|
|
|
const transform = this.getTransform(); |
|
|
|
// const transform = this.getTransform();
|
|
|
|
const { |
|
|
|
axiosInstance, |
|
|
|
options: { transform }, |
|
|
|
} = this; |
|
|
|
if (!transform) { |
|
|
|
return; |
|
|
|
} |
|
|
|
@ -77,16 +87,13 @@ export class VAxios { |
|
|
|
const axiosCanceler = new AxiosCanceler(); |
|
|
|
|
|
|
|
// Request interceptor configuration processing
|
|
|
|
this.axiosInstance.interceptors.request.use((config: AxiosRequestConfig) => { |
|
|
|
this.axiosInstance.interceptors.request.use((config: InternalAxiosRequestConfig) => { |
|
|
|
// If cancel repeat request is turned on, then cancel repeat request is prohibited
|
|
|
|
// @ts-ignore
|
|
|
|
const { ignoreCancelToken } = config.requestOptions; |
|
|
|
const ignoreCancel = |
|
|
|
ignoreCancelToken !== undefined |
|
|
|
? ignoreCancelToken |
|
|
|
: this.options.requestOptions?.ignoreCancelToken; |
|
|
|
|
|
|
|
!ignoreCancel && axiosCanceler.addPending(config); |
|
|
|
const { requestOptions } = this.options; |
|
|
|
const ignoreCancelToken = requestOptions?.ignoreCancelToken ?? true; |
|
|
|
|
|
|
|
!ignoreCancelToken && axiosCanceler.addPending(config); |
|
|
|
|
|
|
|
if (requestInterceptors && isFunction(requestInterceptors)) { |
|
|
|
config = requestInterceptors(config, this.options); |
|
|
|
} |
|
|
|
@ -111,8 +118,7 @@ export class VAxios { |
|
|
|
responseInterceptorsCatch && |
|
|
|
isFunction(responseInterceptorsCatch) && |
|
|
|
this.axiosInstance.interceptors.response.use(undefined, (error) => { |
|
|
|
// @ts-ignore
|
|
|
|
return responseInterceptorsCatch(this.axiosInstance, error); |
|
|
|
return responseInterceptorsCatch(axiosInstance, error); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|