From ccaa84c3058c7f7ff5ac9ce14ec1d951c87fa5a6 Mon Sep 17 00:00:00 2001
From: Kirk Lin <linkirk@163.com>
Date: 星期四, 06 四月 2023 22:02:42 +0800
Subject: [PATCH] fix: axios type (#2678)

---
 package.json                           |    2 +-
 src/utils/http/axios/axiosTransform.ts |   17 +++++++++++------
 src/utils/http/axios/Axios.ts          |   30 ++++++++++++++++++------------
 pnpm-lock.yaml                         |    8 ++++----
 4 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/package.json b/package.json
index f6e5798..13ad7ee 100644
--- a/package.json
+++ b/package.json
@@ -75,7 +75,7 @@
     "@vueuse/shared": "^9.13.0",
     "@zxcvbn-ts/core": "^2.2.1",
     "ant-design-vue": "^3.2.17",
-    "axios": "^1.3.4",
+    "axios": "^1.3.5",
     "codemirror": "^5.65.12",
     "cropperjs": "^1.5.13",
     "crypto-js": "^4.1.1",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 6518593..391416d 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -32,8 +32,8 @@
         specifier: ^3.2.17
         version: 3.2.17(vue@3.2.47)
       axios:
-        specifier: ^1.3.4
-        version: 1.3.4
+        specifier: ^1.3.5
+        version: 1.3.5
       codemirror:
         specifier: ^5.65.12
         version: 5.65.12
@@ -3021,8 +3021,8 @@
       - debug
     dev: true
 
-  /axios@1.3.4:
-    resolution: {integrity: sha512-toYm+Bsyl6VC5wSkfkbbNB6ROv7KY93PEBBL6xyDczaIHasAiv4wPqQ/c4RjoQzipxRD2W5g21cOqQulZ7rHwQ==}
+  /axios@1.3.5:
+    resolution: {integrity: sha512-glL/PvG/E+xCWwV8S6nCHcrfg1exGx7vxyUIivIA1iL7BIh6bePylCfVHwp6k13ao7SATxB6imau2kqY+I67kw==}
     dependencies:
       follow-redirects: 1.15.2(debug@4.3.4)
       form-data: 4.0.0
diff --git a/src/utils/http/axios/Axios.ts b/src/utils/http/axios/Axios.ts
index 62730cc..38b9a59 100644
--- a/src/utils/http/axios/Axios.ts
+++ b/src/utils/http/axios/Axios.ts
@@ -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 @@
    * @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 @@
     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;
+      const { requestOptions } = this.options;
+      const ignoreCancelToken = requestOptions?.ignoreCancelToken ?? true;
 
-      !ignoreCancel && axiosCanceler.addPending(config);
+      !ignoreCancelToken && axiosCanceler.addPending(config);
+
       if (requestInterceptors && isFunction(requestInterceptors)) {
         config = requestInterceptors(config, this.options);
       }
@@ -111,8 +118,7 @@
     responseInterceptorsCatch &&
       isFunction(responseInterceptorsCatch) &&
       this.axiosInstance.interceptors.response.use(undefined, (error) => {
-        // @ts-ignore
-        return responseInterceptorsCatch(this.axiosInstance, error);
+        return responseInterceptorsCatch(axiosInstance, error);
       });
   }
 
diff --git a/src/utils/http/axios/axiosTransform.ts b/src/utils/http/axios/axiosTransform.ts
index f65def9..b0cc0af 100644
--- a/src/utils/http/axios/axiosTransform.ts
+++ b/src/utils/http/axios/axiosTransform.ts
@@ -1,7 +1,12 @@
 /**
  * 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';
 
 export interface CreateAxiosOptions extends AxiosRequestConfig {
@@ -12,8 +17,8 @@
 
 export abstract class AxiosTransform {
   /**
-   * @description: Process configuration before request
-   * @description: Process configuration before request
+   * A function that is called before a request is sent. It can modify the request configuration as needed.
+   * 鍦ㄥ彂閫佽姹備箣鍓嶈皟鐢ㄧ殑鍑芥暟銆傚畠鍙互鏍规嵁闇�瑕佷慨鏀硅姹傞厤缃��
    */
   beforeRequestHook?: (config: AxiosRequestConfig, options: RequestOptions) => AxiosRequestConfig;
 
@@ -31,9 +36,9 @@
    * @description: 璇锋眰涔嬪墠鐨勬嫤鎴櫒
    */
   requestInterceptors?: (
-    config: AxiosRequestConfig,
+    config: InternalAxiosRequestConfig,
     options: CreateAxiosOptions,
-  ) => AxiosRequestConfig;
+  ) => InternalAxiosRequestConfig;
 
   /**
    * @description: 璇锋眰涔嬪悗鐨勬嫤鎴櫒
@@ -48,5 +53,5 @@
   /**
    * @description: 璇锋眰涔嬪悗鐨勬嫤鎴櫒閿欒澶勭悊
    */
-  responseInterceptorsCatch?: (axiosInstance: AxiosResponse, error: Error) => void;
+  responseInterceptorsCatch?: (axiosInstance: AxiosInstance, error: Error) => void;
 }

--
Gitblit v1.8.0