Эх сурвалжийг харах

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

奔跑的面条 2 жил өмнө
parent
commit
327d23ebac

+ 3 - 3
src/views/chart/hooks/useSync.hook.ts

@@ -1,6 +1,6 @@
 import { onUnmounted } from 'vue';
 import html2canvas from 'html2canvas'
-import { getUUID, httpErrorHandle, fetchRouteParamsLocation, base64toFile } from '@/utils'
+import { getUUID, httpErrorHandle, fetchRouteParamsLocation, base64toFile, JSONStringify, JSONParse } from '@/utils'
 import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
 import { EditCanvasTypeEnum, ChartEditStoreEnum, ProjectInfoEnum, ChartEditStorage } from '@/store/modules/chartEditStore/chartEditStore.d'
 import { useChartHistoryStore } from '@/store/modules/chartHistoryStore/chartHistoryStore'
@@ -245,7 +245,7 @@ export const useSync = () => {
         if (res.data) {
           updateStoreInfo(res.data)
           // 更新全局数据
-          await updateComponent(JSON.parse(res.data.content))
+          await updateComponent(JSONParse(res.data.content))
           return
         }else {
           chartEditStore.setProjectInfo(ProjectInfoEnum.PROJECT_ID, fetchRouteParamsLocation())
@@ -305,7 +305,7 @@ export const useSync = () => {
     // 保存数据
     let params = new FormData()
     params.append('projectId', projectId)
-    params.append('content', JSON.stringify(chartEditStore.getStorageInfo || {}))
+    params.append('content', JSONStringify(chartEditStore.getStorageInfo || {}))
     const res= await saveProjectApi(params)
 
     if (res && res.code === ResultEnum.SUCCESS) {

+ 2 - 2
src/views/preview/utils/storage.ts

@@ -1,4 +1,4 @@
-import { getSessionStorage, fetchRouteParamsLocation, httpErrorHandle } from '@/utils'
+import { getSessionStorage, fetchRouteParamsLocation, httpErrorHandle, JSONParse } from '@/utils'
 import { ResultEnum } from '@/enums/httpEnum'
 import { StorageEnum } from '@/enums/storageEnum'
 import { ChartEditStorage } from '@/store/modules/chartEditStore/chartEditStore.d'
@@ -23,7 +23,7 @@ export const getSessionStorageInfo = async () => {
         // 跳转未发布页
         return { isRelease: false }
       }
-      return { ...JSON.parse(content), id }
+      return { ...JSONParse(content), id }
     } else {
       httpErrorHandle()
     }