diff --git a/web-vue/package.json b/web-vue/package.json index db7801d0b..776c741d4 100644 --- a/web-vue/package.json +++ b/web-vue/package.json @@ -18,6 +18,7 @@ "axios": "^1.6.5", "codemirror": "^5.65.16", "codemirror-editor-vue3": "^2.4.1", + "crypto-js": "^4.2.0", "dayjs": "^1.11.10", "echarts": "^5.4.3", "js-sha1": "^0.6.0", @@ -35,6 +36,7 @@ "xterm-addon-fit": "^0.8.0" }, "devDependencies": { + "@types/crypto-js": "^4.2.2", "@types/node": "^20.10.8", "@typescript-eslint/eslint-plugin": "^6.18.1", "@typescript-eslint/parser": "^6.18.1", diff --git a/web-vue/src/api/config.ts b/web-vue/src/api/config.ts index 3c8959071..d507bc980 100644 --- a/web-vue/src/api/config.ts +++ b/web-vue/src/api/config.ts @@ -5,6 +5,7 @@ import { refreshToken } from './user/user' import { useAppStore } from '@/stores/app' import { useUserStore } from '@/stores/user' import { GlobalWindow } from '@/interface/common' +import CryptoJS from 'crypto-js' import Qs from 'qs' import router from '../router' @@ -31,6 +32,14 @@ const instance: AxiosInstance = axios.create({ let refreshTokenIng = false +const obj2base64 = (obj: { [x: string]: any }) => { + const keys = Object.keys(obj) + for (const key of keys) { + obj[key] = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(obj[key])) + } + return obj +} + // 请求拦截 instance.interceptors.request.use((config: InternalAxiosRequestConfig) => { const appStore = useAppStore() @@ -44,6 +53,13 @@ instance.interceptors.request.use((config: InternalAxiosRequestConfig) => { // 防止 url 出现 // config.url = (routerBase + config.url).replace(new RegExp('//', 'gm'), '/') } + // TODO 根据后端返回值做调整 + if (config.data) { + config.data = obj2base64(config.data) + } + if (config.params) { + config.params = obj2base64(config.params) + } return config })