From e8bbe0ac15b3d13e687054105de2b89974d2ba09 Mon Sep 17 00:00:00 2001
From: WeiHan <1844152414@qq.com>
Date: 星期五, 24 一月 2025 15:10:25 +0800
Subject: [PATCH] update src/components/Process/approvalRecord.vue.
---
src/utils/request.ts | 64 ++++++++++++++++++++++---------
1 files changed, 45 insertions(+), 19 deletions(-)
diff --git a/src/utils/request.ts b/src/utils/request.ts
index 5b8480b..9682b81 100644
--- a/src/utils/request.ts
+++ b/src/utils/request.ts
@@ -8,16 +8,20 @@
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';
+import { encryptBase64, encryptWithAes, generateAesKey, decryptWithAes, decryptBase64 } from '@/utils/crypto';
+import { encrypt, decrypt } from '@/utils/jsencrypt';
+import router from '@/router';
+const encryptHeader = 'encrypt-key';
let downloadLoadingInstance: LoadingInstance;
// 鏄惁鏄剧ず閲嶆柊鐧诲綍
export const isRelogin = { show: false };
-export const globalHeaders = {
- Authorization: "Bearer " + getToken(),
- clientid: import.meta.env.VITE_APP_CLIENT_ID
-}
+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;
@@ -33,11 +37,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 璇锋牴鎹疄闄呮儏鍐佃嚜琛屼慨鏀�
}
@@ -72,12 +77,14 @@
}
}
}
- // 褰撳紑鍚弬鏁板姞瀵�
- 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);
+ 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) {
@@ -86,7 +93,6 @@
return config;
},
(error: any) => {
- console.log(error);
return Promise.reject(error);
}
);
@@ -94,6 +100,22 @@
// 鍝嶅簲鎷︽埅鍣�
service.interceptors.response.use(
(res: AxiosResponse) => {
+ 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;
// 鑾峰彇閿欒淇℃伅
@@ -113,15 +135,19 @@
}).then(() => {
isRelogin.show = false;
useUserStore().logout().then(() => {
- location.href = import.meta.env.VITE_APP_CONTEXT_PATH + 'index';
- });
+ router.replace({
+ path: '/login',
+ query: {
+ redirect: encodeURIComponent(router.currentRoute.value.fullPath || '/')
+ }
+ })
+ });
}).catch(() => {
isRelogin.show = false;
});
}
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