parent
357beabaeb
commit
ccaa84c305
|
|
@ -75,7 +75,7 @@
|
||||||
"@vueuse/shared": "^9.13.0",
|
"@vueuse/shared": "^9.13.0",
|
||||||
"@zxcvbn-ts/core": "^2.2.1",
|
"@zxcvbn-ts/core": "^2.2.1",
|
||||||
"ant-design-vue": "^3.2.17",
|
"ant-design-vue": "^3.2.17",
|
||||||
"axios": "^1.3.4",
|
"axios": "^1.3.5",
|
||||||
"codemirror": "^5.65.12",
|
"codemirror": "^5.65.12",
|
||||||
"cropperjs": "^1.5.13",
|
"cropperjs": "^1.5.13",
|
||||||
"crypto-js": "^4.1.1",
|
"crypto-js": "^4.1.1",
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,8 @@ importers:
|
||||||
specifier: ^3.2.17
|
specifier: ^3.2.17
|
||||||
version: 3.2.17(vue@3.2.47)
|
version: 3.2.17(vue@3.2.47)
|
||||||
axios:
|
axios:
|
||||||
specifier: ^1.3.4
|
specifier: ^1.3.5
|
||||||
version: 1.3.4
|
version: 1.3.5
|
||||||
codemirror:
|
codemirror:
|
||||||
specifier: ^5.65.12
|
specifier: ^5.65.12
|
||||||
version: 5.65.12
|
version: 5.65.12
|
||||||
|
|
@ -3021,8 +3021,8 @@ packages:
|
||||||
- debug
|
- debug
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/axios@1.3.4:
|
/axios@1.3.5:
|
||||||
resolution: {integrity: sha512-toYm+Bsyl6VC5wSkfkbbNB6ROv7KY93PEBBL6xyDczaIHasAiv4wPqQ/c4RjoQzipxRD2W5g21cOqQulZ7rHwQ==}
|
resolution: {integrity: sha512-glL/PvG/E+xCWwV8S6nCHcrfg1exGx7vxyUIivIA1iL7BIh6bePylCfVHwp6k13ao7SATxB6imau2kqY+I67kw==}
|
||||||
dependencies:
|
dependencies:
|
||||||
follow-redirects: 1.15.2(debug@4.3.4)
|
follow-redirects: 1.15.2(debug@4.3.4)
|
||||||
form-data: 4.0.0
|
form-data: 4.0.0
|
||||||
|
|
|
||||||
|
|
@ -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 { RequestOptions, Result, UploadFileParams } from '/#/axios';
|
||||||
import type { CreateAxiosOptions } from './axiosTransform';
|
import type { CreateAxiosOptions } from './axiosTransform';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
@ -63,7 +69,11 @@ export class VAxios {
|
||||||
* @description: Interceptor configuration 拦截器配置
|
* @description: Interceptor configuration 拦截器配置
|
||||||
*/
|
*/
|
||||||
private setupInterceptors() {
|
private setupInterceptors() {
|
||||||
const transform = this.getTransform();
|
// const transform = this.getTransform();
|
||||||
|
const {
|
||||||
|
axiosInstance,
|
||||||
|
options: { transform },
|
||||||
|
} = this;
|
||||||
if (!transform) {
|
if (!transform) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -77,16 +87,13 @@ export class VAxios {
|
||||||
const axiosCanceler = new AxiosCanceler();
|
const axiosCanceler = new AxiosCanceler();
|
||||||
|
|
||||||
// Request interceptor configuration processing
|
// 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
|
// If cancel repeat request is turned on, then cancel repeat request is prohibited
|
||||||
// @ts-ignore
|
const { requestOptions } = this.options;
|
||||||
const { ignoreCancelToken } = config.requestOptions;
|
const ignoreCancelToken = requestOptions?.ignoreCancelToken ?? true;
|
||||||
const ignoreCancel =
|
|
||||||
ignoreCancelToken !== undefined
|
!ignoreCancelToken && axiosCanceler.addPending(config);
|
||||||
? ignoreCancelToken
|
|
||||||
: this.options.requestOptions?.ignoreCancelToken;
|
|
||||||
|
|
||||||
!ignoreCancel && axiosCanceler.addPending(config);
|
|
||||||
if (requestInterceptors && isFunction(requestInterceptors)) {
|
if (requestInterceptors && isFunction(requestInterceptors)) {
|
||||||
config = requestInterceptors(config, this.options);
|
config = requestInterceptors(config, this.options);
|
||||||
}
|
}
|
||||||
|
|
@ -111,8 +118,7 @@ export class VAxios {
|
||||||
responseInterceptorsCatch &&
|
responseInterceptorsCatch &&
|
||||||
isFunction(responseInterceptorsCatch) &&
|
isFunction(responseInterceptorsCatch) &&
|
||||||
this.axiosInstance.interceptors.response.use(undefined, (error) => {
|
this.axiosInstance.interceptors.response.use(undefined, (error) => {
|
||||||
// @ts-ignore
|
return responseInterceptorsCatch(axiosInstance, error);
|
||||||
return responseInterceptorsCatch(this.axiosInstance, error);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,12 @@
|
||||||
/**
|
/**
|
||||||
* Data processing class, can be configured according to the project
|
* Data processing class, can be configured according to the project
|
||||||
*/
|
*/
|
||||||
import type { AxiosRequestConfig, AxiosResponse } from 'axios';
|
import type {
|
||||||
|
AxiosInstance,
|
||||||
|
AxiosRequestConfig,
|
||||||
|
AxiosResponse,
|
||||||
|
InternalAxiosRequestConfig
|
||||||
|
} from 'axios';
|
||||||
import type { RequestOptions, Result } from '/#/axios';
|
import type { RequestOptions, Result } from '/#/axios';
|
||||||
|
|
||||||
export interface CreateAxiosOptions extends AxiosRequestConfig {
|
export interface CreateAxiosOptions extends AxiosRequestConfig {
|
||||||
|
|
@ -12,8 +17,8 @@ export interface CreateAxiosOptions extends AxiosRequestConfig {
|
||||||
|
|
||||||
export abstract class AxiosTransform {
|
export abstract class AxiosTransform {
|
||||||
/**
|
/**
|
||||||
* @description: Process configuration before request
|
* A function that is called before a request is sent. It can modify the request configuration as needed.
|
||||||
* @description: Process configuration before request
|
* 在发送请求之前调用的函数。它可以根据需要修改请求配置。
|
||||||
*/
|
*/
|
||||||
beforeRequestHook?: (config: AxiosRequestConfig, options: RequestOptions) => AxiosRequestConfig;
|
beforeRequestHook?: (config: AxiosRequestConfig, options: RequestOptions) => AxiosRequestConfig;
|
||||||
|
|
||||||
|
|
@ -31,9 +36,9 @@ export abstract class AxiosTransform {
|
||||||
* @description: 请求之前的拦截器
|
* @description: 请求之前的拦截器
|
||||||
*/
|
*/
|
||||||
requestInterceptors?: (
|
requestInterceptors?: (
|
||||||
config: AxiosRequestConfig,
|
config: InternalAxiosRequestConfig,
|
||||||
options: CreateAxiosOptions,
|
options: CreateAxiosOptions,
|
||||||
) => AxiosRequestConfig;
|
) => InternalAxiosRequestConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: 请求之后的拦截器
|
* @description: 请求之后的拦截器
|
||||||
|
|
@ -48,5 +53,5 @@ export abstract class AxiosTransform {
|
||||||
/**
|
/**
|
||||||
* @description: 请求之后的拦截器错误处理
|
* @description: 请求之后的拦截器错误处理
|
||||||
*/
|
*/
|
||||||
responseInterceptorsCatch?: (axiosInstance: AxiosResponse, error: Error) => void;
|
responseInterceptorsCatch?: (axiosInstance: AxiosInstance, error: Error) => void;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue