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()
}
}