mirror of
https://gitee.com/dromara/go-view.git
synced 2024-12-02 03:38:27 +08:00
feat: 还原实时同步到预览页面的功能
This commit is contained in:
parent
3d56037b44
commit
70d080ff70
@ -12,6 +12,7 @@ export enum DragKeyEnum {
|
||||
// 不同页面保存操作
|
||||
export enum SavePageEnum {
|
||||
CHART = 'SaveChart',
|
||||
CHART_TO_PREVIEW = 'ChartToPreview',
|
||||
JSON = 'SaveJSON',
|
||||
CLOSE = 'close'
|
||||
}
|
||||
|
@ -24,6 +24,11 @@ export const syncData = () => {
|
||||
})
|
||||
}
|
||||
|
||||
// 同步数据到预览页
|
||||
export const syncDataToPreview = () => {
|
||||
dispatchEvent(new CustomEvent(SavePageEnum.CHART_TO_PREVIEW, { detail: chartEditStore.getStorageInfo }))
|
||||
}
|
||||
|
||||
// 侦听器更新
|
||||
const useSyncUpdateHandle = () => {
|
||||
// 定义侦听器变量
|
||||
@ -48,8 +53,8 @@ const useSyncUpdateHandle = () => {
|
||||
// document.hasFocus() && syncData()
|
||||
// }, editToJsonInterval)
|
||||
|
||||
// 失焦同步数据(暂不开启)
|
||||
// addEventListener('blur', syncData)
|
||||
// 失焦同步数据
|
||||
addEventListener('blur', syncDataToPreview)
|
||||
|
||||
// 监听编辑器保存事件 刷新工作台图表
|
||||
addEventListener(SavePageEnum.JSON, updateFn)
|
||||
@ -61,7 +66,7 @@ const useSyncUpdateHandle = () => {
|
||||
// 关闭侦听
|
||||
const unUse = () => {
|
||||
// clearInterval(timer)
|
||||
// removeEventListener('blur', syncData)
|
||||
removeEventListener('blur', syncDataToPreview)
|
||||
removeEventListener(SavePageEnum.JSON, updateFn)
|
||||
}
|
||||
|
||||
|
@ -1,25 +1,25 @@
|
||||
<template>
|
||||
<preview :key="key"></preview>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { getSessionStorageInfo } from './utils'
|
||||
import type { ChartEditStorageType } from './index.d'
|
||||
import { SavePageEnum } from '@/enums/editPageEnum'
|
||||
import { setSessionStorage } from '@/utils'
|
||||
import { StorageEnum } from '@/enums/storageEnum'
|
||||
import { ref } from 'vue'
|
||||
import Preview from './index.vue'
|
||||
|
||||
let key = ref(Date.now())
|
||||
|
||||
// 数据变更 -> 组件销毁重建
|
||||
;[SavePageEnum.JSON, SavePageEnum.CHART].forEach((saveEvent: string) => {
|
||||
if (!window.opener) return
|
||||
window.opener.addEventListener(saveEvent, async (e: any) => {
|
||||
const localStorageInfo: ChartEditStorageType = await getSessionStorageInfo() as unknown as ChartEditStorageType
|
||||
setSessionStorage(StorageEnum.GO_CHART_STORAGE_LIST, [{ ...e.detail, id: localStorageInfo.id }])
|
||||
key.value = Date.now()
|
||||
})
|
||||
})
|
||||
</script>
|
||||
<template>
|
||||
<preview :key="key"></preview>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { getSessionStorageInfo } from './utils'
|
||||
import type { ChartEditStorageType } from './index.d'
|
||||
import { SavePageEnum } from '@/enums/editPageEnum'
|
||||
import { setSessionStorage } from '@/utils'
|
||||
import { StorageEnum } from '@/enums/storageEnum'
|
||||
import { ref } from 'vue'
|
||||
import Preview from './index.vue'
|
||||
|
||||
let key = ref(Date.now())
|
||||
|
||||
// 数据变更 -> 组件销毁重建
|
||||
;[SavePageEnum.JSON, SavePageEnum.CHART_TO_PREVIEW].forEach((saveEvent: string) => {
|
||||
if (!window.opener) return
|
||||
window.opener.addEventListener(saveEvent, async (e: any) => {
|
||||
const localStorageInfo: ChartEditStorageType = await getSessionStorageInfo() as unknown as ChartEditStorageType
|
||||
setSessionStorage(StorageEnum.GO_CHART_STORAGE_LIST, [{ ...e.detail, id: localStorageInfo.id }])
|
||||
key.value = Date.now()
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user