From 6b22261fb089527d3c9fd3807647ce995d9f2ff0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=8E=89=E9=9C=9E?= Date: Mon, 17 Jun 2024 18:03:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/dasadmin/src/utils/axios.ts | 15 ++++++++++----- ui/dasadmin/src/utils/crypto.ts | 6 +++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/ui/dasadmin/src/utils/axios.ts b/ui/dasadmin/src/utils/axios.ts index fb3c4a6e..1f431a5c 100644 --- a/ui/dasadmin/src/utils/axios.ts +++ b/ui/dasadmin/src/utils/axios.ts @@ -58,7 +58,7 @@ function createAxios>(axiosConfig: AxiosRequest // if (adminBaseRoute.path != '/admin' && isAdminApp() && /^\/admin\//.test(axiosConfig.url!)) { // axiosConfig.url = axiosConfig.url!.replace(/^\/admin\//, adminBaseRoute.path + '.php/') // } - alert(axiosConfig.data) + // alert(axiosConfig.data) // 合并默认请求选项 options = Object.assign( @@ -77,6 +77,7 @@ function createAxios>(axiosConfig: AxiosRequest // 请求拦截 Axios.interceptors.request.use( (config) => { + const v = generateRandomNumber(16) removePending(config) options.CancelDuplicateRequest && addPending(config) // 创建loading实例 @@ -87,15 +88,19 @@ function createAxios>(axiosConfig: AxiosRequest } } + if (config.method === 'post' && config.data) { + // 对data进行加密 + config.data = encrypt_aes(config.data, v) + } else if (config.method === 'get' && config.params) { + // 对params进行加密 + config.params = encrypt_aes(config.params, v) + } + // 自动携带token if (config.headers) { - const v = generateRandomNumber(16) config.headers.v = v const token = adminInfo.getToken() if (token) (config.headers as anyObj).token = encrypt_aes(token, v) - - // const userToken = options.anotherToken || userInfo.getToken() - // if (userToken) (config.headers as anyObj)['token'] = userToken } return config diff --git a/ui/dasadmin/src/utils/crypto.ts b/ui/dasadmin/src/utils/crypto.ts index fe4c899a..58e1b180 100644 --- a/ui/dasadmin/src/utils/crypto.ts +++ b/ui/dasadmin/src/utils/crypto.ts @@ -11,11 +11,11 @@ export function encrypt_aes(plaintText: string, iv: string) { padding: CryptoJS.pad.Pkcs7, }) - const encryptedBase64Str = encryptedData.toString() + // const encryptedBase64Str = encryptedData.toString() - // 需要读取encryptedData上的ciphertext.toString()才能拿到跟Java一样的密文 + // // 需要读取encryptedData上的ciphertext.toString()才能拿到跟Java一样的密文 - const encryptedStr = encryptedData.ciphertext.toString() + // const encryptedStr = encryptedData.ciphertext.toString() return encryptedData.toString(CryptoJS.format.Base64) }