feat: 还原实时同步到预览页面的功能

This commit is contained in:
奔跑的面条 2023-04-01 22:00:26 +08:00
parent 3d56037b44
commit 70d080ff70
3 changed files with 34 additions and 28 deletions

View File

@ -12,6 +12,7 @@ export enum DragKeyEnum {
// 不同页面保存操作
export enum SavePageEnum {
CHART = 'SaveChart',
CHART_TO_PREVIEW = 'ChartToPreview',
JSON = 'SaveJSON',
CLOSE = 'close'
}

View File

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

View File

@ -14,7 +14,7 @@ import Preview from './index.vue'
let key = ref(Date.now())
// ->
;[SavePageEnum.JSON, SavePageEnum.CHART].forEach((saveEvent: string) => {
;[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