From d160c3a61cc38359de4794b208884bba430f0a1c Mon Sep 17 00:00:00 2001 From: LiuHao <liuhaoai545@gmail.com> Date: 星期一, 10 七月 2023 22:56:42 +0800 Subject: [PATCH] merge --- src/utils/request.ts | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-) diff --git a/src/utils/request.ts b/src/utils/request.ts index d5fac4e..74f0d19 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -8,6 +8,8 @@ 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; // 鏄惁鏄剧ず閲嶆柊鐧诲綍 @@ -29,6 +31,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 +67,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