chore: crypto-js 切换为 js-base64

This commit is contained in:
a20070322 2024-02-23 14:27:23 +08:00
parent efab706588
commit 8036d0c4e0
3 changed files with 14 additions and 9 deletions

View File

@ -16,9 +16,9 @@
"@codemirror/lang-javascript": "^6.2.1", "@codemirror/lang-javascript": "^6.2.1",
"ant-design-vue": "^4.1.0", "ant-design-vue": "^4.1.0",
"axios": "^1.6.5", "axios": "^1.6.5",
"base64-js": "^1.5.1",
"codemirror": "^5.65.16", "codemirror": "^5.65.16",
"codemirror-editor-vue3": "^2.4.1", "codemirror-editor-vue3": "^2.4.1",
"crypto-js": "^4.2.0",
"dayjs": "^1.11.10", "dayjs": "^1.11.10",
"echarts": "^5.4.3", "echarts": "^5.4.3",
"js-sha1": "^0.6.0", "js-sha1": "^0.6.0",
@ -36,7 +36,6 @@
"xterm-addon-fit": "^0.8.0" "xterm-addon-fit": "^0.8.0"
}, },
"devDependencies": { "devDependencies": {
"@types/crypto-js": "^4.2.2",
"@types/node": "^20.10.8", "@types/node": "^20.10.8",
"@typescript-eslint/eslint-plugin": "^6.18.1", "@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1", "@typescript-eslint/parser": "^6.18.1",

View File

@ -5,10 +5,9 @@ import { refreshToken } from './user/user'
import { useAppStore } from '@/stores/app' import { useAppStore } from '@/stores/app'
import { useUserStore } from '@/stores/user' import { useUserStore } from '@/stores/user'
import { GlobalWindow } from '@/interface/common' import { GlobalWindow } from '@/interface/common'
import CryptoJS from 'crypto-js'
import Qs from 'qs' import Qs from 'qs'
import router from '../router' import router from '../router'
import { base64Encode } from '@/utils/check-type'
const delTimeout: number = 20 * 1000 const delTimeout: number = 20 * 1000
const jpomWindow_ = window as unknown as GlobalWindow const jpomWindow_ = window as unknown as GlobalWindow
@ -45,7 +44,7 @@ const obj2base64 = (obj: any) => {
if (Array.isArray(obj)) { if (Array.isArray(obj)) {
return obj.map((item: any) => { return obj.map((item: any) => {
if (typeof item === 'string' || typeof item === 'number' || typeof item === 'boolean') { if (typeof item === 'string' || typeof item === 'number' || typeof item === 'boolean') {
item = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(String(item))) item = base64Encode(String(item))
} }
}) })
} }
@ -55,9 +54,7 @@ const obj2base64 = (obj: any) => {
for (const key of keys) { for (const key of keys) {
const item = obj[key] const item = obj[key]
if (typeof item === 'string' || typeof item === 'number' || typeof item === 'boolean') { if (typeof item === 'string' || typeof item === 'number' || typeof item === 'boolean') {
newData[CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(String(key)))] = CryptoJS.enc.Base64.stringify( newData[base64Encode(String(key))] = base64Encode(String(item))
CryptoJS.enc.Utf8.parse(String(item))
)
} }
} }
return newData return newData

View File

@ -1,3 +1,4 @@
import { fromByteArray } from 'base64-js'
const isBlob = (data: any) => { const isBlob = (data: any) => {
return data instanceof Blob return data instanceof Blob
} }
@ -7,9 +8,17 @@ const isArrayBuffer = (data: any) => {
} }
const isFile = (mimeType: any) => { const isFile = (mimeType: any) => {
return data instanceof File return mimeType instanceof File
} }
const isImageType = (mimeType: any) => { const isImageType = (mimeType: any) => {
return mimeType.startsWith('image/') return mimeType.startsWith('image/')
} }
export const base64Encode = (data: string) => {
// 将字符串转换为 UTF-8 字节数组
const utf8Bytes = new TextEncoder().encode(data)
// 将字节数组转换为 Base64 字符串
const base64String = fromByteArray(utf8Bytes)
return base64String
}