From b7d73e61a747000c780ee42b8cfa9ff56d8dc034 Mon Sep 17 00:00:00 2001 From: dmy Date: Wed, 4 Mar 2026 10:09:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=87=A0=E4=BD=95?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=B1=BB=E5=9E=8B=E8=BD=AC=E6=8D=A2=E5=8F=8A?= =?UTF-8?q?=E6=8A=98=E5=8F=A0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webui/src/components/Geometry.vue | 46 ++++++++++++------------------- webview_app.py | 7 +++-- 2 files changed, 21 insertions(+), 32 deletions(-) diff --git a/webui/src/components/Geometry.vue b/webui/src/components/Geometry.vue index 2d8899f..39fe898 100644 --- a/webui/src/components/Geometry.vue +++ b/webui/src/components/Geometry.vue @@ -1,17 +1,14 @@ @@ -57,8 +53,6 @@ const props = defineProps<{ const canvasWidth = 600 const canvasHeight = 500 -// 展开/折叠状态 -const expanded = ref(true) const canvasRef = ref(null) let ctx: CanvasRenderingContext2D | null = null @@ -67,23 +61,14 @@ const margin = { top: 40, right: 40, bottom: 60, left: 60 } const plotWidth = canvasWidth - margin.left - margin.right const plotHeight = canvasHeight - margin.top - margin.bottom -// 切换展开/折叠 -const toggleExpand = () => { - expanded.value = !expanded.value - if (expanded.value) { - setTimeout(() => { - if (canvasRef.value) { - ctx = canvasRef.value.getContext('2d') - draw() - } - }, 350) - } -} - // 计算坐标范围 const calculateRange = () => { - const allHeights = [...props.hArm, 0] // 包含地面 - const allX = [...props.gcX, -props.gcX[0] * 0.5, props.gcX[0] * 1.5] // 扩展水平范围 + // 确保将字符串转换为数字 + const hArmNums = props.hArm.map(v => Number(v)) + const gcXNums = props.gcX.map(v => Number(v)) + + const allHeights = [...hArmNums, 0] // 包含地面 + const allX = [...gcXNums, -gcXNums[0] * 0.5, gcXNums[0] * 1.5] // 扩展水平范围 const yMin = 0 const yMax = Math.max(...allHeights) * 1.15 @@ -105,7 +90,7 @@ const toCanvasY = (y: number, range: ReturnType): number // 绘制函数 const draw = () => { - if (!ctx || !expanded.value) return + if (!ctx) return const range = calculateRange() @@ -208,11 +193,13 @@ const drawWirePoints = (range: ReturnType) => { const c = ctx props.hArm.forEach((height, index) => { - const wireX = props.gcX[index] || 0 + // 确保将字符串转换为数字 + const heightNum = Number(height) + const wireX = Number(props.gcX[index]) || 0 const isGroundWire = index === 0 const canvasX = toCanvasX(wireX, range) - const canvasY = toCanvasY(height, range) + const canvasY = toCanvasY(heightNum, range) // 绘制挂点标记 c.fillStyle = isGroundWire ? '#4CAF50' : '#FF9800' @@ -229,7 +216,7 @@ const drawWirePoints = (range: ReturnType) => { const labelY = canvasY - 8 const wireName = isGroundWire ? '地线' : `导线${index}` - const heightLabel = `H=${height}m` + const heightLabel = `H=${heightNum}m` const xLabel = `X=${wireX}m` c.fillText(wireName, labelX, labelY) @@ -244,7 +231,8 @@ const drawWirePoints = (range: ReturnType) => { const drawGround = (range: ReturnType) => { if (!ctx) return - const groundAngle = props.groundAngels[0] || 0 + // 确保将字符串转换为数字 + const groundAngle = Number(props.groundAngels[0]) || 0 const angleRad = (groundAngle * Math.PI) / 180 ctx.strokeStyle = '#795548' diff --git a/webview_app.py b/webview_app.py index 2af95e9..ff79728 100644 --- a/webview_app.py +++ b/webview_app.py @@ -316,12 +316,13 @@ class EGMWebApp: para.insulator_c_len = float(parameter_data.get('insulator_c_len', 7.02)) para.string_c_len = float(parameter_data.get('string_c_len', 9.2)) para.string_g_len = float(parameter_data.get('string_g_len', 0.5)) - para.gc_x = list(parameter_data.get('gc_x', [17.9, 17])) + # 确保数组元素转换为数字类型 + para.gc_x = [float(x) for x in parameter_data.get('gc_x', [17.9, 17])] para.ground_angels = [ - angel / 180 * math.pi + float(angel) / 180 * math.pi for angel in parameter_data.get('ground_angels', [0]) ] - para.h_arm = list(parameter_data.get('h_arm', [150, 130])) + para.h_arm = [float(h) for h in parameter_data.get('h_arm', [150, 130])] para.altitude = int(parameter_data.get('altitude', 1000)) # 解析电压等级字符串,如 "500kV" -> 500 rated_voltage_str = str(parameter_data.get('rated_voltage', '500kV'))