From 789a408c27a804361e9f4a48129a067eb01bd5e1 Mon Sep 17 00:00:00 2001 From: "zhu.yawen" Date: Tue, 26 Sep 2023 16:23:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D3D=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E9=A2=9C=E8=89=B2=E9=85=8D=E7=BD=AE=E5=90=8E=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=9B=86=E9=A2=9C=E8=89=B2=E5=A4=B1=E6=95=88?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data-room-ui/packages/EchartsRender/index.vue | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/data-room-ui/packages/EchartsRender/index.vue b/data-room-ui/packages/EchartsRender/index.vue index 145a6152..3697669b 100644 --- a/data-room-ui/packages/EchartsRender/index.vue +++ b/data-room-ui/packages/EchartsRender/index.vue @@ -74,7 +74,17 @@ export default { } }, mounted () { - + const dragSelect = document.querySelector('#' + this.chatId) + const resizeObserver = new ResizeObserver(entries => { + if (this.chart) { + this.chart.resize() + let config = this.observeChart(entries) + config = this.seriesStyle(config) + config.option && this.chart.setOption(config.option) + } + // const config = this.observeChart(entries) + }) + resizeObserver.observe(dragSelect) }, beforeDestroy () { if (this.chart) { @@ -118,31 +128,21 @@ export default { const chartDom = document.getElementById(this.chatId) this.chart = echarts.init(chartDom) config.option && this.chart.setOption(config.option) - this.observeChart(chartDom, this.chart) }, /** * 控制底部阴影大小 */ - observeChart (container, myChart) { - const resizeObserver = new ResizeObserver(entries => { - myChart.resize() - // entries[0].contentRect.width:此时监测的盒子的宽度 - // entries[0].contentRect.height:此时监测的盒子的高度 - const width = entries[0].contentRect.width - const height = entries[0].contentRect.height - const option = this.config.option - // 调整长方形的大小 - option.graphic.children[0].shape.width = width * 0.9 - // 调整多边形的大小 - option.graphic.children[1].shape.points = [ - [width / 10, -height / 6], - [width - width / 6, -height / 6], - [width * 0.9, 0], - [0, 0] - ] - myChart.setOption(option) - }) - resizeObserver.observe(container) + observeChart (entries) { + // entries[0].contentRect.width:此时监测的盒子的宽度 + // entries[0].contentRect.height:此时监测的盒子的高度 + const width = entries[0].contentRect.width + const height = entries[0].contentRect.height + const option = this.config.option + // 调整长方形的大小 + option.graphic.children[0].shape.width = width * 0.9 + // 调整多边形的大小 + option.graphic.children[1].shape.points = [[width / 10, -height / 6], [width - width / 6, -height / 6], [width * 0.9, 0], [0, 0]] + return this.config }, /** * 注册事件 @@ -237,7 +237,6 @@ export default { return config }, dataFormatting (config, data) { - console.log('config', config); // config = this.config // 数据返回成功则赋值 if (data.success) {