Parcourir la source

fix(cockpit): 历史与效率列表同步当前报警状态

ChenJZ il y a 22 heures
Parent
commit
14bd47df81
1 fichiers modifiés avec 35 ajouts et 2 suppressions
  1. 35 2
      src/modules/cockpit/stores/eventStore.js

+ 35 - 2
src/modules/cockpit/stores/eventStore.js

@@ -94,6 +94,33 @@ function initialSections() {
     }
 }
 
+/** 当前事件分区是本次请求里最新的一份状态事实;历史/效率行只借用它的 status 字段。 */
+function currentStatusByCode(current) {
+    const result = new Map()
+    const events = current && current.data && Array.isArray(current.data.events) ? current.data.events : []
+    for (const event of events) {
+        const code = event && (event.eventCode || event.eventNo)
+        if (code && event.status) result.set(String(code), event.status)
+    }
+    return result
+}
+
+function mergeRowsStatus(rows, statuses) {
+    if (!Array.isArray(rows) || !statuses.size) return rows
+    return rows.map((row) => {
+        if (!row) return row
+        const status = statuses.get(String(row.eventCode || row.eventNo || ''))
+        return status && status !== row.status ? { ...row, status } : row
+    })
+}
+
+function mergeSectionStatus(section, statuses) {
+    const events = section && section.data && section.data.events
+    if (!Array.isArray(events)) return section
+    const merged = mergeRowsStatus(events, statuses)
+    return merged === events ? section : { ...section, data: { ...section.data, events: merged } }
+}
+
 export const useEventStore = defineStore('eventStore', () => {
     /** 当前切换状态:`WARNING`(预警)或 `ALARM`(报警)。默认预警(`/events/current` 的 mode 必填)。 */
     const mode = ref(EVENT_FAMILY.WARNING)
@@ -382,12 +409,18 @@ export const useEventStore = defineStore('eventStore', () => {
         if (mine !== token) return sections.value
 
         const [current, history, efficiency, analysis, workOrderList, incidentTrend] = requests
+        // 当前事件分区本次刚取到;历史/效率行只借用它的 status。
+        // 后端历史/效率快照即使暂时滞后,列表卡片也不会显示与详情相反的旧状态。
+        const currentStatuses = currentStatusByCode(current)
+        const historyWithStatus = mergeSectionStatus(history, currentStatuses)
         // 票 71 返工:把逐日趋势挂进效率分区(domain 只读 `incidentTrend` 字段)。
         // 取失败(null)时保持缺失 ⇒ 界面说「不画」的原因,不画假线。
         // **同时**用这批带 status 的行替换列表数据源:效率端点不返回 status,
         // 用它画列表会把每条都写成「状态未发布」(维护者 2026-10-29 第 1 条反馈)。
         const trend = incidentTrend && incidentTrend.days ? incidentTrend : null
-        const trendRows = trend && Array.isArray(incidentTrend.rows) ? incidentTrend.rows : null
+        const trendRows = trend && Array.isArray(incidentTrend.rows)
+            ? mergeRowsStatus(incidentTrend.rows, currentStatuses)
+            : null
         const efficiencyWithTrend = efficiency && efficiency.data
             ? {
                   ...efficiency,
@@ -424,7 +457,7 @@ export const useEventStore = defineStore('eventStore', () => {
 
         sections.value = {
             currentEvents: { ...safeCurrent, loaded: true },
-            historyAnalysis: { ...safeHistory, loaded: true },
+            historyAnalysis: { ...historyWithStatus, loaded: true },
             responseEfficiency: { ...efficiencyWithTrend, loaded: true },
             eventAnalysis: { ...analysis, loaded: true },
             workOrderList: { ...workOrderList, loaded: true },