Prechádzať zdrojové kódy

feat(cockpit): 报警类型筛选与跨窗口类型计数对齐

ChenJZ 7 hodín pred
rodič
commit
e514ad0c8a

+ 2 - 2
src/modules/cockpit/components/WarningResponsePane.vue

@@ -34,7 +34,7 @@
         <div v-if="['historyAnalysis', 'eventAnalysis'].includes(props.panelId) && historyFilter.code" class="warning-response-pane__filter" role="status" data-history-type-filter>
             <span class="warning-response-pane__filter-kicker">类型筛选</span>
             <b class="warning-response-pane__filter-name">{{ historyFilter.label || historyFilter.code }}</b>
-            <small class="warning-response-pane__filter-scope">{{ props.panelId === 'historyAnalysis' ? '仅作用于历史事件' : '已应用到历史分析' }}</small>
+            <small class="warning-response-pane__filter-scope">{{ props.panelId === 'historyAnalysis' ? '向下滚动查看已筛选历史事件' : '已应用到历史分析' }}</small>
             <button type="button" class="warning-response-pane__filter-clear" @click="clearHistoryFilter">清除筛选</button>
         </div>
         <PanelBlocks v-if="view" :key="`${panelId}-${eventStore.mode}-${eventStore.range}`" :class="{ 'is-updating': eventStore.loading }" :view="view" @list-page="onListPage" @card-action="onCardAction" @panel-action="onPanelAction" />
@@ -162,7 +162,7 @@ function onPanelAction(action) {
     const section = eventStore.sections.eventAnalysis
     const rows = (section && section.data && section.data.types) || []
     const row = rows.find((item) => item && item.code === code)
-    eventStore.setHistoryTypeFilter(code, (row && row.label) || code)
+    eventStore.setHistoryTypeFilter(code, (row && row.label) || code, eventStore.mode)
     return true
 }
 

+ 1 - 1
src/modules/cockpit/domain/overviewPanels.js

@@ -698,7 +698,7 @@ export function warningStudyPanel(data, section) {
         ),
         // 全类型可点:动作键 `warningType`(落点:切「预警处置」模式并按类型过滤本地列表)。
         // 维护者 2026-10-23 第 4 条:不再只列前三,所有类型都排出来(limit: 0 = 全部)。
-        rankingBarsBlock('预警类型排行', ranking.top || [], {
+        rankingBarsBlock('预警类型排行(30日)', ranking.top || [], {
             limit: 0,
             action: 'warningType',
             variant: 'rank',

+ 28 - 7
src/modules/cockpit/domain/warningResponsePanels.js

@@ -482,8 +482,13 @@ export function historyAnalysisPanel(data, section, extra = {}) {
     const current = data || {}
     const filter = extra.historyTypeFilter && typeof extra.historyTypeFilter === 'object' ? extra.historyTypeFilter : {}
     const filterCode = typeof filter.code === 'string' ? filter.code.trim() : ''
+    const filterFamily = String(filter.family || '').toUpperCase()
     const allEvents = Array.isArray(current.events) ? current.events : []
-    const events = filterCode ? allEvents.filter((item) => item && item.type === filterCode) : allEvents
+    const events = filterCode
+        ? allEvents.filter((item) => item && (filterFamily === EVENT_FAMILY.ALARM
+            ? String(item.name || '').trim() === filterCode
+            : item.type === filterCode))
+        : allEvents
     const filtered = filterCode ? { ...current, events } : current
     const levelCounts = [1, 2, 3, 4].map((level) => ({
         code: String(level),
@@ -1191,6 +1196,20 @@ function alarmEventTypeRows(current, family, extra) {
         .map(([label, count]) => ({ code: label, label, count }))
         .sort((left, right) => right.count - left.count)
 }
+
+/** 预警族「按事件类型」以**同一份已加载历史行**聚合,避免 90 天多窗与后端 30 天窗口对不上。 */
+function historyEventTypeRows(events) {
+    if (!Array.isArray(events) || !events.length) return null
+    const counts = new Map()
+    for (const event of events) {
+        const code = String((event && event.type) || '').trim()
+        if (!code) continue
+        counts.set(code, (counts.get(code) || 0) + 1)
+    }
+    return [...counts.entries()]
+        .map(([code, count]) => ({ code, label: eventTypeText(code), count }))
+        .sort((left, right) => right.count - left.count)
+}
 export function eventAnalysisPanel(data, section, extra) {
     const current = data || {}
     const family = current.family || (extra && extra.mode) || EVENT_FAMILY.WARNING
@@ -1207,14 +1226,16 @@ export function eventAnalysisPanel(data, section, extra) {
     // 报警族的「按事件类型」改由事件行的 `eventName` 归类(后端对该族恒回未知桶);
     // 预警族仍用后端 EVENT_TYPE 桶(那套 `WARN-xxx` 码对预警是准的)。
     const alarmTypes = alarmEventTypeRows(current, family, extra)
-    const rawTypeRows = alarmTypes || current.types || []
+    const historyTypes = family === EVENT_FAMILY.WARNING ? historyEventTypeRows(extra && extra.historyEvents) : null
+    const rawTypeRows = historyTypes || alarmTypes || current.types || []
     const historyFilter = extra && extra.historyTypeFilter && typeof extra.historyTypeFilter === 'object'
         ? extra.historyTypeFilter : {}
     const historyTypeCode = typeof historyFilter.code === 'string' ? historyFilter.code.trim() : ''
-    // 预警族的类型排行可点:点击把类型写入历史分析的本地筛选;报警族没有预警类型码,不做假筛选。
-    const typeRows = family === EVENT_FAMILY.WARNING
-        ? rawTypeRows.map((row) => ({ ...row, selected: Boolean(historyTypeCode && row.code === historyTypeCode) }))
-        : rawTypeRows
+    // 两族的类型排行都可点:点击把类型写入历史分析的本地筛选。
+    const typeRows = rawTypeRows.map((row) => ({
+        ...row,
+        selected: Boolean(historyTypeCode && row.code === historyTypeCode),
+    }))
     return sectionView('eventAnalysis', section, [
         // 2026-10-13 维护者反馈:条形图四连排视觉疲劳——类别少的构成改环形图(行业=行业色、
         // 类型=图表色序),等级/片区保留条形(条形适合作排名比较)。行业行保留联动。
@@ -1223,7 +1244,7 @@ export function eventAnalysisPanel(data, section, extra) {
         // 维护者第 15 轮:类型是**多类别**,排行(由大到小)比环图更读得清;成因改堆叠条。
         rankingBarsBlock('按事件类型', sortByCountDesc(typeRows, (row) => row.count), {
             limit: 0,
-            action: family === EVENT_FAMILY.WARNING ? 'historyType' : '',
+            action: 'historyType',
             variant: 'rank',
             unit: '起',
             // 报警族的类别来自事件名称(后端对该族的 EVENT_TYPE 恒为未知桶),如实标注。

+ 7 - 5
src/modules/cockpit/stores/eventStore.js

@@ -172,7 +172,7 @@ export const useEventStore = defineStore('eventStore', () => {
      */
     const warningTypeFilter = ref({ code: '', label: '' })
     /** 历史分析的类型筛选:与当前列表分开,避免把历史类型筛进当前列表。 */
-    const historyTypeFilter = ref({ code: '', label: '' })
+    const historyTypeFilter = ref({ code: '', label: '', family: '' })
 
     /** 当前事件分区(`/events/current` 的整体响应;成败由内部事件分区状态表达)。 */
     const sections = shallowRef(initialSections())
@@ -386,14 +386,16 @@ export const useEventStore = defineStore('eventStore', () => {
         return warningTypeFilter.value
     }
 
-    function setHistoryTypeFilter(code, label = '') {
+    function setHistoryTypeFilter(code, label = '', family = '') {
         const next = typeof code === 'string' ? code.trim() : ''
-        historyTypeFilter.value = next ? { code: next, label: label || next } : { code: '', label: '' }
+        historyTypeFilter.value = next
+            ? { code: next, label: label || next, family: String(family || '').toUpperCase() }
+            : { code: '', label: '', family: '' }
         return historyTypeFilter.value
     }
 
     function clearHistoryTypeFilter() {
-        historyTypeFilter.value = { code: '', label: '' }
+        historyTypeFilter.value = { code: '', label: '', family: '' }
         return historyTypeFilter.value
     }
 
@@ -746,7 +748,7 @@ export const useEventStore = defineStore('eventStore', () => {
         currentDomain.value = null
         range.value = '7d'
         warningTypeFilter.value = { code: '', label: '' }
-        historyTypeFilter.value = { code: '', label: '' }
+        historyTypeFilter.value = { code: '', label: '', family: '' }
         currentPage.value = 1
         historyPage.value = 1
         // 票 71:效率列表的页码与钉住的条件一并回零(reset 是「回到未加载状态」,

+ 28 - 0
tests/warningTypeFilter.test.js

@@ -31,3 +31,31 @@ test('预警分析类型排行可写入历史筛选并显示选中态', () => {
     assert.equal(block.action, 'historyType')
     assert.equal(block.rows[0].selected, true)
 })
+
+test('报警历史按事件名称筛选', () => {
+    const view = historyAnalysisPanel(
+        { mode: 'ALARM', events: [
+            { name: '设备离线', eventCode: 'BJ1', status: 'HANDLED' },
+            { name: '井盖倾斜', eventCode: 'BJ2', status: 'HANDLED' },
+        ], trend: [], paging: null },
+        { state: 'SUCCESS' },
+        { historyTypeFilter: { code: '设备离线', label: '设备离线', family: 'ALARM' } },
+    )
+    const list = view.blocks.find((block) => block.label === '历史事件')
+    assert.equal(list.rows.length, 1)
+    assert.ok(list.rows[0].summaryText.includes('设备离线') || list.rows[0].title.includes('设备离线'))
+})
+
+test('预警分析类型计数使用已加载历史行,而不是滞后的后端类型桶', () => {
+    const historyEvents = [
+        { type: 'WARN-PRESSURE' }, { type: 'WARN-PRESSURE' },
+        { type: 'WARN-PRESSURE' }, { type: 'WARN-PRESSURE' },
+    ]
+    const view = eventAnalysisPanel(
+        { family: 'WARNING', types: [{ code: 'WARN-PRESSURE', label: '压力预警', count: 2 }] },
+        { state: 'SUCCESS' },
+        { mode: 'WARNING', historyEvents },
+    )
+    const block = view.blocks.find((item) => item.label === '按事件类型')
+    assert.equal(block.rows.find((row) => row.key === 'WARN-PRESSURE').count, 4)
+})