@@ -10,7 +10,7 @@ import { processAnimation, processAria, processFont, processRtl } from "@util/ec
1010import { type AriaComponentOption , type ComposeOption , SeriesOption , TitleComponentOption } from "echarts"
1111import { type ECharts , init } from "echarts/core"
1212import { ElLoading } from "element-plus"
13- import { type Ref , isRef , onMounted , ref , watch } from "vue"
13+ import { type Ref , type WatchSource , isRef , onMounted , ref , watch } from "vue"
1414import { useElementSize } from './useElementSize'
1515import { useWindowSize } from "./useWindowSize"
1616
@@ -86,7 +86,6 @@ export abstract class EchartsWrapper<BizOption, EchartsOption> {
8686
8787
8888type WrapperResult < BizOption , EchartsOption , EW extends EchartsWrapper < BizOption , EchartsOption > > = {
89- refresh : ( ) => Promise < void >
9089 elRef : Ref < HTMLDivElement | undefined >
9190 wrapper : EW
9291}
@@ -97,15 +96,17 @@ export const useEcharts = <BizOption, EchartsOption, EW extends EchartsWrapper<B
9796 option ?: {
9897 hideLoading ?: boolean
9998 manual ?: boolean
100- afterInit ?: ( ew : EW ) => void
99+ afterInit ?: ArgCallback < EW > ,
100+ deps ?: WatchSource | WatchSource [ ] ,
101101 } ) : WrapperResult < BizOption , EchartsOption , EW > => {
102102 const elRef = ref < HTMLDivElement > ( )
103103 const wrapperInstance = new Wrapper ( )
104104 const {
105105 hideLoading = false ,
106106 manual = false ,
107107 afterInit,
108- } = option || { }
108+ deps,
109+ } = option ?? { }
109110
110111 let refresh = async ( ) => {
111112 const loading = hideLoading ? null : ElLoading . service ( { target : elRef . value } )
@@ -124,13 +125,11 @@ export const useEcharts = <BizOption, EchartsOption, EW extends EchartsWrapper<B
124125 isRef ( fetch ) && watch ( fetch , refresh )
125126 } )
126127
128+ deps && watch ( deps , refresh )
129+
127130 const { width : winW , height : winH } = useWindowSize ( )
128131 const { width : elW , height : elH } = useElementSize ( elRef , { debounce : 50 } )
129132 watch ( [ winW , winH , elW , elH ] , ( ) => wrapperInstance ?. resize ?.( ) )
130133
131- return {
132- refresh,
133- elRef,
134- wrapper : wrapperInstance ,
135- }
134+ return { elRef, wrapper : wrapperInstance }
136135}
0 commit comments