From 2401b0b19a268737627a27b59a6f8c1376860ba3 Mon Sep 17 00:00:00 2001 From: dmy Date: Tue, 3 Mar 2026 10:19:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=B7=B3=E9=97=B8?= =?UTF-8?q?=E7=8E=87=E8=A7=A3=E6=9E=90=E5=B9=B6=E5=AE=9E=E7=8E=B0=E9=9B=B7?= =?UTF-8?q?=E6=9A=B4=E6=97=A5=E4=B8=8E=E5=9C=B0=E9=97=AA=E5=AF=86=E5=BA=A6?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在Log组件中解析跳闸率数值并暴露给父组件 在ParameterForm组件中实现雷暴日与地闪密度的双向自动转换 --- webui/src/components/Log.vue | 11 ++++++++- webui/src/components/ParameterForm.vue | 31 ++++++++++++++++++++------ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/webui/src/components/Log.vue b/webui/src/components/Log.vue index d4ce06c..e8260c0 100644 --- a/webui/src/components/Log.vue +++ b/webui/src/components/Log.vue @@ -40,6 +40,7 @@ interface LogEntry { const logs = ref([]) const logContainer = ref(null) const expanded = ref(true) +const lastTripRates = ref([]) const addLog = (level: LogEntry['level'], message: string) => { const now = new Date() @@ -47,6 +48,13 @@ const addLog = (level: LogEntry['level'], message: string) => { logs.value.push({ level, time, message }) + // 解析跳闸率数值 + const match = message.match(/不同相跳闸率是\[([\d.\s]+)\]/) + if (match) { + const values = match[1].trim().split(/\s+/).map(Number) + lastTripRates.value = values + } + // 自动滚动到底部 nextTick(() => { if (logContainer.value) { @@ -62,7 +70,8 @@ const clearLog = () => { // 暴露方法给父组件 defineExpose({ addLog, - clearLog + clearLog, + lastTripRates }) diff --git a/webui/src/components/ParameterForm.vue b/webui/src/components/ParameterForm.vue index 43664ca..82e98e8 100644 --- a/webui/src/components/ParameterForm.vue +++ b/webui/src/components/ParameterForm.vue @@ -381,17 +381,34 @@ const currentType = computed(() => { return params.parameter.rated_voltage.includes('±') ? 'DC' : 'AC' }) -// 当地闪密度大于 0 时,自动将雷暴日设为 -1,且不可编辑 -// 当地闪密度小于 0 时,自动将雷暴日设为 20,且可以编辑 -const isTdDisabled = computed(() => Number(params.advance.ng) > 0) +// 雷暴日与地闪密度相互转换,公式:ng = 0.023 * td^3 +// 标志位避免循环更新 +let isUpdatingFromWatch = false watch( () => params.advance.ng, (newNg) => { - if (Number(newNg) > 0) { - params.parameter.td = -1 - } else { - params.parameter.td = 20 + if (isUpdatingFromWatch) return + const ng = Number(newNg) + if (ng > 0) { + isUpdatingFromWatch = true + // td = (ng / 0.023)^(1/1.3) + params.parameter.td = Math.round(Math.pow(ng / 0.023, 1/1.3) * 100) / 100 + isUpdatingFromWatch = false + } + } +) + +watch( + () => params.parameter.td, + (newTd) => { + if (isUpdatingFromWatch) return + const td = Number(newTd) + if (td > 0) { + isUpdatingFromWatch = true + // ng = 0.023 * td^1.3 + params.advance.ng = Math.round(0.023 * Math.pow(td, 1.3) * 100) / 100 + isUpdatingFromWatch = false } } )