fix(hooks): 修改useEcharts getInstance无法获取
parent
286cd991d3
commit
4c2b3abbac
|
@ -12,7 +12,6 @@ import { useMenuSetting } from '@/hooks/setting/useMenuSetting'
|
|||
|
||||
export function useECharts(elRef: Ref<HTMLDivElement>, theme: 'light' | 'dark' | 'default' = 'default') {
|
||||
const { getDarkMode: getSysDarkMode } = useRootSetting()
|
||||
|
||||
const { getCollapsed } = useMenuSetting()
|
||||
|
||||
const getDarkMode = computed(() => {
|
||||
|
@ -58,23 +57,26 @@ export function useECharts(elRef: Ref<HTMLDivElement>, 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')
|
||||
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()
|
||||
if (!chartInstance) return
|
||||
}
|
||||
clear && chartInstance?.clear()
|
||||
|
||||
chartInstance?.setOption(unref(getOptions))
|
||||
}, 30)
|
||||
chartInstance?.setOption(unref(getOptions))
|
||||
resolve(null)
|
||||
}, 30)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue