From 73df6a1b30c7720c76cbe2dfd3d94ae51a18a739 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子Li <15040126243@163.com>
Date: 星期三, 09 八月 2023 15:18:25 +0800
Subject: [PATCH] !34 修复编译报类型错误问题 Merge pull request !34 from VergLsm/ts

---
 src/utils/request.ts |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/src/utils/request.ts b/src/utils/request.ts
index d5fac4e..4ade2f4 100644
--- a/src/utils/request.ts
+++ b/src/utils/request.ts
@@ -8,12 +8,21 @@
 import { LoadingInstance } from 'element-plus/es/components/loading/src/loading';
 import FileSaver from 'file-saver';
 import { getLanguage } from '@/lang';
+import { encryptBase64, encryptWithAes, generateAesKey } from '@/utils/crypto';
+import { encrypt } from '@/utils/jsencrypt';
 
 let downloadLoadingInstance: LoadingInstance;
 // 鏄惁鏄剧ず閲嶆柊鐧诲綍
 export const isRelogin = { show: false };
+export const globalHeaders = () => {
+  return {
+    Authorization: "Bearer " + getToken(),
+    clientid: import.meta.env.VITE_APP_CLIENT_ID
+  }
+}
 
 axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8';
+axios.defaults.headers['clientid'] = import.meta.env.VITE_APP_CLIENT_ID;
 // 鍒涘缓 axios 瀹炰緥
 const service = axios.create({
   baseURL: import.meta.env.VITE_APP_BASE_API,
@@ -29,6 +38,8 @@
     const isToken = (config.headers || {}).isToken === false;
     // 鏄惁闇�瑕侀槻姝㈡暟鎹噸澶嶆彁浜�
     const isRepeatSubmit = (config.headers || {}).repeatSubmit === false;
+    // 鏄惁闇�瑕佸姞瀵�
+    const isEncrypt = (config.headers || {}).isEncrypt === 'true';
     if (getToken() && !isToken) {
       config.headers['Authorization'] = 'Bearer ' + getToken(); // 璁╂瘡涓姹傛惡甯﹁嚜瀹氫箟token 璇锋牴鎹疄闄呮儏鍐佃嚜琛屼慨鏀�
     }
@@ -63,6 +74,13 @@
         }
       }
     }
+    // 褰撳紑鍚弬鏁板姞瀵�
+    if (isEncrypt && (config.method === 'post' || config.method === 'put')) {
+      // 鐢熸垚涓�涓� AES 瀵嗛挜
+      const aesKey = generateAesKey();
+      config.headers['encrypt-key'] = 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) {
       delete config.headers['Content-Type'];

--
Gitblit v1.9.3