perf: 优化 JSON 序列化无法处理函数的问题

This commit is contained in:
奔跑的面条
2023-01-09 11:25:03 +08:00
parent 5e0baa4923
commit 462a613bd3
7 changed files with 51 additions and 18 deletions
@@ -1,7 +1,7 @@
import { ref, toRef, nextTick } from 'vue'
import { UploadCustomRequestOptions } from 'naive-ui'
import { FileTypeEnum } from '@/enums/fileTypeEnum'
import { readFile, downloadTextFile } from '@/utils'
import { readFile, downloadTextFile, JSONStringify, JSONParse } from '@/utils'
export const useFile = (targetData: any) => {
const uploadFileListRef = ref()
@@ -23,7 +23,7 @@ export const useFile = (targetData: any) => {
nextTick(() => {
if (file.file) {
readFile(file.file).then((fileData: any) => {
targetData.value.option.dataset = JSON.parse(fileData)
targetData.value.option.dataset = JSONParse(fileData)
})
} else {
window['$message'].error('导入数据失败,请稍后重试或联系管理员!')
@@ -35,7 +35,7 @@ export const useFile = (targetData: any) => {
const download = () => {
try {
window['$message'].success('下载中,请耐心等待...')
downloadTextFile(JSON.stringify(targetData.value.option.dataset), undefined, 'json')
downloadTextFile(JSONStringify(targetData.value.option.dataset), undefined, 'json')
} catch (error) {
window['$message'].error('下载失败,数据错误!')
}