forked from github/dataease
Merge pull request #9606 from dataease/pr@dev-v2@feat_datav-cache
fix(数据大屏): 数据大屏支持前端缓存,异常退出可恢复
This commit is contained in:
commit
adbe6fc0bf
@ -17,6 +17,7 @@ import { canvasSave } from '@/utils/canvasUtils'
|
|||||||
import { changeSizeWithScale } from '@/utils/changeComponentsSizeWithScale'
|
import { changeSizeWithScale } from '@/utils/changeComponentsSizeWithScale'
|
||||||
import MoreComGroup from '@/custom-component/component-group/MoreComGroup.vue'
|
import MoreComGroup from '@/custom-component/component-group/MoreComGroup.vue'
|
||||||
import { XpackComponent } from '@/components/plugin'
|
import { XpackComponent } from '@/components/plugin'
|
||||||
|
import { useCache } from '@/hooks/web/useCache'
|
||||||
let nameEdit = ref(false)
|
let nameEdit = ref(false)
|
||||||
let inputName = ref('')
|
let inputName = ref('')
|
||||||
let nameInput = ref(null)
|
let nameInput = ref(null)
|
||||||
@ -27,6 +28,7 @@ const resourceGroupOpt = ref(null)
|
|||||||
const dvToolbarMain = ref(null)
|
const dvToolbarMain = ref(null)
|
||||||
const { canvasStyleData, dvInfo, editMode } = storeToRefs(dvMainStore)
|
const { canvasStyleData, dvInfo, editMode } = storeToRefs(dvMainStore)
|
||||||
let scaleEdit = 100
|
let scaleEdit = 100
|
||||||
|
const { wsCache } = useCache('localStorage')
|
||||||
|
|
||||||
const closeEditCanvasName = () => {
|
const closeEditCanvasName = () => {
|
||||||
nameEdit.value = false
|
nameEdit.value = false
|
||||||
@ -87,6 +89,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()
|
||||||
canvasSave(() => {
|
canvasSave(() => {
|
||||||
@ -140,6 +143,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')
|
||||||
}
|
}
|
||||||
const openHandler = ref(null)
|
const openHandler = ref(null)
|
||||||
|
@ -86,8 +86,8 @@ export const snapshotStore = defineStore('snapshot', {
|
|||||||
dvMainStore.setComponentData(snapshotInfo.componentData)
|
dvMainStore.setComponentData(snapshotInfo.componentData)
|
||||||
dvMainStore.setCanvasStyle(snapshotInfo.canvasStyleData)
|
dvMainStore.setCanvasStyle(snapshotInfo.canvasStyleData)
|
||||||
dvMainStore.setCanvasViewInfo(snapshotInfo.canvasViewInfo)
|
dvMainStore.setCanvasViewInfo(snapshotInfo.canvasViewInfo)
|
||||||
dvMainStore.setNowPanelJumpInfoInner(snapshotInfo.nowPanelTrackInfo)
|
dvMainStore.setNowPanelJumpInfoInner(snapshotInfo.nowPanelJumpInfo)
|
||||||
dvMainStore.setNowPanelJumpInfo(snapshotInfo.nowPanelJumpInfo)
|
dvMainStore.setNowPanelTrackInfo(snapshotInfo.nowPanelTrackInfo)
|
||||||
dvMainStore.updateCurDvInfo(snapshotInfo.dvInfo)
|
dvMainStore.updateCurDvInfo(snapshotInfo.dvInfo)
|
||||||
const curCacheViewIdInfo = deepCopy(this.cacheViewIdInfo)
|
const curCacheViewIdInfo = deepCopy(this.cacheViewIdInfo)
|
||||||
this.cacheViewIdInfo = snapshotInfo.cacheViewIdInfo
|
this.cacheViewIdInfo = snapshotInfo.cacheViewIdInfo
|
||||||
|
@ -120,8 +120,8 @@ const doUseCache = flag => {
|
|||||||
}, 1500)
|
}, 1500)
|
||||||
} else {
|
} else {
|
||||||
initLocalCanvasData()
|
initLocalCanvasData()
|
||||||
|
wsCache.delete('DE-DV-CATCH-' + state.resourceId)
|
||||||
}
|
}
|
||||||
wsCache.delete('DE-DV-CATCH-' + state.resourceId)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const initLocalCanvasData = () => {
|
const initLocalCanvasData = () => {
|
||||||
|
@ -36,6 +36,8 @@ 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()
|
||||||
@ -58,6 +60,8 @@ const dvMainStore = dvMainStoreWithOut()
|
|||||||
const snapshotStore = snapshotStoreWithOut()
|
const snapshotStore = snapshotStoreWithOut()
|
||||||
const contextmenuStore = contextmenuStoreWithOut()
|
const contextmenuStore = contextmenuStoreWithOut()
|
||||||
const composeStore = composeStoreWithOut()
|
const composeStore = composeStoreWithOut()
|
||||||
|
const canvasCacheOutRef = ref(null)
|
||||||
|
|
||||||
const {
|
const {
|
||||||
componentData,
|
componentData,
|
||||||
curComponent,
|
curComponent,
|
||||||
@ -77,7 +81,10 @@ const state = reactive({
|
|||||||
datasetTree: [],
|
datasetTree: [],
|
||||||
scaleHistory: 100,
|
scaleHistory: 100,
|
||||||
canvasId: 'canvas-main',
|
canvasId: 'canvas-main',
|
||||||
canvasInitStatus: false
|
canvasInitStatus: false,
|
||||||
|
sourcePid: null,
|
||||||
|
resourceId: null,
|
||||||
|
opt: null
|
||||||
})
|
})
|
||||||
|
|
||||||
const contentStyle = computed(() => {
|
const contentStyle = computed(() => {
|
||||||
@ -177,6 +184,42 @@ const initScroll = () => {
|
|||||||
canvasOut.value.scrollTo(scrollX, scrollY)
|
canvasOut.value.scrollTo(scrollX, scrollY)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
const doUseCache = flag => {
|
||||||
|
const canvasCache = wsCache.get('DE-DV-CATCH-' + state.resourceId)
|
||||||
|
if (flag && canvasCache) {
|
||||||
|
const canvasCacheSeries = deepCopy(canvasCache)
|
||||||
|
snapshotStore.snapshotPublish(canvasCacheSeries)
|
||||||
|
state.canvasInitStatus = true
|
||||||
|
nextTick(() => {
|
||||||
|
dvMainStore.setDataPrepareState(true)
|
||||||
|
snapshotStore.recordSnapshotCache('renderChart')
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
initLocalCanvasData()
|
||||||
|
wsCache.delete('DE-DV-CATCH-' + state.resourceId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const initLocalCanvasData = () => {
|
||||||
|
const { opt, sourcePid, resourceId } = state
|
||||||
|
const busiFlg = opt === 'copy' ? 'dataV-copy' : 'dataV'
|
||||||
|
initCanvasData(resourceId, busiFlg, function () {
|
||||||
|
state.canvasInitStatus = true
|
||||||
|
// afterInit
|
||||||
|
nextTick(() => {
|
||||||
|
dvMainStore.setDataPrepareState(true)
|
||||||
|
snapshotStore.recordSnapshotCache('renderChart')
|
||||||
|
if (dvInfo.value && opt === 'copy') {
|
||||||
|
dvInfo.value.dataState = 'prepare'
|
||||||
|
dvInfo.value.optType = 'copy'
|
||||||
|
dvInfo.value.pid = sourcePid
|
||||||
|
setTimeout(() => {
|
||||||
|
snapshotStore.recordSnapshotCache('renderChart')
|
||||||
|
}, 1500)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const previewScaleChange = () => {
|
const previewScaleChange = () => {
|
||||||
state.scaleHistory = canvasStyleData.value.scale
|
state.scaleHistory = canvasStyleData.value.scale
|
||||||
@ -229,25 +272,17 @@ onMounted(async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
initDataset()
|
initDataset()
|
||||||
|
state.resourceId = dvId
|
||||||
|
state.sourcePid = pid
|
||||||
|
state.opt = opt
|
||||||
if (dvId) {
|
if (dvId) {
|
||||||
state.canvasInitStatus = false
|
state.canvasInitStatus = false
|
||||||
const busiFlg = opt === 'copy' ? 'dataV-copy' : 'dataV'
|
const canvasCache = wsCache.get('DE-DV-CATCH-' + dvId)
|
||||||
initCanvasData(dvId, busiFlg, function () {
|
if (canvasCache) {
|
||||||
state.canvasInitStatus = true
|
canvasCacheOutRef.value?.dialogInit({ canvasType: 'dataV', resourceId: dvId })
|
||||||
// afterInit
|
} else {
|
||||||
nextTick(() => {
|
initLocalCanvasData()
|
||||||
dvMainStore.setDataPrepareState(true)
|
}
|
||||||
snapshotStore.recordSnapshotCache('renderChart')
|
|
||||||
if (dvInfo.value && opt === 'copy') {
|
|
||||||
dvInfo.value.dataState = 'prepare'
|
|
||||||
dvInfo.value.optType = 'copy'
|
|
||||||
dvInfo.value.pid = pid
|
|
||||||
setTimeout(() => {
|
|
||||||
snapshotStore.recordSnapshotCache('renderChart')
|
|
||||||
}, 1500)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
} else if (opt && opt === 'create') {
|
} else if (opt && opt === 'create') {
|
||||||
state.canvasInitStatus = false
|
state.canvasInitStatus = false
|
||||||
let watermarkBaseInfo
|
let watermarkBaseInfo
|
||||||
@ -404,6 +439,7 @@ eventBus.on('handleNew', handleNew)
|
|||||||
@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