From 4c2b3abbacec8303d0f0e2ce3f35d8f5b2ee4038 Mon Sep 17 00:00:00 2001 From: xingyuv Date: Wed, 29 Mar 2023 17:15:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(hooks):=20=E4=BF=AE=E6=94=B9useEcharts=20ge?= =?UTF-8?q?tInstance=E6=97=A0=E6=B3=95=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/web/useECharts.ts | 38 +++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/hooks/web/useECharts.ts b/src/hooks/web/useECharts.ts index 21c331a..ce2886f 100644 --- a/src/hooks/web/useECharts.ts +++ b/src/hooks/web/useECharts.ts @@ -12,7 +12,6 @@ import { useMenuSetting } from '@/hooks/setting/useMenuSetting' export function useECharts(elRef: Ref, theme: 'light' | 'dark' | 'default' = 'default') { const { getDarkMode: getSysDarkMode } = useRootSetting() - const { getCollapsed } = useMenuSetting() const getDarkMode = computed(() => { @@ -58,23 +57,26 @@ export function useECharts(elRef: Ref, theme: 'light' | 'dark' | function setOptions(options: EChartsOption, clear = true) { cacheOptions.value = options - if (unref(elRef)?.offsetHeight === 0) { - useTimeoutFn(() => { - setOptions(unref(getOptions)) - }, 30) - return - } - nextTick(() => { - useTimeoutFn(() => { - if (!chartInstance) { - initCharts(getDarkMode.value as 'default') - - if (!chartInstance) return - } - clear && chartInstance?.clear() - - chartInstance?.setOption(unref(getOptions)) - }, 30) + return new Promise((resolve) => { + if (unref(elRef)?.offsetHeight === 0) { + useTimeoutFn(() => { + setOptions(unref(getOptions)) + resolve(null) + }, 30) + } + nextTick(() => { + useTimeoutFn(() => { + if (!chartInstance) { + initCharts(getDarkMode.value as 'default') + + if (!chartInstance) return + } + clear && chartInstance?.clear() + + chartInstance?.setOption(unref(getOptions)) + resolve(null) + }, 30) + }) }) }