From 7535ff77442b90021c71509d8cbb495e95b5555f Mon Sep 17 00:00:00 2001 From: zhangdi <1104545947@qq.com> Date: Thu, 26 Mar 2026 13:45:00 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=B8=E4=BC=BC=E9=9B=B6=E4=BB=B6=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 2 +- src/views/processManagement/sinTer/index.vue | 38 ++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 5275750..3c2b429 100644 --- a/index.html +++ b/index.html @@ -46,7 +46,7 @@ - + diff --git a/src/views/processManagement/sinTer/index.vue b/src/views/processManagement/sinTer/index.vue index a1246e8..c884846 100644 --- a/src/views/processManagement/sinTer/index.vue +++ b/src/views/processManagement/sinTer/index.vue @@ -216,7 +216,7 @@ export default { // 中文字符宽度≈fontSize,英文字符≈fontSize/2,加额外内边距 const cnChar = text.replace(/[a-zA-Z0-9]/g, '').length; const enChar = text.length - cnChar; - return cnChar * fontSize + enChar * (fontSize / 2) + 10; // +20 内边距 + return cnChar * fontSize + enChar * (fontSize / 2) + 20; // +20 内边距 }, // 图表 createBarChart(value) { @@ -228,7 +228,9 @@ export default { this.$nextTick(() => { if (!this.$refs.lineChart) return; - + const chartWidth = this.calculateChartWidth(value); + this.$refs.lineChart.style.width = chartWidth + 'px'; + console.log(98989898989, chartWidth); const mapBoxEchart = this.$echarts.init(this.$refs.lineChart); this.mapBoxEchart = mapBoxEchart; @@ -327,6 +329,38 @@ export default { }); }); }, + // 计算图表所需宽度 + calculateChartWidth(data) { + if (!data || data.length === 0) return 1000; + + let maxChildren = 0; + let maxDepth = 0; + + const traverse = (nodes, depth = 0) => { + if (!nodes || nodes.length === 0) return; + maxDepth = Math.max(maxDepth, depth); + + nodes.forEach(node => { + if (node.children && node.children.length > 0) { + maxChildren = Math.max(maxChildren, node.children.length); + traverse(node.children, depth + 1); + } + }); + }; + + traverse(data); + + // 根据子节点数量和层级计算宽度 + // 每个节点约 200px,每层约 150px + const width = Math.max( + maxChildren * 200, + maxDepth * 150, + 1000 // 最小宽度 1000px + ); + + console.log('图表宽度计算:', { maxChildren, maxDepth, width }); + return width; + }, }, };