mirror of
https://gitee.com/dromara/Jpom.git
synced 2024-11-30 02:48:17 +08:00
commit
2248702cc2
@ -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",
|
||||
|
@ -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
|
||||
})
|
||||
|
||||
|
15
web-vue/src/utils/check-type.ts
Normal file
15
web-vue/src/utils/check-type.ts
Normal 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/')
|
||||
}
|
Loading…
Reference in New Issue
Block a user