<script setup lang="ts">
/**
* AlarmsList:告è¦ä¸å¿ƒåˆ—表版(当å‰å‘Šè¦ + 历å²å‘Šè¦ï¼‰ã€‚纯 UI:
* åªæ”¶ alarms.logic 归一好的 rows,级别/关键å—过滤与展开为内部状æ€ï¼›
* 组/æ—¶é—´/状æ€è¿‡æ»¤ä¸ºå—控 propsï¼ˆå€¼ç”±é¡µé¢æŒæœ‰å¹¶é©±åЍæœåŠ¡ç«¯é‡å–,CARD-MON-02/03ï¼‰ï¼Œå˜æ›´ç» update:* 上抛
* (状æ€=å·²æ¢å¤æ—¶é¡µé¢æŒ‰ recordStatus=2 æœåŠ¡ç«¯é‡å–,CARD-MON-03 定稿 3)。
* ä¸åšå‘Šè¦è§„则é…ç½®ã€ä¸åšå¤„ç½®æµç¨‹ï¼ˆè®¤é¢†/é™é»˜ï¼ŒåŽç«¯æ— 接å£ï¼ŒC05 å ä½ä¸åŠ¨ï¼‰ï¼›
* è®°å½•è¡Œï¼ˆéž resolved)æä¾›è¡Œæ“作「编辑/åˆ é™¤ã€ï¼ˆCARD-MON-03,ç»äº‹ä»¶ä¸ŠæŠ›ç”±é¡µé¢æ‰§è¡Œï¼‰ï¼Œ
* 工具æ¡ã€Œå¯¼å‡º CSVã€å¯¼å‡ºå½“å‰ç›é€‰ç»“果(≤200 æ¡å·²åŠ è½½è¡Œï¼Œå‰ç«¯åŒæ¥ç”Ÿæˆï¼ŒC17)。
*
* 三段状æ€ï¼šloading(spinner)ã€error(å¯è§é”™è¯¯ + é‡è¯•按钮,ä¸é™é»˜ç©ºæ€ï¼‰ã€ç©ºæ€ã€Œæ²¡æœ‰å‘Šè¦ã€ã€‚
* 级别 Dot:critical 红(err)/ warning 黄(warn)/ info ç°ï¼ˆdefault)。
* çŠ¶æ€ Tag:active=未处ç†ï¼ˆwarn)/ recovered=å·²æ¢å¤ï¼ˆok,CARD-MON-03)/ resolved=已处ç†ï¼ˆdefault ç°ï¼‰ã€‚
* 当å‰å‘Šè¦åœ¨å‰ï¼ˆtoAlarmRows 已排好),历å²åœ¨åŽã€‚
* 行内「告è¦åކå²ã€é“¾æŽ¥ï¼ˆè®°å½•行且有组)→ 上抛 history 事件,由页é¢è®¾ç½®ç»„过滤并滚动。
* 行æ“作「编辑/åˆ é™¤ã€ä»…记录行(row.status !== 'resolved',AlarmHistory åªè¯»ï¼‰ã€‚
* æ ·å¼åªç”¨ --el-* + Tailwindï¼Œæ— ç¡¬ç¼–ç 色值。
*/
import { computed, ref } from 'vue';
import Btn from './Btn.vue';
import Card from './Card.vue';
import Dot from './Dot.vue';
import KIcon from './KIcon.vue';
import Tag from './Tag.vue';
import {
filterAlarms,
type AlarmGroupOption,
type AlarmRow,
type AlarmSeverity,
} from './alarms.logic.ts';
import { buildAlarmCsv } from './alarmRecord.logic.ts';
const props = withDefaults(
defineProps<{
rows: AlarmRow[];
loading?: boolean;
error?: string;
/** 告è¦ç»„下拉选项(alarms-filter-group æ•°æ®æºï¼Œç”±é¡µé¢æ‹‰å–ä¼ å…¥ï¼‰ */
groups?: AlarmGroupOption[];
/** 告è¦ç»„åˆ—è¡¨åŠ è½½å¤±è´¥æç¤ºï¼ˆéžè‡´å‘½ï¼Œä¸‹æ‹‰æ—å¯è§ï¼Œåˆ·æ–°å¯é‡è¯•) */
groupError?: string;
/** æœåŠ¡ç«¯ç»„è¿‡æ»¤ï¼ˆå—æŽ§ï¼›null=全部组;组 Id å—符串é€ä¼ ,走查缺陷②全链 string) */
groupId?: string | null;
/** æ—¶é—´èŒƒå›´ï¼ˆå—æŽ§ï¼ŒYYYY-MM-DD;空=ä¸è¿‡æ»¤ï¼Œä¸é€ 默认时间窗) */
dtStart?: string;
dtEnd?: string;
/** 状æ€è¿‡æ»¤ï¼ˆå—控;''=全部状æ€ï¼›'recovered' æ—¶é¡µé¢æŒ‰ recordStatus=2 æœåŠ¡ç«¯é‡å–,CARD-MON-03) */
statusFilter?: string;
}>(),
{
loading: false,
error: '',
groups: () => [],
groupError: '',
groupId: null,
dtStart: '',
dtEnd: '',
statusFilter: '',
},
);
const emit = defineEmits<{
retry: [];
'update:groupId': [value: string | null];
'update:dtStart': [value: string];
'update:dtEnd': [value: string];
/** 状æ€è¿‡æ»¤ä¸ŠæŠ›ï¼ˆ'recovered' æ—¶é¡µé¢æŒ‰æœåŠ¡ç«¯é‡å–,CARD-MON-03) */
'update:statusFilter': [value: string];
/** 行æ“作「编辑ã€ï¼šä»…è®°å½•è¡Œæ¸²æŸ“ï¼Œé¡µé¢æ‰“开编辑抽屉(CARD-MON-03) */
edit: [row: AlarmRow];
/** 行æ“ä½œã€Œåˆ é™¤ã€ï¼šä»…记录行渲染,页é¢å¼¹ Guard 确认(CARD-MON-03) */
remove: [row: AlarmRow];
/** 行内「告è¦åކå²ã€ï¼šæŒ‰è¯¥ç»„过滤并滚动到列表(CARD-MON-02;组 Id å—符串é€ä¼ ,走查缺陷②) */
history: [groupId: string];
}>();
// ---------- å—æŽ§è¿‡æ»¤ä¸ŠæŠ› ----------
function onGroupChange(e: Event): void {
const v = (e.target as HTMLSelectElement).value;
emit('update:groupId', v === '' ? null : v);
}
function onStartChange(e: Event): void {
emit('update:dtStart', (e.target as HTMLInputElement).value);
}
function onEndChange(e: Event): void {
emit('update:dtEnd', (e.target as HTMLInputElement).value);
}
function onStatusChange(e: Event): void {
emit('update:statusFilter', (e.target as HTMLSelectElement).value);
}
/** 行æ“作「编辑/åˆ é™¤ã€ä¸ŠæŠ›ï¼ˆä»…记录行渲染;AlarmHistory åªè¯»ä¸åœ¨è¡Œå†…æä¾›ï¼‰ */
function onEdit(row: AlarmRow): void {
emit('edit', row);
}
function onRemove(row: AlarmRow): void {
emit('remove', row);
}
/** 行内「告è¦åކå²ã€ï¼šä»…对有组的记录行æä¾›ï¼ˆgroupId 空串哨兵=æ— ç»„ï¼‰ */
function goHistory(groupId: string): void {
if (groupId) emit('history', groupId);
}
// ---------- è¿‡æ»¤çŠ¶æ€ ----------
const levelFilter = ref('');
const appQuery = ref('');
const visible = computed<AlarmRow[]>(() =>
filterAlarms(props.rows, levelFilter.value, props.statusFilter ?? '', appQuery.value),
);
/** 统计æ¡ï¼šåªæ•°å½“å‰å‘Šè¦ï¼ˆactive)里的 critical / warning æ¡æ•° */
const activeCritical = computed(
() => props.rows.filter((r) => r.status === 'active' && r.level === 'critical').length,
);
const activeWarning = computed(
() => props.rows.filter((r) => r.status === 'active' && r.level === 'warning').length,
);
// ---------- 展开行 ----------
const openId = ref<string | null>(null);
function toggle(id: string): void {
openId.value = openId.value === id ? null : id;
}
const LEVEL_DOT_TONE: Record<AlarmSeverity, 'err' | 'warn' | 'default'> = {
critical: 'err',
warning: 'warn',
info: 'default',
};
const LEVEL_LABEL: Record<AlarmSeverity, string> = {
critical: 'Critical',
warning: 'Warning',
info: 'Info',
};
// ---------- 导出 CSV(CARD-MON-03 C17:å‰ç«¯åŒæ¥ç”Ÿæˆï¼Œè¡Œé›†=当å‰ç›é€‰ç»“æžœ ≤200 æ¡å·²åŠ è½½è¡Œï¼‰ ----------
/** 组åè§£æžï¼šå‘Šè¦ç»„ä¸‹æ‹‰æ•°æ®æºä¼˜å…ˆï¼Œå–ä¸åˆ°æ˜¾ GroupId(定稿 5,ä¸é€ 数;组 Id å—符串åŒå½¢æ¯”较) */
function resolveGroupName(groupId: string): string {
return props.groups.find((g) => g.id === groupId)?.name ?? groupId;
}
/** ç”Ÿæˆ CSV 并触å‘ä¸‹è½½ï¼ˆåŒæ¥æ— 异æ¥çª—å£ï¼ŒåŒå‡»é˜²æŠ¤ç”±ã€Œç©ºç»“æžœç¦ç”¨ + title åŽŸå› ã€æ‰¿æ‹…) */
function onExport(): void {
if (visible.value.length === 0) return;
const csv = buildAlarmCsv(visible.value, resolveGroupName);
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = '告è¦è®°å½•导出.csv';
a.click();
URL.revokeObjectURL(url);
}
</script>
<template>
<Card
padding="none"
data-spec="alarms-list"
>
<!-- 过滤工具æ¡ï¼šçº§åˆ« + 状æ€ä¸‹æ‹‰ + 应用æœç´¢ -->
<div
class="flex flex-wrap items-center gap-[8px] border-b border-[var(--el-border-color-light)] px-[14px] py-[10px]"
>
<select
v-model="levelFilter"
data-spec="alarms-filter-level"
class="h-[28px] cursor-pointer rounded-[8px] border border-[var(--el-border-color-light)] bg-[var(--el-bg-color-overlay)] px-[9px] text-[12px] text-[var(--el-text-color-primary)] outline-none focus:border-[var(--el-color-primary)]"
>
<option value="">
全部级别
</option>
<option value="critical">
Critical
</option>
<option value="warning">
Warning
</option>
<option value="info">
Info
</option>
</select>
<!-- 状æ€ä¸‹æ‹‰ï¼ˆCARD-MON-03ï¼šå—æŽ§ï¼Œå˜æ›´ä¸ŠæŠ›ç”±é¡µé¢é©±åЍæœåŠ¡ç«¯é‡å–;已æ¢å¤=recordStatus 2) -->
<select
:value="props.statusFilter ?? ''"
data-spec="alarms-filter-status"
aria-label="按状æ€è¿‡æ»¤"
class="h-[28px] cursor-pointer rounded-[8px] border border-[var(--el-border-color-light)] bg-[var(--el-bg-color-overlay)] px-[9px] text-[12px] text-[var(--el-text-color-primary)] outline-none focus:border-[var(--el-color-primary)]"
@change="onStatusChange"
>
<option value="">
全部状æ€
</option>
<option value="active">
未处ç†
</option>
<option value="resolved">
已处ç†
</option>
<option value="recovered">
å·²æ¢å¤
</option>
</select>
<!-- 告è¦ç»„下拉(CARD-MON-02:æœåŠ¡ç«¯è¿‡æ»¤ï¼Œé€‰ä¸å³å¸¦ groupId é‡å–;「全部组ã€=ä¸è¿‡æ»¤ï¼‰ -->
<select
:value="props.groupId ?? ''"
data-spec="alarms-filter-group"
aria-label="按告è¦ç»„过滤"
:title="props.groupError || undefined"
class="h-[28px] max-w-[180px] cursor-pointer rounded-[8px] border border-[var(--el-border-color-light)] bg-[var(--el-bg-color-overlay)] px-[9px] text-[12px] text-[var(--el-text-color-primary)] outline-none focus:border-[var(--el-color-primary)]"
@change="onGroupChange"
>
<option value="">
全部组
</option>
<option
v-for="g in props.groups"
:key="g.id"
:value="g.id"
>
{{ g.name }}
</option>
</select>
<span
v-if="props.groupError"
data-spec="alarms-group-error"
class="text-[11px] text-[var(--el-color-danger)]"
>{{ props.groupError }}</span>
<!-- 时间范围(CARD-MON-02:dtStart/dtEnd ç›´ä¼ æœåŠ¡ç«¯ï¼›ä¸é€‰=å…¨é‡ï¼Œæ— 默认时间窗) -->
<span
data-spec="alarms-filter-range"
class="flex h-[28px] items-center gap-[4px] rounded-[8px] border border-[var(--el-border-color-light)] bg-[var(--el-bg-color-overlay)] px-[9px]"
>
<input
type="date"
:value="props.dtStart"
aria-label="开始日期"
class="w-[112px] cursor-pointer bg-transparent text-[12px] text-[var(--el-text-color-primary)] outline-none"
@change="onStartChange"
>
<span class="text-[11px] text-[var(--el-text-color-placeholder)]">至</span>
<input
type="date"
:value="props.dtEnd"
aria-label="ç»“æŸæ—¥æœŸ"
class="w-[112px] cursor-pointer bg-transparent text-[12px] text-[var(--el-text-color-primary)] outline-none"
@change="onEndChange"
>
</span>
<div
class="flex h-[28px] items-center gap-[6px] rounded-[8px] border border-[var(--el-border-color-light)] bg-[var(--el-bg-color-overlay)] px-[9px]"
>
<KIcon
name="Search"
:size="13"
class="text-[var(--el-text-color-secondary)]"
/>
<input
v-model="appQuery"
type="text"
placeholder="æœç´¢åº”用 / 节点 / æ ‡é¢˜"
data-spec="alarms-filter-q"
class="w-[160px] bg-transparent text-[12px] text-[var(--el-text-color-primary)] outline-none placeholder:text-[var(--el-text-color-placeholder)]"
>
</div>
<span class="flex-1" />
<!-- 统计æ¡ï¼šå½“å‰ N Critical / M Warning -->
<span
v-if="!loading && !error && rows.length > 0"
data-spec="alarms-stats"
class="flex items-center gap-[10px] font-mono text-[11px] text-[var(--el-text-color-secondary)]"
>
<span class="flex items-center gap-[4px]">
<Dot tone="err" />
å½“å‰ {{ activeCritical }} Critical
</span>
<span class="flex items-center gap-[4px]">
<Dot tone="warn" />
å½“å‰ {{ activeWarning }} Warning
</span>
</span>
<!-- 导出 CSV(CARD-MON-03 C17:导出当å‰ç›é€‰ç»“果;空结果ç¦ç”¨ï¼ŒåŽŸå› åœ¨ title éšçжæ€å®žæ—¶å˜åŒ–) -->
<span
data-spec="alarms-export-note"
class="text-[11px] text-[var(--el-text-color-placeholder)]"
>当å‰ç›é€‰ç»“果(最多最近 200 æ¡ï¼‰</span>
<Btn
size="sm"
data-spec="alarms-export"
:disabled="visible.length === 0"
:title="visible.length === 0 ? '当å‰ç›é€‰ç»“æžœä¸ºç©ºï¼Œæ— å¯å¯¼å‡ºæ•°æ®' : '导出当å‰ç›é€‰ç»“果为 CSV'"
@click="onExport"
>
导出 CSV
</Btn>
</div>
<!-- åŠ è½½ä¸ -->
<div
v-if="loading"
data-spec="alarms-loading"
class="flex items-center gap-[8px] px-[14px] py-[18px] text-[12.5px] text-[var(--el-text-color-secondary)]"
>
<span class="inline-block h-[14px] w-[14px] animate-spin rounded-full border-2 border-[var(--el-border-color)] border-t-[var(--el-color-primary)]" />
告è¦åŠ è½½ä¸â€¦
</div>
<!-- 失败:å¯è§é”™è¯¯ + é‡è¯•,ä¸å½“ä½œç©ºæ€ -->
<div
v-else-if="error"
data-spec="alarms-failed"
class="flex items-center gap-[10px] px-[14px] py-[14px] text-[12.5px] text-[var(--el-color-danger)]"
>
告è¦åŠ è½½å¤±è´¥ï¼š{{ error }}
<Btn
size="sm"
data-spec="alarms-retry"
@click="emit('retry')"
>
é‡è¯•
</Btn>
</div>
<!-- 空æ€ï¼šæ— æ•°æ®ï¼ˆæˆ–过滤åŽä¸ºç©ºç»Ÿä¸€æç¤ºï¼‰ -->
<div
v-else-if="visible.length === 0"
data-spec="alarms-empty"
class="px-[14px] py-[22px] text-center text-[12.5px] text-[var(--el-text-color-secondary)]"
>
<template v-if="rows.length === 0">
没有告è¦
</template>
<template v-else>
当å‰è¿‡æ»¤æ¡ä»¶ä¸‹æ²¡æœ‰åŒ¹é…的告è¦
</template>
</div>
<!-- è¡¨æ ¼ -->
<template v-else>
<table class="w-full border-collapse">
<thead>
<tr>
<th class="w-[60px] border-b border-[var(--el-border-color-light)] px-[14px] py-[9px] text-left text-[11px] font-medium text-[var(--el-text-color-secondary)]">
级别
</th>
<th class="border-b border-[var(--el-border-color-light)] px-[10px] py-[9px] text-left text-[11px] font-medium text-[var(--el-text-color-secondary)]">
å‘Šè¦æ ‡é¢˜
</th>
<th class="w-[140px] border-b border-[var(--el-border-color-light)] px-[10px] py-[9px] text-left text-[11px] font-medium text-[var(--el-text-color-secondary)]">
对象
</th>
<th class="w-[80px] border-b border-[var(--el-border-color-light)] px-[10px] py-[9px] text-left text-[11px] font-medium text-[var(--el-text-color-secondary)]">
状æ€
</th>
<th class="w-[110px] border-b border-[var(--el-border-color-light)] px-[10px] py-[9px] text-left text-[11px] font-medium text-[var(--el-text-color-secondary)]">
æŒç»æ—¶é—´
</th>
<th class="w-[80px] border-b border-[var(--el-border-color-light)] px-[10px] py-[9px] text-right text-[11px] font-medium text-[var(--el-text-color-secondary)]">
通知次数
</th>
<th class="w-[130px] border-b border-[var(--el-border-color-light)] px-[14px] py-[9px] text-right text-[11px] font-medium text-[var(--el-text-color-secondary)]">
开始时间
</th>
</tr>
</thead>
<tbody>
<template
v-for="row in visible"
:key="row.id"
>
<tr
data-spec="alarm-row"
:data-level="row.level"
:data-status="row.status"
:data-open="openId === row.id"
class="cursor-pointer transition-colors hover:bg-[var(--el-bg-color-overlay)]"
@click="toggle(row.id)"
>
<td class="border-b border-[var(--el-border-color-light)] px-[14px] py-[10px]">
<span class="flex items-center gap-[6px]">
<Dot :tone="LEVEL_DOT_TONE[row.level]" />
<span class="font-mono text-[10.5px] uppercase text-[var(--el-text-color-secondary)]">
{{ LEVEL_LABEL[row.level] }}
</span>
</span>
</td>
<td class="border-b border-[var(--el-border-color-light)] px-[10px] py-[10px]">
<span class="flex items-center gap-[6px]">
<b class="truncate text-[12.5px] font-medium text-[var(--el-text-color-primary)]">{{ row.title }}</b>
<button
v-if="row.status !== 'resolved' && row.groupId !== ''"
type="button"
data-spec="alarms-history-link"
title="查看该组告è¦åކå²"
class="shrink-0 cursor-pointer text-[11px] text-[var(--el-color-primary)] hover:underline"
@click.stop="goHistory(row.groupId)"
>
告è¦åކå²
</button>
<!-- 行æ“作(CARD-MON-03):仅记录行(active/recovered),AlarmHistory åªè¯»ä¸æä¾› -->
<button
v-if="row.status !== 'resolved'"
type="button"
data-spec="alarm-record-edit"
title="编辑该告è¦è®°å½•"
class="shrink-0 cursor-pointer text-[11px] text-[var(--el-color-primary)] hover:underline"
@click.stop="onEdit(row)"
>
编辑
</button>
<button
v-if="row.status !== 'resolved'"
type="button"
data-spec="alarm-record-remove"
title="åˆ é™¤è¯¥å‘Šè¦è®°å½•"
class="shrink-0 cursor-pointer text-[11px] text-[var(--el-color-danger)] hover:underline"
@click.stop="onRemove(row)"
>
åˆ é™¤
</button>
<KIcon
:name="openId === row.id ? 'ChevronDown' : 'ChevronRight'"
:size="13"
class="shrink-0 text-[var(--el-text-color-secondary)]"
/>
</span>
</td>
<td class="truncate border-b border-[var(--el-border-color-light)] px-[10px] py-[10px] text-[12px] text-[var(--el-text-color-secondary)]">
{{ row.appName }}
</td>
<td class="border-b border-[var(--el-border-color-light)] px-[10px] py-[10px]">
<Tag
v-if="row.status === 'active'"
tone="warn"
>
未处ç†
</Tag>
<Tag
v-else-if="row.status === 'recovered'"
tone="ok"
>
å·²æ¢å¤
</Tag>
<Tag
v-else
tone="default"
>
已处ç†
</Tag>
</td>
<td class="border-b border-[var(--el-border-color-light)] px-[10px] py-[10px] font-mono text-[11.5px] tabular-nums text-[var(--el-text-color-secondary)]">
{{ row.durationText }}
</td>
<td class="border-b border-[var(--el-border-color-light)] px-[10px] py-[10px] text-right font-mono text-[11.5px] tabular-nums text-[var(--el-text-color-secondary)]">
{{ row.times }}
</td>
<td class="border-b border-[var(--el-border-color-light)] px-[14px] py-[10px] text-right font-mono text-[11.5px] tabular-nums text-[var(--el-text-color-secondary)]">
{{ row.startTime }}
</td>
</tr>
<!-- 展开详情:完整 Content + Category + Action + æ—¶é—´çº¿ä¿¡æ¯ -->
<tr
v-if="openId === row.id"
data-spec="alarm-detail"
>
<td
colspan="7"
class="border-b border-[var(--el-border-color-light)] bg-[var(--el-fill-color-light)] px-[18px] py-[12px]"
>
<pre
v-if="row.content"
data-spec="alarm-content"
class="m-0 whitespace-pre-wrap rounded-[8px] border border-[var(--el-border-color-light)] bg-[var(--el-bg-color)] p-[10px] font-mono text-[12px] leading-relaxed text-[var(--el-text-color-regular)]"
>{{ row.content }}</pre>
<div class="mt-[8px] grid grid-cols-2 gap-x-[16px] gap-y-[4px] text-[11.5px] text-[var(--el-text-color-secondary)] min-[720px]:grid-cols-5">
<span>类别:{{ row.category || '—' }}</span>
<span>对象:{{ row.action || '—' }}</span>
<span>开始:{{ row.startTime }}</span>
<span>æŒç»ï¼š{{ row.durationText }}</span>
<span data-spec="alarm-error">错误:{{ row.error || '(空)' }}</span>
</div>
</td>
</tr>
</template>
</tbody>
</table>
</template>
</Card>
</template>
|