瀏覽代碼

feat(cockpit): 预警类型排行筛选落到历史分析

ChenJZ 21 小時之前
父節點
當前提交
f897723d52

+ 67 - 10
src/modules/cockpit/CockpitShell.vue

@@ -377,7 +377,15 @@
                 -->
                 <PipeColorLegend :counts="pipeColorCountsView" />
                 <!-- 实体详情只占中央一张图;按来源栏靠近对应侧边,绝不覆盖侧栏。 -->
-                <EntityDetailDrawer v-if="!introVisible && !facilityDetailOpen" :side="entityDetailSide" @locate-device="locateDeviceFromDetail" @focus-network="focusNetworkFromDetail" @open-work-order="openWorkOrderFromDetail" @open-relation="openRelationFromDetail" />
+                <EntityDetailDrawer
+                    v-if="!introVisible && !facilityDetailOpen"
+                    :side="entityDetailSide"
+                    :underground-ready="undergroundReadyForDetail"
+                    @locate-device="locateDeviceFromDetail"
+                    @focus-network="focusNetworkFromDetail"
+                    @open-work-order="openWorkOrderFromDetail"
+                    @open-underground="openUndergroundFromDetail"
+                />
             </section>
 
             <PipeEnhancement
@@ -1069,10 +1077,13 @@ async function openWorkOrderFromDetail(workOrderCode) {
     if (!workOrderCode) return false
     if (facilityDetailOpen.value) entityDetailStore.close()
     const orderId = await resolveWorkOrderId(workOrderCode)
+    // 记住来源详情:工单卡点 × 时退回刚才那张隐患/风险详情,而不是一路关掉。
+    const back = entityDetailStore.identity ? { ...entityDetailStore.identity } : null
     // 反查不到(工单被删或超出列表范围)时仍按编号打开,由卡片如实说「详情暂未取到」。
     return entityDetailStore.show(
         { kind: 'work-order', id: orderId || workOrderCode },
         orderId ? { orderId } : {},
+        back ? { returnTo: back } : {},
     )
 }
 
@@ -1147,7 +1158,8 @@ async function focusNetworkFromDetail(networkCode) {
     // 打开卡片与飞行并行:卡片一打开,设施图标就由 facilityPointStore 的选中点派生出来。
     const [located] = await Promise.all([
         pointLocateStore.focusFacilityPoint(identity, { network: pipeNetworkStore.layer.data }),
-        entityDetailStore.show(identity, networkPrefill(networkCode)),
+        // 管网在基础设施详情端点里没有资源(实测 404),直接跳过远端请求,卡片用 prefill 就够。
+        entityDetailStore.show(identity, networkPrefill(networkCode), { skipRemote: true }),
     ])
     return located
 }
@@ -1237,23 +1249,33 @@ function handlePanelAction(action) {
         return true
     }
     if (action.kind === 'warningType') return focusWarningType(action.key)
+    if (action.kind === 'historyType') return focusHistoryType(action.key)
     return false
 }
 
 /**
- * 预警类型排行 → 切「预警处置」模式的当前预警列表,并按该类型**本地**筛选(票 07 · G11)。
- *
- * 三步都必须真实发生:切模式(否则用户看不到列表)、切到预警族(排行是预警类型)、
- * 写本地筛选状态(不伪造服务端参数)。列表覆盖范围由 `eventStore.view.filterView` 如实回显。
- * @param {string} code warning_type 码(排行行的 `actionKey`)
- * @returns {boolean} 是否真的切了
+ * 概览「预警类型排行」是**近 30 日发生量**,点击落点是预警处置的**历史分析**类型筛选,
+ * 不是当前预警(已处理/已解除的类型在当前列表本来就看不到)。
  */
 function focusWarningType(code) {
     const key = typeof code === 'string' ? code.trim() : ''
     if (!key) return false
     uiStore.setMode('warningResponse')
-    if (eventStore.mode !== EVENT_FAMILY.WARNING) eventStore.setMode(EVENT_FAMILY.WARNING)
-    eventStore.setWarningTypeFilter(key, warningTypeLabel(key))
+    eventStore.clearWarningTypeFilter()
+    eventStore.setHistoryTypeFilter(key, warningTypeLabel(key))
+    void eventStore.loadPanels({ mode: EVENT_FAMILY.WARNING, range: '30d' })
+    return true
+}
+
+/** 预警分析「按事件类型」排行 → 同一条历史分析类型筛选;再点一次取消。 */
+function focusHistoryType(code) {
+    const key = typeof code === 'string' ? code.trim() : ''
+    if (!key) return false
+    if (eventStore.historyTypeFilter && eventStore.historyTypeFilter.code === key) {
+        eventStore.clearHistoryTypeFilter()
+        return true
+    }
+    eventStore.setHistoryTypeFilter(key, warningTypeLabel(key))
     return true
 }
 
