|
|
|
@ -13,13 +13,16 @@ import { AxiosRetry } from './axiosRetry'
|
|
|
|
|
import { useMessage } from '@/hooks/useMessage' |
|
|
|
|
import { ContentTypeEnum, HttpErrorMsgEnum, HttpSuccessEnum, RequestEnum, ResultEnum } from '@/enums/httpEnum' |
|
|
|
|
import { isEmpty, isNull, isString, isUndefined } from '@/utils/is' |
|
|
|
|
import { deepMerge, setObjToUrlParams } from '@/utils' |
|
|
|
|
import { deepMerge, setObjToUrlParams, strHasArr } from '@/utils' |
|
|
|
|
import crypto from '@/utils/crypto' |
|
|
|
|
import { useUserStore } from '@/store/moules/userStore/index' |
|
|
|
|
|
|
|
|
|
const { createMessage, createErrorModal, createSuccessModal } = useMessage() |
|
|
|
|
|
|
|
|
|
// 请求白名单,无须token的接口
|
|
|
|
|
const whiteList: string[] = ['/login', '/refresh-token'] |
|
|
|
|
// 不需要解密接口白名单
|
|
|
|
|
const notDecryptWhiteList = ['/hulk-auth/oauth/token'] |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @description: 数据处理,方便区分多种处理方式 |
|
|
|
@ -40,12 +43,17 @@ const transform: AxiosTransform = {
|
|
|
|
|
|
|
|
|
|
// 不进行任何处理,直接返回
|
|
|
|
|
// 用于页面代码可能需要直接获取code,data,message这些信息时开启
|
|
|
|
|
if (!isTransformResponse) |
|
|
|
|
return res.data |
|
|
|
|
if (!isTransformResponse) { |
|
|
|
|
if (strHasArr(res.config.url!, notDecryptWhiteList)) { |
|
|
|
|
return res.data |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
return JSON.parse(crypto.decryptAES(res.data as unknown as string, crypto.aesKey)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 错误的时候返回
|
|
|
|
|
|
|
|
|
|
const { data } = res |
|
|
|
|
const data = JSON.parse(crypto.decryptAES(res.data as unknown as string, crypto.aesKey)) |
|
|
|
|
|
|
|
|
|
if (!data) { |
|
|
|
|
// return '[HTTP] Request has no return value';
|
|
|
|
@ -189,7 +197,7 @@ const transform: AxiosTransform = {
|
|
|
|
|
if (token && !isToken) { |
|
|
|
|
// jwt token
|
|
|
|
|
(config as Recordable).headers[import.meta.env.VITE_GLOB_APP_TOKEN_KEY] = options.tokenScheme |
|
|
|
|
? `${options.tokenScheme} ${token}` |
|
|
|
|
? `${options.tokenScheme} ${crypto.encryptAES(token, crypto.cryptoKey)}` |
|
|
|
|
: token |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|