fix(aiot): 修复告警列表自动计时 - duration_ms为NULL时显示进行中
问题描述: - 前端告警列表对于新触发的告警(duration_ms=null)仍然显示"5分"等具体时长 - 这是因为前端在显示时没有正确处理null值 解决方案: - 修改 formatDuration 函数,显式检查 duration_ms 是否为 null/undefined - 当 duration_ms 为 null 时,返回"进行中"而不是"--" - 简化模板代码,直接调用 formatDuration 函数处理所有情况 影响范围: - 告警列表表格的持续时长列 - 告警详情弹窗的持续时长字段 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -22,8 +22,10 @@ import {
|
||||
defineOptions({ name: 'AiotAlarmList' });
|
||||
|
||||
/** 格式化持续时长(毫秒 → 可读文本) */
|
||||
function formatDuration(ms: number): string {
|
||||
if (!ms || ms <= 0) return '--';
|
||||
function formatDuration(ms: number | null | undefined): string {
|
||||
// 当 duration_ms 为 null 时,说明告警仍在进行中
|
||||
if (ms === null || ms === undefined) return '进行中';
|
||||
if (ms <= 0) return '--';
|
||||
if (ms < 60000) {
|
||||
return `${Math.round(ms / 1000)} 秒`;
|
||||
}
|
||||
@@ -218,10 +220,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
|
||||
<!-- 持续时长列 -->
|
||||
<template #duration="{ row }">
|
||||
<span v-if="row.durationMs != null && row.durationMs > 0">{{
|
||||
formatDuration(row.durationMs)
|
||||
}}</span>
|
||||
<span v-else class="text-gray-400">--</span>
|
||||
<span>{{ formatDuration(row.durationMs) }}</span>
|
||||
</template>
|
||||
|
||||
<!-- 结束时间列 -->
|
||||
@@ -333,11 +332,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-gray-500">持续时长:</span>
|
||||
<span>{{
|
||||
currentAlert.durationMs != null && currentAlert.durationMs > 0
|
||||
? formatDuration(currentAlert.durationMs)
|
||||
: '-'
|
||||
}}</span>
|
||||
<span>{{ formatDuration(currentAlert.durationMs) }}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-gray-500">触发时间:</span>
|
||||
|
||||
Reference in New Issue
Block a user