Forráskód Böngészése

fix: 修改预览的存储方式为 sessionStorage

MTrun 3 éve
szülő
commit
a96df3cc13

+ 9 - 9
src/views/chart/HeaderRightBtn/index.vue

@@ -11,7 +11,7 @@
 
 <script setup lang="ts">
 import { shallowReactive } from 'vue'
-import { renderIcon, fetchPathByName, routerTurnByPath, setLocalStorage, getLocalStorage } from '@/utils'
+import { renderIcon, fetchPathByName, routerTurnByPath,setSessionStorage, getLocalStorage } from '@/utils'
 import { PreviewEnum } from '@/enums/pageEnum'
 import { StorageEnum } from '@/enums/storageEnum'
 import { icon } from '@/plugins'
@@ -32,22 +32,22 @@ const previewHandle = () => {
   // id 标识
   const previewId = typeof id === 'string' ? id : id[0]
   const storageInfo = chartEditStore.getStorageInfo
-  const localStorageInfo = getLocalStorage(StorageEnum.GO_CHART_STORAGE_LIST) || []
+  const sessionStorageInfo = getLocalStorage(StorageEnum.GO_CHART_STORAGE_LIST) || []
 
-  if (localStorageInfo?.length) {
-    const repeateIndex = localStorageInfo.findIndex((e: { id: string }) => e.id === previewId)
+  if (sessionStorageInfo?.length) {
+    const repeateIndex = sessionStorageInfo.findIndex((e: { id: string }) => e.id === previewId)
     // 重复替换
     if (repeateIndex !== -1) {
-      localStorageInfo.splice(repeateIndex, 1, { id: previewId, ...storageInfo })
-      setLocalStorage(StorageEnum.GO_CHART_STORAGE_LIST, localStorageInfo)
+      sessionStorageInfo.splice(repeateIndex, 1, { id: previewId, ...storageInfo })
+      setSessionStorage(StorageEnum.GO_CHART_STORAGE_LIST, sessionStorageInfo)
     } else {
-      localStorageInfo.push({
+      sessionStorageInfo.push({
         id: previewId, ...storageInfo
       })
-      setLocalStorage(StorageEnum.GO_CHART_STORAGE_LIST, localStorageInfo)
+      setSessionStorage(StorageEnum.GO_CHART_STORAGE_LIST, sessionStorageInfo)
     }
   } else {
-    setLocalStorage(StorageEnum.GO_CHART_STORAGE_LIST, [{ id: previewId, ...storageInfo }])
+    setSessionStorage(StorageEnum.GO_CHART_STORAGE_LIST, [{ id: previewId, ...storageInfo }])
   }
   // 跳转
   routerTurnByPath(path, [previewId], undefined, true)

+ 2 - 3
src/views/preview/index.vue

@@ -16,14 +16,13 @@ import { onUnmounted, ref, nextTick, computed } from 'vue'
 import { usePreviewScale } from '@/hooks/index'
 import { RenderList } from './components/RenderList/index'
 import { ChartEditStorageType } from './index.d'
-import { getLocalStorageInfo } from './utils/index'
-import { useEditCanvasConfigStyle } from './utils'
+import { useEditCanvasConfigStyle, getSessionStorageInfo } from './utils'
 import { CreateComponentType } from '@/packages/index.d'
 import { fetchChartComponent } from '@/packages/index'
 
 const previewRef = ref()
 
-const localStorageInfo: ChartEditStorageType = getLocalStorageInfo() as ChartEditStorageType
+const localStorageInfo: ChartEditStorageType = getSessionStorageInfo() as ChartEditStorageType
 
 const width = ref(localStorageInfo?.editCanvasConfig.width)
 const height = ref(localStorageInfo?.editCanvasConfig.height)

+ 4 - 4
src/views/preview/utils/index.ts

@@ -1,5 +1,5 @@
 export * from './style'
-import { getLocalStorage } from '@/utils'
+import { getSessionStorage } from '@/utils'
 import { StorageEnum } from '@/enums/storageEnum'
 import { ChartEditStorage } from '@/store/modules/chartEditStore/chartEditStore.d'
 
@@ -8,12 +8,12 @@ export interface ChartEditStorageType extends ChartEditStorage {
 }
 
 // 根据路由 id 获取存储数据的信息
-export const getLocalStorageInfo = () => {
+export const getSessionStorageInfo = () => {
   const urlHash = document.location.hash
   const toPathArray = urlHash.split('/')
   const id = toPathArray && toPathArray[toPathArray.length - 1]
 
-  const storageList: ChartEditStorageType[] = getLocalStorage(
+  const storageList: ChartEditStorageType[] = getSessionStorage(
     StorageEnum.GO_CHART_STORAGE_LIST
   )
 
@@ -24,4 +24,4 @@ export const getLocalStorageInfo = () => {
       return storageList[i]
     }
   }
-}
+}