From a63543a5c793c8954fa2f9da0ee4fb215c62d8c2 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子Li <15040126243@163.com>
Date: 星期一, 20 五月 2024 10:26:46 +0800
Subject: [PATCH] !118 ♥️发布 5.2.0-BETA 公测版本 Merge pull request !118 from 疯狂的狮子Li/dev

---
 src/utils/request.ts |   51 +++++++++++++++++++++++++++------------------------
 1 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/src/utils/request.ts b/src/utils/request.ts
index a183ca6..f2a69f0 100644
--- a/src/utils/request.ts
+++ b/src/utils/request.ts
@@ -36,11 +36,12 @@
     // 瀵瑰簲鍥介檯鍖栬祫婧愭枃浠跺悗缂�
     config.headers['Content-Language'] = getLanguage();
 
-    const isToken = (config.headers || {}).isToken === false;
+    const isToken = config.headers?.isToken === false;
     // 鏄惁闇�瑕侀槻姝㈡暟鎹噸澶嶆彁浜�
-    const isRepeatSubmit = (config.headers || {}).repeatSubmit === false;
+    const isRepeatSubmit = config.headers?.repeatSubmit === false;
     // 鏄惁闇�瑕佸姞瀵�
-    const isEncrypt = (config.headers || {}).isEncrypt === 'true';
+    const isEncrypt = config.headers?.isEncrypt === 'true';
+
     if (getToken() && !isToken) {
       config.headers['Authorization'] = 'Bearer ' + getToken(); // 璁╂瘡涓姹傛惡甯﹁嚜瀹氫箟token 璇锋牴鎹疄闄呮儏鍐佃嚜琛屼慨鏀�
     }
@@ -75,12 +76,14 @@
         }
       }
     }
-    // 褰撳紑鍚弬鏁板姞瀵�
-    if (isEncrypt && (config.method === 'post' || config.method === 'put')) {
-      // 鐢熸垚涓�涓� AES 瀵嗛挜
-      const aesKey = generateAesKey();
-      config.headers[encryptHeader] = encrypt(encryptBase64(aesKey));
-      config.data = typeof config.data === 'object' ? encryptWithAes(JSON.stringify(config.data), aesKey) : encryptWithAes(config.data, aesKey);
+    if (import.meta.env.VITE_APP_ENCRYPT === 'true') {
+      // 褰撳紑鍚弬鏁板姞瀵�
+      if (isEncrypt && (config.method === 'post' || config.method === 'put')) {
+        // 鐢熸垚涓�涓� AES 瀵嗛挜
+        const aesKey = generateAesKey();
+        config.headers[encryptHeader] = encrypt(encryptBase64(aesKey));
+        config.data = typeof config.data === 'object' ? encryptWithAes(JSON.stringify(config.data), aesKey) : encryptWithAes(config.data, aesKey);
+      }
     }
     // FormData鏁版嵁鍘昏姹傚ごContent-Type
     if (config.data instanceof FormData) {
@@ -89,7 +92,6 @@
     return config;
   },
   (error: any) => {
-    console.log(error);
     return Promise.reject(error);
   }
 );
@@ -97,19 +99,21 @@
 // 鍝嶅簲鎷︽埅鍣�
 service.interceptors.response.use(
   (res: AxiosResponse) => {
-    // 鍔犲瘑鍚庣殑 AES 绉橀挜
-    const keyStr = res.headers[encryptHeader];
-    // 鍔犲瘑
-    if (keyStr != null && keyStr != '') {
-      const data = res.data;
-      // 璇锋眰浣� AES 瑙e瘑
-      const base64Str = decrypt(keyStr);
-      // base64 瑙g爜 寰楀埌璇锋眰澶寸殑 AES 绉橀挜
-      const aesKey = decryptBase64(base64Str.toString());
-      // aesKey 瑙g爜 data
-      const decryptData = decryptWithAes(data, aesKey);
-      // 灏嗙粨鏋� (寰楀埌鐨勬槸 JSON 瀛楃涓�) 杞负 JSON
-      res.data = JSON.parse(decryptData);
+    if (import.meta.env.VITE_APP_ENCRYPT === 'true') {
+      // 鍔犲瘑鍚庣殑 AES 绉橀挜
+      const keyStr = res.headers[encryptHeader];
+      // 鍔犲瘑
+      if (keyStr != null && keyStr != '') {
+        const data = res.data;
+        // 璇锋眰浣� AES 瑙e瘑
+        const base64Str = decrypt(keyStr);
+        // base64 瑙g爜 寰楀埌璇锋眰澶寸殑 AES 绉橀挜
+        const aesKey = decryptBase64(base64Str.toString());
+        // aesKey 瑙g爜 data
+        const decryptData = decryptWithAes(data, aesKey);
+        // 灏嗙粨鏋� (寰楀埌鐨勬槸 JSON 瀛楃涓�) 杞负 JSON
+        res.data = JSON.parse(decryptData);
+      }
     }
     // 鏈缃姸鎬佺爜鍒欓粯璁ゆ垚鍔熺姸鎬�
     const code = res.data.code || HttpStatus.SUCCESS;
@@ -138,7 +142,6 @@
       }
       return Promise.reject('鏃犳晥鐨勪細璇濓紝鎴栬�呬細璇濆凡杩囨湡锛岃閲嶆柊鐧诲綍銆�');
     } else if (code === HttpStatus.SERVER_ERROR) {
-      console.log(msg);
       ElMessage({ message: msg, type: 'error' });
       return Promise.reject(new Error(msg));
     } else if (code === HttpStatus.WARN) {

--
Gitblit v1.9.3