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

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

View File

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

View File

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

View File

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