Commit fb6c76db535bd0c6305d03c0cff876a1f079100b
1 parent
46899aa3
feat(echarts): add getInstance for useECharts
为useECharts添加getInstance以便绑定事件或执行更多自定义动作
Showing
1 changed file
with
16 additions
and
10 deletions
src/hooks/web/useECharts.ts
@@ -23,17 +23,15 @@ export function useECharts( | @@ -23,17 +23,15 @@ export function useECharts( | ||
23 | 23 | ||
24 | resizeFn = useDebounceFn(resize, 200); | 24 | resizeFn = useDebounceFn(resize, 200); |
25 | 25 | ||
26 | - const getOptions = computed( | ||
27 | - (): EChartsOption => { | ||
28 | - if (getDarkMode.value !== 'dark') { | ||
29 | - return cacheOptions.value; | ||
30 | - } | ||
31 | - return { | ||
32 | - backgroundColor: 'transparent', | ||
33 | - ...cacheOptions.value, | ||
34 | - }; | 26 | + const getOptions = computed((): EChartsOption => { |
27 | + if (getDarkMode.value !== 'dark') { | ||
28 | + return cacheOptions.value; | ||
35 | } | 29 | } |
36 | - ); | 30 | + return { |
31 | + backgroundColor: 'transparent', | ||
32 | + ...cacheOptions.value, | ||
33 | + }; | ||
34 | + }); | ||
37 | 35 | ||
38 | function initCharts(t = theme) { | 36 | function initCharts(t = theme) { |
39 | const el = unref(elRef); | 37 | const el = unref(elRef); |
@@ -100,9 +98,17 @@ export function useECharts( | @@ -100,9 +98,17 @@ export function useECharts( | ||
100 | chartInstance = null; | 98 | chartInstance = null; |
101 | }); | 99 | }); |
102 | 100 | ||
101 | + function getInstance(): echarts.ECharts | null { | ||
102 | + if (!chartInstance) { | ||
103 | + initCharts(getDarkMode.value as 'default'); | ||
104 | + } | ||
105 | + return chartInstance; | ||
106 | + } | ||
107 | + | ||
103 | return { | 108 | return { |
104 | setOptions, | 109 | setOptions, |
105 | resize, | 110 | resize, |
106 | echarts, | 111 | echarts, |
112 | + getInstance, | ||
107 | }; | 113 | }; |
108 | } | 114 | } |