forked from github/dataease
fix(仪表板): 仪表板支持前端缓存,异常退出可恢复
This commit is contained in:
parent
6e32b7cf80
commit
7137b19365
@ -27,6 +27,7 @@ import DeResourceGroupOpt from '@/views/common/DeResourceGroupOpt.vue'
|
|||||||
import OuterParamsSet from '@/components/visualization/OuterParamsSet.vue'
|
import OuterParamsSet from '@/components/visualization/OuterParamsSet.vue'
|
||||||
import { XpackComponent } from '@/components/plugin'
|
import { XpackComponent } from '@/components/plugin'
|
||||||
import DbMoreComGroup from '@/custom-component/component-group/DbMoreComGroup.vue'
|
import DbMoreComGroup from '@/custom-component/component-group/DbMoreComGroup.vue'
|
||||||
|
import { useCache } from '@/hooks/web/useCache'
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const dvMainStore = dvMainStoreWithOut()
|
const dvMainStore = dvMainStoreWithOut()
|
||||||
const snapshotStore = snapshotStoreWithOut()
|
const snapshotStore = snapshotStoreWithOut()
|
||||||
@ -54,6 +55,7 @@ const state = reactive({
|
|||||||
})
|
})
|
||||||
const resourceGroupOpt = ref(null)
|
const resourceGroupOpt = ref(null)
|
||||||
const outerParamsSetRef = ref(null)
|
const outerParamsSetRef = ref(null)
|
||||||
|
const { wsCache } = useCache('localStorage')
|
||||||
|
|
||||||
const editCanvasName = () => {
|
const editCanvasName = () => {
|
||||||
nameEdit.value = true
|
nameEdit.value = true
|
||||||
@ -147,6 +149,7 @@ const saveCanvasWithCheck = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const saveResource = () => {
|
const saveResource = () => {
|
||||||
|
wsCache.delete('DE-DV-CATCH-' + dvInfo.value.id)
|
||||||
if (styleChangeTimes.value > 0) {
|
if (styleChangeTimes.value > 0) {
|
||||||
snapshotStore.resetStyleChangeTimes()
|
snapshotStore.resetStyleChangeTimes()
|
||||||
dvMainStore.matrixSizeAdaptor()
|
dvMainStore.matrixSizeAdaptor()
|
||||||
@ -199,6 +202,7 @@ const backHandler = (url: string) => {
|
|||||||
openHandler.value.invokeMethod(pm)
|
openHandler.value.invokeMethod(pm)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
wsCache.delete('DE-DV-CATCH-' + dvInfo.value.id)
|
||||||
window.open(url, '_self')
|
window.open(url, '_self')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,65 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog
|
||||||
|
ref="canvasCacheDialogRef"
|
||||||
|
:title="dialogInfo.title"
|
||||||
|
:append-to-body="true"
|
||||||
|
v-model="dialogShow"
|
||||||
|
width="540px"
|
||||||
|
trigger="click"
|
||||||
|
>
|
||||||
|
<el-row style="height: 20px">
|
||||||
|
<el-col :span="3">
|
||||||
|
<Icon name="warn-tree" style="width: 20px; height: 20px; float: right" />
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="21">
|
||||||
|
<span style="font-size: 13px; margin-left: 10px; font-weight: bold; line-height: 20px">
|
||||||
|
{{ dialogInfo.tips }}
|
||||||
|
</span>
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
|
<template #footer>
|
||||||
|
<div class="dialog-footer">
|
||||||
|
<el-button size="mini" @click="doUseCache(false)">否 </el-button>
|
||||||
|
<el-button type="primary" size="mini" @click="doUseCache(true)">是 </el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref } from 'vue'
|
||||||
|
import { useI18n } from '@/hooks/web/useI18n'
|
||||||
|
import { dvMainStoreWithOut } from '@/store/modules/data-visualization/dvMain'
|
||||||
|
const dvMainStore = dvMainStoreWithOut()
|
||||||
|
const dialogShow = ref(false)
|
||||||
|
const { t } = useI18n()
|
||||||
|
import { useCache } from '@/hooks/web/useCache'
|
||||||
|
const { wsCache } = useCache()
|
||||||
|
const emits = defineEmits(['doUseCache'])
|
||||||
|
|
||||||
|
const dialogInfo = {
|
||||||
|
resourceId: null,
|
||||||
|
title: '',
|
||||||
|
tips: ''
|
||||||
|
}
|
||||||
|
|
||||||
|
const dialogInit = initInfo => {
|
||||||
|
const canvasTypeName = initInfo.canvasType === 'dataV' ? '数据大屏' : '仪表板'
|
||||||
|
dialogInfo.resourceId = initInfo.resourceId
|
||||||
|
dialogInfo.title = '存在未保存的' + canvasTypeName
|
||||||
|
dialogInfo.tips =
|
||||||
|
'检查到上次有' + canvasTypeName + '未能正常保存,是否使用上次未保存的' + canvasTypeName + '?'
|
||||||
|
dialogShow.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
const doUseCache = flag => {
|
||||||
|
emits('doUseCache', flag)
|
||||||
|
dialogShow.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
dialogInit
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="less" scoped></style>
|
@ -5,16 +5,20 @@ import { deepCopy } from '@/utils/utils'
|
|||||||
import { BASE_THEMES } from '@/views/chart/components/editor/util/dataVisualiztion'
|
import { BASE_THEMES } from '@/views/chart/components/editor/util/dataVisualiztion'
|
||||||
import eventBus from '@/utils/eventBus'
|
import eventBus from '@/utils/eventBus'
|
||||||
import { useEmitt } from '@/hooks/web/useEmitt'
|
import { useEmitt } from '@/hooks/web/useEmitt'
|
||||||
|
import { useCache } from '@/hooks/web/useCache'
|
||||||
|
const { wsCache } = useCache('localStorage')
|
||||||
|
|
||||||
const dvMainStore = dvMainStoreWithOut()
|
const dvMainStore = dvMainStoreWithOut()
|
||||||
const {
|
const {
|
||||||
|
dvInfo,
|
||||||
curComponent,
|
curComponent,
|
||||||
componentData,
|
componentData,
|
||||||
canvasStyleData,
|
canvasStyleData,
|
||||||
canvasViewInfo,
|
canvasViewInfo,
|
||||||
curOriginThemes,
|
curOriginThemes,
|
||||||
dataPrepareState,
|
dataPrepareState,
|
||||||
nowPanelTrackInfo
|
nowPanelTrackInfo,
|
||||||
|
nowPanelJumpInfo
|
||||||
} = storeToRefs(dvMainStore)
|
} = storeToRefs(dvMainStore)
|
||||||
|
|
||||||
let defaultCanvasInfo = {
|
let defaultCanvasInfo = {
|
||||||
@ -83,6 +87,8 @@ export const snapshotStore = defineStore('snapshot', {
|
|||||||
dvMainStore.setCanvasStyle(snapshotInfo.canvasStyleData)
|
dvMainStore.setCanvasStyle(snapshotInfo.canvasStyleData)
|
||||||
dvMainStore.setCanvasViewInfo(snapshotInfo.canvasViewInfo)
|
dvMainStore.setCanvasViewInfo(snapshotInfo.canvasViewInfo)
|
||||||
dvMainStore.setNowPanelJumpInfoInner(snapshotInfo.nowPanelTrackInfo)
|
dvMainStore.setNowPanelJumpInfoInner(snapshotInfo.nowPanelTrackInfo)
|
||||||
|
dvMainStore.setNowPanelJumpInfo(snapshotInfo.nowPanelJumpInfo)
|
||||||
|
dvMainStore.updateCurDvInfo(snapshotInfo.dvInfo)
|
||||||
const curCacheViewIdInfo = deepCopy(this.cacheViewIdInfo)
|
const curCacheViewIdInfo = deepCopy(this.cacheViewIdInfo)
|
||||||
this.cacheViewIdInfo = snapshotInfo.cacheViewIdInfo
|
this.cacheViewIdInfo = snapshotInfo.cacheViewIdInfo
|
||||||
|
|
||||||
@ -142,7 +148,9 @@ export const snapshotStore = defineStore('snapshot', {
|
|||||||
canvasStyleData: deepCopy(canvasStyleData.value),
|
canvasStyleData: deepCopy(canvasStyleData.value),
|
||||||
canvasViewInfo: deepCopy(canvasViewInfo.value),
|
canvasViewInfo: deepCopy(canvasViewInfo.value),
|
||||||
cacheViewIdInfo: deepCopy(this.cacheViewIdInfo),
|
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
|
this.snapshotData[++this.snapshotIndex] = newSnapshot
|
||||||
// 在 undo 过程中,添加新的快照时,要将它后面的快照清理掉
|
// 在 undo 过程中,添加新的快照时,要将它后面的快照清理掉
|
||||||
@ -151,6 +159,9 @@ export const snapshotStore = defineStore('snapshot', {
|
|||||||
}
|
}
|
||||||
// 清理缓存计数器
|
// 清理缓存计数器
|
||||||
this.snapshotCacheTimes = 0
|
this.snapshotCacheTimes = 0
|
||||||
|
if (this.snapshotData.length > 1) {
|
||||||
|
wsCache.set('DE-DV-CATCH-' + dvInfo.value.id, newSnapshot)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,12 @@ import { interactiveStoreWithOut } from '@/store/modules/interactive'
|
|||||||
import { watermarkFind } from '@/api/watermark'
|
import { watermarkFind } from '@/api/watermark'
|
||||||
import { XpackComponent } from '@/components/plugin'
|
import { XpackComponent } from '@/components/plugin'
|
||||||
import { Base64 } from 'js-base64'
|
import { Base64 } from 'js-base64'
|
||||||
|
import CanvasCacheDialog from '@/components/visualization/CanvasCacheDialog.vue'
|
||||||
|
import { deepCopy } from '@/utils/utils'
|
||||||
const interactiveStore = interactiveStoreWithOut()
|
const interactiveStore = interactiveStoreWithOut()
|
||||||
const embeddedStore = useEmbedded()
|
const embeddedStore = useEmbedded()
|
||||||
const { wsCache } = useCache()
|
const { wsCache } = useCache()
|
||||||
|
const canvasCacheOutRef = ref(null)
|
||||||
const eventCheck = e => {
|
const eventCheck = e => {
|
||||||
if (e.key === 'panel-weight' && !compareStorage(e.oldValue, e.newValue)) {
|
if (e.key === 'panel-weight' && !compareStorage(e.oldValue, e.newValue)) {
|
||||||
const resourceId = embeddedStore.resourceId || router.currentRoute.value.query.resourceId
|
const resourceId = embeddedStore.resourceId || router.currentRoute.value.query.resourceId
|
||||||
@ -55,7 +58,9 @@ const isDataEaseBi = computed(() => appStore.getIsDataEaseBi)
|
|||||||
const state = reactive({
|
const state = reactive({
|
||||||
datasetTree: [],
|
datasetTree: [],
|
||||||
sourcePid: null,
|
sourcePid: null,
|
||||||
canvasId: 'canvas-main'
|
canvasId: 'canvas-main',
|
||||||
|
opt: null,
|
||||||
|
resourceId: null
|
||||||
})
|
})
|
||||||
|
|
||||||
const initDataset = () => {
|
const initDataset = () => {
|
||||||
@ -103,7 +108,37 @@ const loadFinish = ref(false)
|
|||||||
const newWindowFromDiv = ref(false)
|
const newWindowFromDiv = ref(false)
|
||||||
let p = null
|
let p = null
|
||||||
const XpackLoaded = () => p(true)
|
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 () => {
|
onMounted(async () => {
|
||||||
if (window.location.hash.includes('#/dashboard')) {
|
if (window.location.hash.includes('#/dashboard')) {
|
||||||
newWindowFromDiv.value = true
|
newWindowFromDiv.value = true
|
||||||
@ -127,20 +162,16 @@ onMounted(async () => {
|
|||||||
initDataset()
|
initDataset()
|
||||||
|
|
||||||
state.sourcePid = pid
|
state.sourcePid = pid
|
||||||
|
state.opt = opt
|
||||||
|
state.resourceId = resourceId
|
||||||
if (resourceId) {
|
if (resourceId) {
|
||||||
dataInitState.value = false
|
dataInitState.value = false
|
||||||
const busiFlg = opt === 'copy' ? 'dashboard-copy' : 'dashboard'
|
const canvasCache = wsCache.get('DE-DV-CATCH-' + resourceId)
|
||||||
initCanvasData(resourceId, busiFlg, function () {
|
if (canvasCache) {
|
||||||
dataInitState.value = true
|
canvasCacheOutRef.value?.dialogInit({ canvasType: 'dashboard', resourceId: resourceId })
|
||||||
if (dvInfo.value && opt === 'copy') {
|
} else {
|
||||||
dvInfo.value.dataState = 'prepare'
|
initLocalCanvasData()
|
||||||
dvInfo.value.optType = 'copy'
|
}
|
||||||
dvInfo.value.pid = pid
|
|
||||||
setTimeout(() => {
|
|
||||||
snapshotStore.recordSnapshotCache()
|
|
||||||
}, 1500)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else if (opt && opt === 'create') {
|
} else if (opt && opt === 'create') {
|
||||||
dataInitState.value = false
|
dataInitState.value = false
|
||||||
let watermarkBaseInfo
|
let watermarkBaseInfo
|
||||||
@ -267,6 +298,7 @@ onUnmounted(() => {
|
|||||||
@loaded="XpackLoaded"
|
@loaded="XpackLoaded"
|
||||||
@load-fail="XpackLoaded"
|
@load-fail="XpackLoaded"
|
||||||
/>
|
/>
|
||||||
|
<canvas-cache-dialog ref="canvasCacheOutRef" @doUseCache="doUseCache"></canvas-cache-dialog>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="less">
|
<style lang="less">
|
||||||
|
Loading…
Reference in New Issue
Block a user