1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
| import { SetupContext, defineComponent, nextTick, onMounted, ref, shallowRef } from 'vue'
|
| import sdk from 'sdk'
| import isEmpty from 'lodash/isEmpty'
| const { packs } = sdk
| const { echarts } = packs
| export default defineComponent({
| name: '图表',
| props: {
| chartOptions: {
| type: Object,
| default: () => ({}),
| },
| },
| setup(props, { attrs, expose }: SetupContext) {
| const chartDomRef = ref()
|
| const myCharts = shallowRef()
| onMounted(async () => {
| await nextTick()
| if (isEmpty(props.chartOptions)) return
| myCharts.value = (await echarts).init(chartDomRef.value)
| myCharts.value.setOption(props.chartOptions)
| })
|
|
| const getChartInstance = () => {
| return myCharts.value
| }
|
| const setChartOptions = (options: any) => {
| if (myCharts.value) {
| myCharts.value.setOption(options)
| }
| }
|
| expose({
| getChartInstance,
| setChartOptions,
| })
|
|
| return () => <div style="height:100%;width:100%" ref={chartDomRef}></div>
| },
| })
|
|