fix(hooks): 修改useEcharts getInstance无法获取

pull/4/MERGE
xingyuv 2023-03-29 17:15:23 +08:00
parent 286cd991d3
commit 4c2b3abbac
1 changed files with 18 additions and 16 deletions

View File

@ -12,7 +12,6 @@ import { useMenuSetting } from '@/hooks/setting/useMenuSetting'
export function useECharts(elRef: Ref<HTMLDivElement>, theme: 'light' | 'dark' | 'default' = 'default') { export function useECharts(elRef: Ref<HTMLDivElement>, theme: 'light' | 'dark' | 'default' = 'default') {
const { getDarkMode: getSysDarkMode } = useRootSetting() const { getDarkMode: getSysDarkMode } = useRootSetting()
const { getCollapsed } = useMenuSetting() const { getCollapsed } = useMenuSetting()
const getDarkMode = computed(() => { const getDarkMode = computed(() => {
@ -58,11 +57,12 @@ export function useECharts(elRef: Ref<HTMLDivElement>, theme: 'light' | 'dark' |
function setOptions(options: EChartsOption, clear = true) { function setOptions(options: EChartsOption, clear = true) {
cacheOptions.value = options cacheOptions.value = options
return new Promise((resolve) => {
if (unref(elRef)?.offsetHeight === 0) { if (unref(elRef)?.offsetHeight === 0) {
useTimeoutFn(() => { useTimeoutFn(() => {
setOptions(unref(getOptions)) setOptions(unref(getOptions))
resolve(null)
}, 30) }, 30)
return
} }
nextTick(() => { nextTick(() => {
useTimeoutFn(() => { useTimeoutFn(() => {
@ -74,8 +74,10 @@ export function useECharts(elRef: Ref<HTMLDivElement>, theme: 'light' | 'dark' |
clear && chartInstance?.clear() clear && chartInstance?.clear()
chartInstance?.setOption(unref(getOptions)) chartInstance?.setOption(unref(getOptions))
resolve(null)
}, 30) }, 30)
}) })
})
} }
function resize() { function resize() {