!210 fix:支持接口参数编码

Merge pull request !210 from a20070322/issues/I8Z1VJ
This commit is contained in:
蒋小小 2024-02-23 05:46:34 +00:00 committed by Gitee
commit 2248702cc2
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 49 additions and 0 deletions

View File

@ -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",

View File

@ -5,9 +5,11 @@ 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'
import { type } from 'os'
const delTimeout: number = 20 * 1000
const jpomWindow_ = window as unknown as GlobalWindow
const apiTimeout: number = Number(jpomWindow_.apiTimeout === '<apiTimeout>' ? delTimeout : jpomWindow_.apiTimeout)
@ -39,6 +41,27 @@ const instance: AxiosInstance = axios.create({
let refreshTokenIng = false
const obj2base64 = (obj: any) => {
if (Array.isArray(obj)) {
return obj.map((item: any) => {
if (typeof item === 'string' || typeof item === 'number' || typeof item === 'boolean') {
item = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(String(item)))
}
})
}
if (obj instanceof Object && obj.constructor === Object) {
const keys = Object.keys(obj)
for (const key of keys) {
const item = obj[key]
if (typeof item === 'string' || typeof item === 'number' || typeof item === 'boolean') {
obj[key] = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(String(item)))
}
}
return obj
}
return obj
}
// 请求拦截
instance.interceptors.request.use((config: InternalAxiosRequestConfig) => {
const appStore = useAppStore()
@ -52,6 +75,15 @@ instance.interceptors.request.use((config: InternalAxiosRequestConfig) => {
// 防止 url 出现 //
config.url = (routerBase + config.url).replace(new RegExp('//', 'gm'), '/')
}
if (parseTransportEncryption() == 'BASE64') {
if (config.data) {
config.data = obj2base64(config.data)
}
if (config.params) {
config.params = obj2base64(config.params)
}
}
return config
})

View File

@ -0,0 +1,15 @@
const isBlob = (data: any) => {
return data instanceof Blob
}
const isArrayBuffer = (data: any) => {
return data instanceof ArrayBuffer
}
const isFile = (mimeType: any) => {
return data instanceof File
}
const isImageType = (mimeType: any) => {
return mimeType.startsWith('image/')
}