diff --git a/core/core-frontend/src/components/dashboard/DbToolbar.vue b/core/core-frontend/src/components/dashboard/DbToolbar.vue index 36a4f0ca48..f6514f0df0 100644 --- a/core/core-frontend/src/components/dashboard/DbToolbar.vue +++ b/core/core-frontend/src/components/dashboard/DbToolbar.vue @@ -27,6 +27,7 @@ import DeResourceGroupOpt from '@/views/common/DeResourceGroupOpt.vue' import OuterParamsSet from '@/components/visualization/OuterParamsSet.vue' import { XpackComponent } from '@/components/plugin' import DbMoreComGroup from '@/custom-component/component-group/DbMoreComGroup.vue' +import { useCache } from '@/hooks/web/useCache' const { t } = useI18n() const dvMainStore = dvMainStoreWithOut() const snapshotStore = snapshotStoreWithOut() @@ -54,6 +55,7 @@ const state = reactive({ }) const resourceGroupOpt = ref(null) const outerParamsSetRef = ref(null) +const { wsCache } = useCache('localStorage') const editCanvasName = () => { nameEdit.value = true @@ -147,6 +149,7 @@ const saveCanvasWithCheck = () => { } const saveResource = () => { + wsCache.delete('DE-DV-CATCH-' + dvInfo.value.id) if (styleChangeTimes.value > 0) { snapshotStore.resetStyleChangeTimes() dvMainStore.matrixSizeAdaptor() @@ -199,6 +202,7 @@ const backHandler = (url: string) => { openHandler.value.invokeMethod(pm) return } + wsCache.delete('DE-DV-CATCH-' + dvInfo.value.id) window.open(url, '_self') } diff --git a/core/core-frontend/src/components/visualization/CanvasCacheDialog.vue b/core/core-frontend/src/components/visualization/CanvasCacheDialog.vue new file mode 100644 index 0000000000..9f13d7b8e7 --- /dev/null +++ b/core/core-frontend/src/components/visualization/CanvasCacheDialog.vue @@ -0,0 +1,65 @@ + + + + + diff --git a/core/core-frontend/src/store/modules/data-visualization/snapshot.ts b/core/core-frontend/src/store/modules/data-visualization/snapshot.ts index 1e1ce22eee..cbfec71bff 100644 --- a/core/core-frontend/src/store/modules/data-visualization/snapshot.ts +++ b/core/core-frontend/src/store/modules/data-visualization/snapshot.ts @@ -5,16 +5,20 @@ import { deepCopy } from '@/utils/utils' import { BASE_THEMES } from '@/views/chart/components/editor/util/dataVisualiztion' import eventBus from '@/utils/eventBus' import { useEmitt } from '@/hooks/web/useEmitt' +import { useCache } from '@/hooks/web/useCache' +const { wsCache } = useCache('localStorage') const dvMainStore = dvMainStoreWithOut() const { + dvInfo, curComponent, componentData, canvasStyleData, canvasViewInfo, curOriginThemes, dataPrepareState, - nowPanelTrackInfo + nowPanelTrackInfo, + nowPanelJumpInfo } = storeToRefs(dvMainStore) let defaultCanvasInfo = { @@ -83,6 +87,8 @@ export const snapshotStore = defineStore('snapshot', { dvMainStore.setCanvasStyle(snapshotInfo.canvasStyleData) dvMainStore.setCanvasViewInfo(snapshotInfo.canvasViewInfo) dvMainStore.setNowPanelJumpInfoInner(snapshotInfo.nowPanelTrackInfo) + dvMainStore.setNowPanelJumpInfo(snapshotInfo.nowPanelJumpInfo) + dvMainStore.updateCurDvInfo(snapshotInfo.dvInfo) const curCacheViewIdInfo = deepCopy(this.cacheViewIdInfo) this.cacheViewIdInfo = snapshotInfo.cacheViewIdInfo @@ -142,7 +148,9 @@ export const snapshotStore = defineStore('snapshot', { canvasStyleData: deepCopy(canvasStyleData.value), canvasViewInfo: deepCopy(canvasViewInfo.value), cacheViewIdInfo: deepCopy(this.cacheViewIdInfo), - nowPanelTrackInfo: deepCopy(nowPanelTrackInfo.value) + nowPanelTrackInfo: deepCopy(nowPanelTrackInfo.value), + nowPanelJumpInfo: deepCopy(nowPanelJumpInfo.value), + dvInfo: deepCopy(dvInfo.value) } this.snapshotData[++this.snapshotIndex] = newSnapshot // 在 undo 过程中,添加新的快照时,要将它后面的快照清理掉 @@ -151,6 +159,9 @@ export const snapshotStore = defineStore('snapshot', { } // 清理缓存计数器 this.snapshotCacheTimes = 0 + if (this.snapshotData.length > 1) { + wsCache.set('DE-DV-CATCH-' + dvInfo.value.id, newSnapshot) + } } } } diff --git a/core/core-frontend/src/views/dashboard/index.vue b/core/core-frontend/src/views/dashboard/index.vue index 5b79fcb3ff..75b02f10d4 100644 --- a/core/core-frontend/src/views/dashboard/index.vue +++ b/core/core-frontend/src/views/dashboard/index.vue @@ -25,9 +25,12 @@ import { interactiveStoreWithOut } from '@/store/modules/interactive' import { watermarkFind } from '@/api/watermark' import { XpackComponent } from '@/components/plugin' import { Base64 } from 'js-base64' +import CanvasCacheDialog from '@/components/visualization/CanvasCacheDialog.vue' +import { deepCopy } from '@/utils/utils' const interactiveStore = interactiveStoreWithOut() const embeddedStore = useEmbedded() const { wsCache } = useCache() +const canvasCacheOutRef = ref(null) const eventCheck = e => { if (e.key === 'panel-weight' && !compareStorage(e.oldValue, e.newValue)) { const resourceId = embeddedStore.resourceId || router.currentRoute.value.query.resourceId @@ -55,7 +58,9 @@ const isDataEaseBi = computed(() => appStore.getIsDataEaseBi) const state = reactive({ datasetTree: [], sourcePid: null, - canvasId: 'canvas-main' + canvasId: 'canvas-main', + opt: null, + resourceId: null }) const initDataset = () => { @@ -103,7 +108,37 @@ const loadFinish = ref(false) const newWindowFromDiv = ref(false) let p = null const XpackLoaded = () => p(true) -// 全局监听按键事件 + +const doUseCache = flag => { + const canvasCache = wsCache.get('DE-DV-CATCH-' + state.resourceId) + if (flag && canvasCache) { + const canvasCacheSeries = deepCopy(canvasCache) + snapshotStore.snapshotPublish(canvasCacheSeries) + dataInitState.value = true + setTimeout(() => { + snapshotStore.recordSnapshotCache() + }, 1500) + } else { + initLocalCanvasData() + } + wsCache.delete('DE-DV-CATCH-' + state.resourceId) +} + +const initLocalCanvasData = () => { + const { resourceId, opt, sourcePid } = state + const busiFlg = opt === 'copy' ? 'dashboard-copy' : 'dashboard' + initCanvasData(resourceId, busiFlg, function () { + dataInitState.value = true + if (dvInfo.value && opt === 'copy') { + dvInfo.value.dataState = 'prepare' + dvInfo.value.optType = 'copy' + dvInfo.value.pid = sourcePid + setTimeout(() => { + snapshotStore.recordSnapshotCache() + }, 1500) + } + }) +} onMounted(async () => { if (window.location.hash.includes('#/dashboard')) { newWindowFromDiv.value = true @@ -127,20 +162,16 @@ onMounted(async () => { initDataset() state.sourcePid = pid + state.opt = opt + state.resourceId = resourceId if (resourceId) { dataInitState.value = false - const busiFlg = opt === 'copy' ? 'dashboard-copy' : 'dashboard' - initCanvasData(resourceId, busiFlg, function () { - dataInitState.value = true - if (dvInfo.value && opt === 'copy') { - dvInfo.value.dataState = 'prepare' - dvInfo.value.optType = 'copy' - dvInfo.value.pid = pid - setTimeout(() => { - snapshotStore.recordSnapshotCache() - }, 1500) - } - }) + const canvasCache = wsCache.get('DE-DV-CATCH-' + resourceId) + if (canvasCache) { + canvasCacheOutRef.value?.dialogInit({ canvasType: 'dashboard', resourceId: resourceId }) + } else { + initLocalCanvasData() + } } else if (opt && opt === 'create') { dataInitState.value = false let watermarkBaseInfo @@ -267,6 +298,7 @@ onUnmounted(() => { @loaded="XpackLoaded" @load-fail="XpackLoaded" /> +