@@ -1511,6 +1533,13 @@ const facilityUndergroundReady = computed(() => Boolean(
     facilityDetailOpen.value && facilityUndergroundTarget(currentFacilityRow.value),
 ))
 
+/** 实体详情抽屉里的地下设施能否进「地下管线详情视图」:管网一定能(按管段编码选中),窨井沿用设施判定。 */
+const undergroundReadyForDetail = computed(() => {
+    const category = entityDetailStore.identity && entityDetailStore.identity.category
+    if (category === 'PIPE_NETWORK') return true
+    return category === 'MANHOLE' && facilityUndergroundReady.value
+})
+
 
 /**
  * 设备→设施真实关联索引(维护者 2026-10-22 批准的后端契约)。
@@ -1591,6 +1620,34 @@ const pipeColorCountsView = computed(() => pipeColorCounts(pipeNetworkStore.laye
  */
 
 /** 「查看详情」:选中关联管段,既有三维视图随之打开(不新建第二条渲染链)。 */
+/**
+ * 详情卡里的「查看详情 →」:进「地下管线详情视图」。
+ *
+ * 管网没有设施点行(走的是实体详情抽屉),所以直接按管段编码选中三维视图;
+ * 其它地下设施仍走原有判定(要有可渲染的 3D 模型与坐标)。
+ */
+function openUndergroundFromDetail() {
+    const identity = entityDetailStore.identity
+    if (identity && identity.category === 'PIPE_NETWORK' && identity.id) {
+        return pipeEnhancementStore.select(PIPE_ENHANCEMENT_KIND.PIPE, identity.id)
+    }
+    openFacilityUnderground()
+}
+
+/**
+ * 详情卡里的「查看详情 →」:进「地下管线详情视图」。
+ *
+ * 管网没有设施点行(走的是实体详情抽屉),所以直接按管段编码选中三维视图;
+ * 其它地下设施仍走原有判定(要有可渲染的 3D 模型与坐标)。
+ */
+function openUndergroundFromDetail() {
+    const identity = entityDetailStore.identity
+    if (identity && identity.category === 'PIPE_NETWORK' && identity.id) {
+        return pipeEnhancementStore.select(PIPE_ENHANCEMENT_KIND.PIPE, identity.id)
+    }
+    openFacilityUnderground()
+}
+
 function openFacilityUnderground() {
     const target = facilityUndergroundTarget(currentFacilityRow.value)
     if (!target) return

+ 69 - 1
src/modules/cockpit/components/WarningResponsePane.vue

@@ -31,7 +31,13 @@
             {{ rangeLabel }} · {{ eventStore.loading ? '正在更新…' : '当前统计窗口' }}
         </p>
         <p v-if="!eventStore.loading && section && section.reason && /历史接口回显/.test(section.reason)" class="warning-response-pane__range-status" role="alert">{{ section.reason }}</p>
-        <PanelBlocks v-if="view" :key="`${panelId}-${eventStore.mode}-${eventStore.range}`" :class="{ 'is-updating': eventStore.loading }" :view="view" @list-page="onListPage" @card-action="onCardAction" />
+        <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>
+            <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" />
     </div>
 </template>
 
@@ -54,6 +60,7 @@ const modeOptions = eventListSwitchOptions()
 const rangeOptions = EVENT_RANGES
 const rangeLabel = computed(() => EVENT_RANGES.find((item) => item.key === eventStore.range)?.label || '')
 const section = computed(() => eventStore.sections[props.panelId])
+const historyFilter = computed(() => eventStore.historyTypeFilter || { code: '', label: '' })
 const view = computed(() => {
     const current = section.value || { state: 'empty', loaded: false, data: null }
     // 票 65:把当前切换族交给 domain —— 预警效率面板要按族分流(预警不挂工单)。
@@ -70,6 +77,7 @@ const view = computed(() => {
         mode: eventStore.mode,
         workOrderList: eventStore.sections.workOrderList,
         historyEvents,
+        historyTypeFilter: eventStore.historyTypeFilter,
     })
 })
 
@@ -138,6 +146,26 @@ function onListPage(payload) {
 }
 
 /** 历史事件与工单按显式身份分流,禁止把事件卡误开成工单。 */
+function clearHistoryFilter() {
+    eventStore.clearHistoryTypeFilter()
+}
+
+/** 预警分析「按事件类型」排行:写下历史筛选;再点同一类取消。 */
+function onPanelAction(action) {
+    if (!action || action.kind !== 'historyType') return false
+    const code = typeof action.key === 'string' ? action.key.trim() : ''
+    if (!code) return false
+    if (eventStore.historyTypeFilter && eventStore.historyTypeFilter.code === code) {
+        eventStore.clearHistoryTypeFilter()
+        return true
+    }
+    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)
+    return true
+}
+
 function onCardAction(action) {
     const row = (action && action.row) || {}
     // 工单卡的路由身份是后端 orderId(票 129);事件仍用业务编码。
@@ -216,6 +244,46 @@ function refreshAfterOpen(opened) {
     color: var(--text-2);
     font-size: var(--fs-caption);
 }
+
+/* 类型筛选提示:做成一条有层次的筛选胶囊,不用裸文本把信息硬怼在列表上。 */
+.warning-response-pane__filter {
+    display: flex;
+    flex-wrap: wrap;
+    align-items: center;
+    gap: 6px;
+    padding: 6px 9px;
+    border: 1px solid rgba(1, 171, 234, .34);
+    border-left: 2px solid var(--cyan-hi, #35d8ff);
+    border-radius: 7px;
+    background: linear-gradient(90deg, rgba(0, 82, 168, .34), rgba(0, 20, 72, .26));
+    font-size: var(--fs-caption, 10.5px);
+}
+.warning-response-pane__filter-kicker {
+    padding: 0 5px;
+    border: 1px solid rgba(53, 216, 255, .45);
+    border-radius: 8px;
+    color: var(--cyan-hi, #35d8ff);
+    font-size: calc(9.5 * var(--u, 1px));
+    letter-spacing: .06em;
+}
+.warning-response-pane__filter-name { color: var(--text-strong, #eaf6ff); font-size: calc(11.5 * var(--u, 1px)); }
+.warning-response-pane__filter-scope { color: var(--muted, #5680b0); }
+.warning-response-pane__filter-clear {
+    margin-left: auto;
+    padding: 1px 7px;
+    border: 1px solid rgba(1, 171, 234, .45);
+    border-radius: 8px;
+    background: rgba(0, 20, 72, .5);
+    color: var(--cyan-hi, #35d8ff);
+    font: inherit;
+    font-size: calc(10 * var(--u, 1px));
+    cursor: pointer;
+}
+.warning-response-pane__filter-clear:hover,
+.warning-response-pane__filter-clear:focus-visible {
+    border-color: var(--cyan-hi, #00b8ff);
+    color: var(--text-strong, #eaf6ff);
+}
 /* 刷新时保留列表 DOM 与滚动位置,只做弱提示;不能因 v-if 卸载把用户正在看的卡片滚回顶部。 */
 .warning-response-pane [data-panel-blocks].is-updating {
     transition: opacity .15s;

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

@@ -676,7 +676,7 @@ export function warningStudyPanel(data, section) {
     const ranking = current.typeRanking || {}
     // 排行标题按设计稿拆成两段:块标题「预警类型排行」+ 右上角小字「近30日 · 共XX起 · 点击筛选」。
     // 小字整句仍是需求原文的锁定文案(拆位置不拆字),闸门按整句断言。
-    const rankingAside = `近30日 · 共${valueText(ranking.total)}起 · 点击筛选`
+    const rankingAside = `近30日发生 · 共${valueText(ranking.total)}起 · 点击筛选`
     const blocks = [
         kpiBlock([
             // 差值:正红负绿(规格 §6.6),块构造器按 `delta` 自动补文案与色调。

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

@@ -460,9 +460,8 @@ export function eventCardRows(events, family) {
     })
 }
 
-function historyEventListBlock(current) {
+function historyEventListBlock(current, emptyText = '当前时间范围没有历史事件') {
     const rows = eventCardRows(current.events, String(current.mode || '').toUpperCase())
-    const emptyText = '当前时间范围没有历史事件'
     const paging = current.paging && typeof current.paging === 'object' ? current.paging : null
     if (!paging) return listBlock('历史事件', rows, emptyText)
     if (paging.mode === 'server') {
@@ -479,25 +478,32 @@ function historyEventListBlock(current) {
     })
 }
 
-export function historyAnalysisPanel(data, section) {
+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 allEvents = Array.isArray(current.events) ? current.events : []
+    const events = filterCode ? allEvents.filter((item) => item && item.type === filterCode) : allEvents
+    const filtered = filterCode ? { ...current, events } : current
     const levelCounts = [1, 2, 3, 4].map((level) => ({
         code: String(level),
         label: `${level}级`,
-        count: (current.events || []).filter((item) => Number(item.level) === level).length,
+        count: events.filter((item) => Number(item.level) === level).length,
     }))
     return sectionView('historyAnalysis', section, [
         // 2026-10-13 图表选型:时间趋势用折线。
         trendBlock((current.trend || []).length > 48 ? '历史事件趋势 · 每日合计' : '历史事件趋势', historyTrendRows(current.trend || []), { chart: 'line', compact: true }),
         // 维护者 2026-10-29:小字说明进面板摘要(标题栏的 ?),块标题保持短,不被省略号切掉。
         supplementalBlock(donutBlock('已加载事件等级分布', levelCounts, { layout: 'compact' })),
-        historyEventListBlock(current),
+        historyEventListBlock(filtered, filterCode ? '当前时间范围没有该类型的历史事件' : '当前时间范围没有历史事件'),
     ], {
         label: '历史分析',
         range: current.range,
         rangeNote: current.range && current.range.start ? `时间范围:${current.range.start} 至 ${current.range.end}` : '',
         // 已加载集合的口径(原块右上角小字,搬到摘要里,避免把块标题挤成省略号)。
-        note: '等级分布只统计当前已加载的事件集合,不代表整个统计窗口',
+        note: filterCode
+            ? `列表按类型「${filter.label || filterCode}」本地筛选;等级分布只统计筛选后的已加载事件`
+            : '等级分布只统计当前已加载的事件集合,不代表整个统计窗口',
     })
 }
 
@@ -1201,7 +1207,14 @@ export function eventAnalysisPanel(data, section, extra) {
     // 报警族的「按事件类型」改由事件行的 `eventName` 归类(后端对该族恒回未知桶);
     // 预警族仍用后端 EVENT_TYPE 桶(那套 `WARN-xxx` 码对预警是准的)。
     const alarmTypes = alarmEventTypeRows(current, family, extra)
-    const typeRows = alarmTypes || current.types || []
+    const rawTypeRows = 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
     return sectionView('eventAnalysis', section, [
         // 2026-10-13 维护者反馈:条形图四连排视觉疲劳——类别少的构成改环形图(行业=行业色、
         // 类型=图表色序),等级/片区保留条形(条形适合作排名比较)。行业行保留联动。
@@ -1210,6 +1223,7 @@ export function eventAnalysisPanel(data, section, extra) {
         // 维护者第 15 轮:类型是**多类别**,排行(由大到小)比环图更读得清;成因改堆叠条。
         rankingBarsBlock('按事件类型', sortByCountDesc(typeRows, (row) => row.count), {
             limit: 0,
+            action: family === EVENT_FAMILY.WARNING ? 'historyType' : '',
             variant: 'rank',
             unit: '起',
             // 报警族的类别来自事件名称(后端对该族的 EVENT_TYPE 恒为未知桶),如实标注。

+ 18 - 0
src/modules/cockpit/stores/eventStore.js

@@ -134,6 +134,8 @@ export const useEventStore = defineStore('eventStore', () => {
      * 切族/重置时清空:类型码是预警族的词汇,挂到报警列表上只会在另一个族里静默漏筛。
      */
     const warningTypeFilter = ref({ code: '', label: '' })
+    /** 历史分析的类型筛选:与当前列表分开,避免把历史类型筛进当前列表。 */
+    const historyTypeFilter = ref({ code: '', label: '' })
 
     /** 当前事件分区(`/events/current` 的整体响应;成败由内部事件分区状态表达)。 */
     const sections = shallowRef(initialSections())
@@ -347,6 +349,17 @@ export const useEventStore = defineStore('eventStore', () => {
         return warningTypeFilter.value
     }
 
+    function setHistoryTypeFilter(code, label = '') {
+        const next = typeof code === 'string' ? code.trim() : ''
+        historyTypeFilter.value = next ? { code: next, label: label || next } : { code: '', label: '' }
+        return historyTypeFilter.value
+    }
+
+    function clearHistoryTypeFilter() {
+        historyTypeFilter.value = { code: '', label: '' }
+        return historyTypeFilter.value
+    }
+
     /**
      * 取预警处置四块面板。切换 mode/range/筛选时四块共享一次条件,迟到响应整批丢弃;
      * 条件变化同时把两个服务端页码回第 1 页(**定时刷新不带条件 ⇒ 页码保持**)。
@@ -683,6 +696,7 @@ export const useEventStore = defineStore('eventStore', () => {
         if (!isKnownEventMode(next) || next === mode.value) return sections.value.currentEvents
         // 类型筛选是预警族的词汇,切族即失效(避免报警列表被一条预警类型静默筛空)。
         clearWarningTypeFilter()
+        clearHistoryTypeFilter()
         return loadPanels({ mode: next })
     }
 
@@ -694,6 +708,7 @@ export const useEventStore = defineStore('eventStore', () => {
         currentDomain.value = null
         range.value = '7d'
         warningTypeFilter.value = { code: '', label: '' }
+        historyTypeFilter.value = { code: '', label: '' }
         currentPage.value = 1
         historyPage.value = 1
         // 票 71:效率列表的页码与钉住的条件一并回零(reset 是「回到未加载状态」,
@@ -737,6 +752,9 @@ export const useEventStore = defineStore('eventStore', () => {
         warningTypeFilter,
         setWarningTypeFilter,
         clearWarningTypeFilter,
+        historyTypeFilter,
+        setHistoryTypeFilter,
+        clearHistoryTypeFilter,
         reset,
     }
 })

+ 33 - 0
tests/warningTypeFilter.test.js

@@ -0,0 +1,33 @@
+/** 概览/预警分析的类型筛选落在历史分析,不筛当前预警。 */
+import assert from 'node:assert/strict'
+import { test } from 'node:test'
+
+import { eventAnalysisPanel, historyAnalysisPanel } from '../src/modules/cockpit/domain/warningResponsePanels.js'
+
+const events = [
+    { eventNo: 'YJ1', eventCode: 'YJ1', eventName: '氨氮预警', type: 'WARN-AMMONIA-NITROGEN', status: 'CLOSED', level: 1 },
+    { eventNo: 'YJ2', eventCode: 'YJ2', eventName: 'PH预警', type: 'WARN-PH', status: 'CLOSED', level: 2 },
+]
+
+test('历史分析按类型本地筛选事件列表', () => {
+    const view = historyAnalysisPanel(
+        { mode: 'WARNING', events, trend: [], paging: null },
+        { state: 'SUCCESS' },
+        { historyTypeFilter: { code: 'WARN-AMMONIA-NITROGEN', label: '氨氮监测' } },
+    )
+    const list = view.blocks.find((block) => block.label === '历史事件')
+    assert.ok(list)
+    assert.equal(list.rows.length, 1)
+    assert.equal(list.rows[0].summaryText, '氨氮预警')
+})
+
+test('预警分析类型排行可写入历史筛选并显示选中态', () => {
+    const view = eventAnalysisPanel(
+        { family: 'WARNING', types: [{ code: 'WARN-AMMONIA-NITROGEN', label: '氨氮监测', count: 1 }] },
+        { state: 'SUCCESS' },
+        { mode: 'WARNING', historyTypeFilter: { code: 'WARN-AMMONIA-NITROGEN', label: '氨氮监测' } },
+    )
+    const block = view.blocks.find((item) => item.label === '按事件类型')
+    assert.equal(block.action, 'historyType')
+    assert.equal(block.rows[0].selected, true)
+})