From 13ce24557b09446b8f29cd8511548cb182dd8692 Mon Sep 17 00:00:00 2001 From: wisonic-s Date: Wed, 3 Apr 2024 22:39:45 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9B=BE=E8=A1=A8):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=9C=B0=E5=9B=BE=E6=B8=B2=E6=9F=93=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/components/ChartComponentG2Plot.vue | 50 +++++++++++-------- .../views/chart/components/views/index.vue | 1 + 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/core/core-frontend/src/views/chart/components/views/components/ChartComponentG2Plot.vue b/core/core-frontend/src/views/chart/components/views/components/ChartComponentG2Plot.vue index 2c407e8100..39b125fb80 100644 --- a/core/core-frontend/src/views/chart/components/views/components/ChartComponentG2Plot.vue +++ b/core/core-frontend/src/views/chart/components/views/components/ChartComponentG2Plot.vue @@ -44,7 +44,7 @@ const props = defineProps({ } }) -const emit = defineEmits(['onChartClick', 'onDrillFilters', 'onJumpClick']) +const emit = defineEmits(['onChartClick', 'onDrillFilters', 'onJumpClick', 'resetLoading']) const { view, showPosition, scale, terminal } = toRefs(props) @@ -92,22 +92,21 @@ const calcData = async (view, callback) => { } } dvMainStore.setViewDataDetails(view.id, chartData.value) - await renderChart(res) - callback?.() + await renderChart(res, callback) } }) .catch(() => { callback?.() }) } else { - if (view.type === 'map') { - await renderChart(view) + if (['bubble-map', 'map'].includes(view.type)) { + await renderChart(view, callback) } callback?.() } } let curView -const renderChart = async view => { +const renderChart = async (view, callback?) => { if (!view) { return } @@ -123,10 +122,11 @@ const renderChart = async view => { recursionTransObj(customStyleTrans, chart.customStyle, scale.value, terminal.value) switch (chartView.library) { case ChartLibraryType.L7_PLOT: - await renderL7Plot(chart, chartView as L7PlotChartView) + await renderL7Plot(chart, chartView as L7PlotChartView, callback) break case ChartLibraryType.G2_PLOT: renderG2Plot(chart, chartView as G2PlotChartView) + callback?.() break default: break @@ -150,24 +150,30 @@ const country = ref('') const appStore = useAppStoreWithOut() const isDataEaseBi = computed(() => appStore.getIsDataEaseBi) const chartContainer = ref(null) -const renderL7Plot = async (chart, chartView: L7PlotChartView) => { +let mapTimer: number +const renderL7Plot = async (chart, chartView: L7PlotChartView, callback) => { const map = parseJson(chart.customAttr).map let areaId = map.id country.value = areaId.slice(0, 3) if (dynamicAreaId.value) { areaId = dynamicAreaId.value } - myChart?.destroy() - if (chartContainer.value) { - chartContainer.value.textContent = '' - } - myChart = await chartView.drawChart({ - chartObj: myChart, - container: containerId, - chart, - areaId, - action - }) + mapTimer && clearTimeout(mapTimer) + mapTimer = setTimeout(async () => { + myChart?.destroy() + if (chartContainer.value) { + chartContainer.value.textContent = '' + } + myChart = await chartView.drawChart({ + chartObj: myChart, + container: containerId, + chart, + areaId, + action + }) + callback?.() + emit('resetLoading') + }, 500) } const action = param => { @@ -265,7 +271,6 @@ defineExpose({ let resizeObserver const TOLERANCE = 0.01 const RESIZE_MONITOR_CHARTS = ['map', 'bubble-map'] -let mapTimer: number onMounted(() => { const containerDom = document.getElementById(containerId) const { offsetWidth, offsetHeight } = containerDom @@ -280,10 +285,11 @@ onMounted(() => { if (Math.abs(widthOffsetPercent) < TOLERANCE && Math.abs(heightOffsetPercent) < TOLERANCE) { return } + if (myChart && preSize[1] > 1) { + renderChart(curView) + } preSize[0] = size.inlineSize preSize[1] = size.blockSize - mapTimer && clearTimeout(mapTimer) - mapTimer = setTimeout(() => renderChart(curView), 500) }) resizeObserver.observe(containerDom) }) diff --git a/core/core-frontend/src/views/chart/components/views/index.vue b/core/core-frontend/src/views/chart/components/views/index.vue index 25eeae0e30..f6cc98ba9d 100644 --- a/core/core-frontend/src/views/chart/components/views/index.vue +++ b/core/core-frontend/src/views/chart/components/views/index.vue @@ -679,6 +679,7 @@ const iconSize = computed(() => { @onChartClick="chartClick" @onDrillFilters="onDrillFilters" @onJumpClick="jumpClick" + @resetLoading="() => (loading = false)" />