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, nextTick } from 'vue'
import { UploadCustomRequestOptions } from 'naive-ui'
import { FileTypeEnum } from '@/enums/fileTypeEnum'
import { readFile, goDialog } from '@/utils'
import { readFile, goDialog, JSONParse } from '@/utils'
import { useSync } from '@/views/chart/hooks/useSync.hook'
export const useFile = () => {
@@ -34,7 +34,7 @@ export const useFile = () => {
// 新增
onPositiveCallback: async () => {
try {
fileData = JSON.parse(fileData)
fileData = JSONParse(fileData)
await updateComponent(fileData, false, true)
window['$message'].success('导入成功!')
} catch (error) {
@@ -45,7 +45,7 @@ export const useFile = () => {
// 覆盖
onNegativeCallback: async () => {
try {
fileData = JSON.parse(fileData)
fileData = JSONParse(fileData)
await updateComponent(fileData, true, true)
window['$message'].success('导入成功!')
} catch (error) {
@@ -1,5 +1,5 @@
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { canvasCut, downloadTextFile } from '@/utils'
import { canvasCut, downloadTextFile, JSONStringify } from '@/utils'
const chartEditStore = useChartEditStore()
// 导出
@@ -9,9 +9,7 @@ export const exportHandle = () => {
// 导出数据
downloadTextFile(
JSON.stringify(chartEditStore.getStorageInfo || [], (k, v) => {
return v === undefined ? null : v
}),
JSONStringify(chartEditStore.getStorageInfo || []),
undefined,
'json'
)
@@ -6,7 +6,7 @@ import { CreateComponentType, CreateComponentGroupType, PickCreateComponentType
import { useContextMenu } from '@/views/chart/hooks/useContextMenu.hook'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { EditCanvasTypeEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
import { loadingStart, loadingFinish, loadingError, setComponentPosition } from '@/utils'
import { loadingStart, loadingFinish, loadingError, setComponentPosition, JSONParse } from '@/utils'
import { throttle, cloneDeep } from 'lodash'
const chartEditStore = useChartEditStore()
@@ -28,7 +28,7 @@ export const dragHandle = async (e: DragEvent) => {
// 修改状态
chartEditStore.setEditCanvas(EditCanvasTypeEnum.IS_CREATE, false)
const dropData: Exclude<ConfigType, ['image']> = JSON.parse(drayDataString)
const dropData: Exclude<ConfigType, ['image']> = JSONParse(drayDataString)
// 创建新图表组件
let newComponent: CreateComponentType = await createComponent(dropData)