From e521af0eaee067671aab2d2807ac9b5aa3d4cf30 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子Li <15040126243@163.com>
Date: 星期三, 25 十二月 2024 23:45:06 +0800
Subject: [PATCH] !169 fix 修复用户管理界面修改按钮权限字符串错误 Merge pull request !169 from QianRj/dev
---
src/utils/request.ts | 59 +++++++++++++++++++++++++++++++++++------------------------
1 files changed, 35 insertions(+), 24 deletions(-)
diff --git a/src/utils/request.ts b/src/utils/request.ts
index 6135d69..9682b81 100644
--- a/src/utils/request.ts
+++ b/src/utils/request.ts
@@ -10,6 +10,7 @@
import { getLanguage } from '@/lang';
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;
@@ -36,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 璇锋牴鎹疄闄呮儏鍐佃嚜琛屼慨鏀�
}
@@ -75,12 +77,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) {
@@ -96,19 +100,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;
@@ -129,8 +135,13 @@
}).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;
});
--
Gitblit v1.9.3