diff --git a/src/hooks/echart.js b/src/hooks/echart.js index cc07670..a154282 100644 --- a/src/hooks/echart.js +++ b/src/hooks/echart.js @@ -3,21 +3,21 @@ import * as echarts from 'echarts' import { guid } from '@/utils/util' export function useEchart() { - let chart = null + let chart = ref(null) let id = ref(guid()) const initChart = () => { const dom = document.getElementById(id.value) - chart = echarts.init(dom) + chart.value = echarts.init(dom) } const setOption = (params, update = false) => { - chart.setOption(params, update) + chart.value.setOption(params, update) } const dispose = () => { - chart.dispose() - chart = null + chart.value.dispose() + chart.value = null } const resize = () => { - chart.resize() + chart.value.resize() } onMounted(() => { initChart() diff --git a/src/views/monitor/components/alarmRate.vue b/src/views/monitor/components/alarmRate.vue index 1b13001..73fb07d 100644 --- a/src/views/monitor/components/alarmRate.vue +++ b/src/views/monitor/components/alarmRate.vue @@ -27,16 +27,10 @@ } }) - const { id, setOption } = useEchart() + const { id, chart, setOption } = useEchart() let params = null - let getTotal = () => { - return props.dataList.reduce((per, cur) => { - return per + cur.count - }, 0) - } - let defaultCofig = { color: [], legend: { @@ -48,7 +42,7 @@ itemGap: fitChartSize(6), formatter: (name) => { let obj = props.dataList.find((item) => item.name == name) - return `{name|${name}} {value|${obj?.value}}{value|%}` + return `{name|${name}} {value|${obj?.value}}{value|次}` }, textStyle: { rich: { @@ -97,13 +91,17 @@ ] } + let getTotal = () => { + return props.dataList.reduce((per, cur) => { + return per + cur.value + }, 0) + } + watch( - () => props.dataList, - (val) => { - if (val.length > 0) { - setTimeout(() => { - init() - }, 1000) + () => [props.dataList, chart.value], + () => { + if (props.dataList.length > 0 && chart.value) { + init() } }, { immediate: true } diff --git a/src/views/monitor/components/box-1.vue b/src/views/monitor/components/box-1.vue index e561771..432e601 100644 --- a/src/views/monitor/components/box-1.vue +++ b/src/views/monitor/components/box-1.vue @@ -3,32 +3,58 @@