diff --git a/src/utils/request/core.ts b/src/utils/request/core.ts index bbefc67..345d353 100644 --- a/src/utils/request/core.ts +++ b/src/utils/request/core.ts @@ -153,27 +153,27 @@ export default class Request { ...config.extraConfig, } - // if (config.data && !(config.data instanceof FormData)) { - // const plainText = JSON.stringify(config.data) - // config.data = HiAesUtil.encryptData(plainText, encryptionKey) - // } - // - // if (config.method?.toLowerCase() === 'get' || config.params) { - // const paramsToEncrypt = config.params || {} - // const plainParamsText = JSON.stringify(paramsToEncrypt) - // const encryptedParams = HiAesUtil.encryptData(plainParamsText, encryptionKey) - // - // config.params = { - // data: encryptedParams.data, - // time: encryptedParams.time, - // } - // } + if (config.data && !(config.data instanceof FormData)) { + const plainText = JSON.stringify(config.data) + config.data = HiAesUtil.encryptData(plainText, encryptionKey) + } + + if (config.method?.toLowerCase() === 'get' || config.params) { + const paramsToEncrypt = config.params || {} + const plainParamsText = JSON.stringify(paramsToEncrypt) + const encryptedParams = HiAesUtil.encryptData(plainParamsText, encryptionKey) + + config.params = { + data: encryptedParams.data, + time: encryptedParams.time, + } + } config.headers = mergeExtraConfig.formatHeader({ ...this.config.headers, ...config.headers, lang: 'zh_CN', - // 'login-type': 'device', + 'login-type': 'device', ...(mergeExtraConfig.withToken && { [mergeExtraConfig.tokenKey]: mergeExtraConfig.getToken(), }), @@ -193,21 +193,22 @@ export default class Request { this.axiosInstance.interceptors.response.use( (response: ResponseType) => { const { data, config } = response - const responseData = response.data.data + let responseData = response.data.data - // if (responseData && responseData.data && responseData.time) { - // try { - // const decryptedStr = HiAesUtil.decryptData( - // responseData.data, - // responseData.time, - // encryptionKey, - // ) - // responseData = JSON.parse(decryptedStr) - // } catch (e) { - // console.error('解密失败:', e) - // return Promise.reject({ message: '数据解密异常' }) - // } - // } + if (responseData && responseData.data && responseData.time) { + try { + const decryptedStr = HiAesUtil.decryptData( + responseData.data, + responseData.time, + encryptionKey, + ) + console.log('decryptedStr', JSON.parse(decryptedStr)) + responseData = JSON.parse(decryptedStr) + } catch (e) { + console.error('解密失败:', e) + return Promise.reject({ message: '数据解密异常' }) + } + } axiosCanceler.removePending(config) if (data.code !== 200) {