From 5a8953d1e57eea84b6755ced9715c3c9623943bb Mon Sep 17 00:00:00 2001 From: dmy Date: Mon, 2 Mar 2026 23:20:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E5=B9=B6=E8=B0=83=E6=95=B4=E5=AF=BC=E7=BA=BF?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E6=93=8D=E4=BD=9C=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在main.py中添加gc_x和h_arm长度校验 在ParameterForm.vue中修改导线数量操作逻辑,仅允许1或3条导线 --- main.py | 11 +++++++++ webui/src/components/ParameterForm.vue | 34 ++++++++++++++++---------- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/main.py b/main.py index b675d22..2dc286a 100644 --- a/main.py +++ b/main.py @@ -71,6 +71,17 @@ def run_egm(para: Parameter) -> dict: 计算结果字典。 """ parameter_display(para) + + # 参数校验:gc_x 和 h_arm 长度必须一致 + if len(para.gc_x) != len(para.h_arm): + error_msg = f"参数错误:gc_x 长度({len(para.gc_x)})与 h_arm 长度({len(para.h_arm)})不一致" + logger.error(error_msg) + return { + "success": False, + "message": error_msg, + "data": None + } + h_whole = para.h_arm[0] # 挂点高 string_g_len = para.string_g_len string_c_len = para.string_c_len diff --git a/webui/src/components/ParameterForm.vue b/webui/src/components/ParameterForm.vue index 1a456b4..43664ca 100644 --- a/webui/src/components/ParameterForm.vue +++ b/webui/src/components/ParameterForm.vue @@ -128,10 +128,10 @@ />
- +
- +
@@ -152,10 +152,10 @@ />
- +
- +
@@ -396,41 +396,49 @@ watch( } ) -// 数组操作函数(最多3条导线,即数组最多4个元素:1地线+3导线) +// 数组操作函数(导线数量只能是1或3条,即数组长度为2或4:1地线+导线) // 两个数组同步增减 const addHArm = () => { - if (params.parameter.h_arm.length < 4) { + if (params.parameter.h_arm.length === 2) { + // 从1条导线增加到3条导线,添加2个元素 const last = params.parameter.h_arm[params.parameter.h_arm.length - 1] || 100 - params.parameter.h_arm.push(last - 20) + params.parameter.h_arm.push(last - 20, last - 40) // 同步增加 gc_x const lastX = params.parameter.gc_x[params.parameter.gc_x.length - 1] || 10 - params.parameter.gc_x.push(lastX) + params.parameter.gc_x.push(lastX, lastX) } } const removeHArm = () => { - if (params.parameter.h_arm.length > 2) { + if (params.parameter.h_arm.length === 4) { + // 从3条导线减少到1条导线,移除2个元素 + params.parameter.h_arm.pop() params.parameter.h_arm.pop() // 同步删除 gc_x params.parameter.gc_x.pop() + params.parameter.gc_x.pop() } } const addGcX = () => { - if (params.parameter.gc_x.length < 4) { + if (params.parameter.gc_x.length === 2) { + // 从1条导线增加到3条导线,添加2个元素 const lastX = params.parameter.gc_x[params.parameter.gc_x.length - 1] || 10 - params.parameter.gc_x.push(lastX) + params.parameter.gc_x.push(lastX, lastX) // 同步增加 h_arm const last = params.parameter.h_arm[params.parameter.h_arm.length - 1] || 100 - params.parameter.h_arm.push(last - 20) + params.parameter.h_arm.push(last - 20, last - 40) } } const removeGcX = () => { - if (params.parameter.gc_x.length > 2) { + if (params.parameter.gc_x.length === 4) { + // 从3条导线减少到1条导线,移除2个元素 + params.parameter.gc_x.pop() params.parameter.gc_x.pop() // 同步删除 h_arm params.parameter.h_arm.pop() + params.parameter.h_arm.pop() } }