feat: 添加跳闸率解析并实现雷暴日与地闪密度自动转换
在Log组件中解析跳闸率数值并暴露给父组件 在ParameterForm组件中实现雷暴日与地闪密度的双向自动转换
This commit is contained in:
@@ -40,6 +40,7 @@ interface LogEntry {
|
|||||||
const logs = ref<LogEntry[]>([])
|
const logs = ref<LogEntry[]>([])
|
||||||
const logContainer = ref<HTMLElement | null>(null)
|
const logContainer = ref<HTMLElement | null>(null)
|
||||||
const expanded = ref(true)
|
const expanded = ref(true)
|
||||||
|
const lastTripRates = ref<number[]>([])
|
||||||
|
|
||||||
const addLog = (level: LogEntry['level'], message: string) => {
|
const addLog = (level: LogEntry['level'], message: string) => {
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
@@ -47,6 +48,13 @@ const addLog = (level: LogEntry['level'], message: string) => {
|
|||||||
|
|
||||||
logs.value.push({ level, time, message })
|
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(() => {
|
nextTick(() => {
|
||||||
if (logContainer.value) {
|
if (logContainer.value) {
|
||||||
@@ -62,7 +70,8 @@ const clearLog = () => {
|
|||||||
// 暴露方法给父组件
|
// 暴露方法给父组件
|
||||||
defineExpose({
|
defineExpose({
|
||||||
addLog,
|
addLog,
|
||||||
clearLog
|
clearLog,
|
||||||
|
lastTripRates
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -381,17 +381,34 @@ const currentType = computed(() => {
|
|||||||
return params.parameter.rated_voltage.includes('±') ? 'DC' : 'AC'
|
return params.parameter.rated_voltage.includes('±') ? 'DC' : 'AC'
|
||||||
})
|
})
|
||||||
|
|
||||||
// 当地闪密度大于 0 时,自动将雷暴日设为 -1,且不可编辑
|
// 雷暴日与地闪密度相互转换,公式:ng = 0.023 * td^3
|
||||||
// 当地闪密度小于 0 时,自动将雷暴日设为 20,且可以编辑
|
// 标志位避免循环更新
|
||||||
const isTdDisabled = computed(() => Number(params.advance.ng) > 0)
|
let isUpdatingFromWatch = false
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => params.advance.ng,
|
() => params.advance.ng,
|
||||||
(newNg) => {
|
(newNg) => {
|
||||||
if (Number(newNg) > 0) {
|
if (isUpdatingFromWatch) return
|
||||||
params.parameter.td = -1
|
const ng = Number(newNg)
|
||||||
} else {
|
if (ng > 0) {
|
||||||
params.parameter.td = 20
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user