diff --git a/src/views/components/echarts/lendAcross.vue b/src/views/components/echarts/lendAcross.vue index 1c1a415..cbdc751 100644 --- a/src/views/components/echarts/lendAcross.vue +++ b/src/views/components/echarts/lendAcross.vue @@ -24,11 +24,17 @@ export default { height: { type: String, default: '100%' + }, + refreshtime: { + type: Number, + default: null // 接收父组件的刷新间隔值 } }, + data() { return { - chart: null + chart: null, + timer: null } }, watch: { @@ -43,11 +49,22 @@ export default { } }, mounted() { - this.drawChart() + // this.drawChart() + this.refreshEchart() }, beforeDestroy() { + clearInterval(this.timer) }, methods: { + refreshEchart() { + if (this.refreshtime) { + this.timer = setInterval(() => { + this.drawChart() + }, this.refreshtime) + } else { + this.drawChart() + } + }, drawChart() { const chartDom = document.getElementById('mainlend') this.chart = echarts.init(chartDom) @@ -144,6 +161,7 @@ export default { } ] } + this.chart.clear() option && this.chart.setOption(option) } diff --git a/src/views/components/echarts/typePie.vue b/src/views/components/echarts/typePie.vue index 82caf68..483da53 100644 --- a/src/views/components/echarts/typePie.vue +++ b/src/views/components/echarts/typePie.vue @@ -25,11 +25,16 @@ export default { height: { type: String, default: '100%' + }, + refreshtime: { + type: Number, + default: null // 接收父组件的刷新间隔值 } }, data() { return { - chart: null + chart: null, + timer: null } }, watch: { @@ -44,9 +49,22 @@ export default { } }, mounted() { - this.drawChart() + // this.drawChart() + this.refreshEchart() + }, + beforeDestroy() { + clearInterval(this.timer) }, methods: { + refreshEchart() { + if (this.refreshtime) { + this.timer = setInterval(() => { + this.drawChart() + }, this.refreshtime) + } else { + this.drawChart() + } + }, drawChart() { const chartDom = document.getElementById('maintype') this.chart = echarts.init(chartDom, 'light') @@ -100,7 +118,7 @@ export default { } ] } - + this.chart.clear() option && this.chart.setOption(option) } } diff --git a/src/views/environmentalScreen/index.vue b/src/views/environmentalScreen/index.vue index e6d60fb..5f33a47 100644 --- a/src/views/environmentalScreen/index.vue +++ b/src/views/environmentalScreen/index.vue @@ -180,15 +180,15 @@