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

This commit is contained in:
MTrun 2022-03-10 18:57:18 +08:00
parent 4c6ed77806
commit a96df3cc13
3 changed files with 15 additions and 16 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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
)