This commit is contained in:
刘玉霞 2024-06-17 18:03:10 +08:00
parent 67cf65dbb3
commit 6b22261fb0
2 changed files with 13 additions and 8 deletions

View File

@ -58,7 +58,7 @@ function createAxios<Data = any, T = ApiPromise<Data>>(axiosConfig: AxiosRequest
// if (adminBaseRoute.path != '/admin' && isAdminApp() && /^\/admin\//.test(axiosConfig.url!)) { // if (adminBaseRoute.path != '/admin' && isAdminApp() && /^\/admin\//.test(axiosConfig.url!)) {
// axiosConfig.url = axiosConfig.url!.replace(/^\/admin\//, adminBaseRoute.path + '.php/') // axiosConfig.url = axiosConfig.url!.replace(/^\/admin\//, adminBaseRoute.path + '.php/')
// } // }
alert(axiosConfig.data) // alert(axiosConfig.data)
// 合并默认请求选项 // 合并默认请求选项
options = Object.assign( options = Object.assign(
@ -77,6 +77,7 @@ function createAxios<Data = any, T = ApiPromise<Data>>(axiosConfig: AxiosRequest
// 请求拦截 // 请求拦截
Axios.interceptors.request.use( Axios.interceptors.request.use(
(config) => { (config) => {
const v = generateRandomNumber(16)
removePending(config) removePending(config)
options.CancelDuplicateRequest && addPending(config) options.CancelDuplicateRequest && addPending(config)
// 创建loading实例 // 创建loading实例
@ -87,15 +88,19 @@ function createAxios<Data = any, T = ApiPromise<Data>>(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 // 自动携带token
if (config.headers) { if (config.headers) {
const v = generateRandomNumber(16)
config.headers.v = v config.headers.v = v
const token = adminInfo.getToken() const token = adminInfo.getToken()
if (token) (config.headers as anyObj).token = encrypt_aes(token, v) 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 return config

View File

@ -11,11 +11,11 @@ export function encrypt_aes(plaintText: string, iv: string) {
padding: CryptoJS.pad.Pkcs7, 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) return encryptedData.toString(CryptoJS.format.Base64)
} }