Browse Source

fix(cockpit): 聚合徽章补全类型/状态信息与聚合级特效

按规格 69-72 与票面复核:未关联设备聚合改用设备原生五态(报警>工单处置>预警>正常>离线>未发布,修正此前误用点位六态导致的工单/预警优先级倒置)。徽章常驻准确成员数与类别,左上角同质行业类型图案(混合用通用标记),右上角最高优先级异常及数量、其余异常 +N 种状态;每组只挂一套与最高异常一致的聚合级特效(pulse/spin/blink),title 汇总类型与状态分布;成员列表补类型/状态中文词与类型+状态摘要,成员行显示 名称·编码·类型·状态。
ChenJZ 2 ngày trước cách đây
mục cha
commit
ca0d832835

+ 88 - 16
src/modules/cockpit/domain/pointAggregation.js

@@ -12,7 +12,10 @@
  *
  * 屏幕距离用网格划分 + 并查集,平均 O(n),避免两两比较(密集点位下 O(n^2) 会拖慢每帧)。
  */
-import { unassociatedVisualFor } from './pointStatus.js'
+// 未关联设备的“原生状态”是设备五态(不是点位六态):色/词/优先级都走设备表,
+// 否则工单处置与预警的先后会被点位表带反(设备规则:报警 > 工单处置 > 预警)。
+import { deviceVisualForStatus } from './deviceStatus.js'
+import { industryLabel } from './filterOptions.js'
 
 /** 聚合符号的 kind(只用于显示/拾取身份,不是业务对象,也不是设备编码)。 */
 export const AGGREGATE_KIND = 'unassociated-equipment-aggregate'
@@ -40,9 +43,9 @@ function isCandidate(item) {
         && Number.isFinite(item.screen.y)
 }
 
-/** 未关联设备的状态优先级:沿用既有视觉词表(报警/预警/工单处置/在线/离线/状态未发布)。 */
+/** 未关联设备的状态优先级:设备五态(报警 > 工单处置 > 预警 > 正常 > 离线 > 未发布)。 */
 export function statusPriority(status) {
-    const visual = unassociatedVisualFor(status || '')
+    const visual = deviceVisualForStatus(status || '')
     return Number.isFinite(visual.priority) ? visual.priority : 999
 }
 
@@ -52,15 +55,27 @@ function statusSummaryOf(members) {
         const key = member.status || 'UNKNOWN'
         counts[key] = (counts[key] || 0) + 1
     }
-    let primary = null
-    for (const status of Object.keys(counts)) {
-        const priority = statusPriority(status)
-        if (!primary || priority < primary.priority) {
-            const visual = unassociatedVisualFor(status)
-            primary = { status, count: counts[status], priority, tone: visual.tone, label: visual.label }
+    const statuses = Object.keys(counts).map((status) => {
+        const visual = deviceVisualForStatus(status)
+        return {
+            status,
+            count: counts[status],
+            priority: Number.isFinite(visual.priority) ? visual.priority : 999,
+            tone: visual.tone,
+            label: visual.label,
+            effect: visual.effect || '',
         }
+    }).sort((a, b) => a.priority - b.priority || String(a.status).localeCompare(String(b.status)))
+    const primary = statuses[0] || null
+    // 「异常」= 设备表里带动效的三态(报警/工单处置/预警);角标取最高优先级异常,其余用 +N 种状态。
+    const abnormal = statuses.filter((item) => item.effect !== '')
+    return {
+        counts,
+        statuses,
+        primary,
+        primaryAbnormal: abnormal[0] || null,
+        otherAbnormalCount: Math.max(0, abnormal.length - 1),
     }
-    return { counts, primary }
 }
 
 function screenBounds(members) {
@@ -103,7 +118,17 @@ function buildGroup(rawMembers) {
     const screenBox = screenBounds(members)
     const boundsWorld = worldBounds(members)
     const codes = members.map((item) => String(item.code || ''))
-    const industries = new Set(members.map((item) => item.industry || ''))
+    // 类型维度:未关联设备的“类型”就是它的行业(燃气/供水/排水/窨井);同质用该类型图案,
+    // 混合则用通用图案(规格:不得长期显示过期类别语义)。
+    const industryCounts = new Map()
+    for (const member of members) {
+        const key = member.industry || ''
+        industryCounts.set(key, (industryCounts.get(key) || 0) + 1)
+    }
+    const industrySummary = [...industryCounts.entries()]
+        .map(([key, count]) => ({ key, count, label: industryLabel(key) || (key || '未标注') }))
+        .sort((a, b) => b.count - a.count || a.key.localeCompare(b.key))
+    const mixedIndustry = industrySummary.length > 1
     return {
         kind: AGGREGATE_KIND,
         // 组身份 = 成员编码集合(成员不变则稳定,相机微移不抖)。
@@ -120,7 +145,10 @@ function buildGroup(rawMembers) {
         boundsWorld,
         spreadPx: Math.hypot(screenBox.maxX - screenBox.minX, screenBox.maxY - screenBox.minY),
         statusSummary: statusSummaryOf(members),
-        mixedIndustry: industries.size > 1,
+        industrySummary,
+        mixedIndustry,
+        primaryIndustry: industrySummary.length ? industrySummary[0].key : '',
+        typeLabel: mixedIndustry ? '混合' : (industrySummary.length ? industrySummary[0].label : '设备'),
         category: '独立设备',
     }
 }
@@ -185,10 +213,24 @@ export function groupUnassociatedByScreen(items, { minSeparationPx = DEFAULT_MIN
     return { groups, selected: selectedRow }
 }
 
-/** 聚合徽章的可显示描述(数量 + 类别;风险摘要的细节归后续票)。 */
+/**
+ * 聚合徽章的可显示描述(规格 69–72)。
+ *
+ * 徽章必须常驻:类别、准确成员数、**最高优先级异常及数量**、其余异常的 +N 种状态提示;
+ * 同质单一行业用该类型图案、混合用通用图案;每组最多一套与最高优先级异常一致的特效。
+ * 文本/类型摘要同时写进 tooltip,悬停即可读到「聚合了哪些类型、各是什么状态」。
+ */
 export function aggregateBadge(group) {
     if (!group || group.count < 2) return null
-    const primary = group.statusSummary && group.statusSummary.primary
+    const summary = group.statusSummary || {}
+    const primary = summary.primary || null
+    const abnormal = summary.primaryAbnormal || null
+    const statuses = summary.statuses || []
+    const statusText = statuses.map((item) => item.label + ' ' + item.count).join(' / ')
+    const typeText = (group.industrySummary || []).map((item) => item.label + ' ' + item.count).join(' / ')
+    const highestText = abnormal
+        ? abnormal.label + ' ' + abnormal.count
+        : (primary ? primary.label + ' ' + primary.count : '无')
     return {
         kind: AGGREGATE_KIND,
         code: group.groupKey,
@@ -196,8 +238,28 @@ export function aggregateBadge(group) {
         count: group.count,
         category: group.category || '独立设备',
         label: group.count + ' 台独立设备',
-        tone: primary ? primary.tone : 'point-unassociated',
+        // 圆形徽章的描边/角标色:取本组最高优先级状态(异常优先),与成员状态词表同源。
+        tone: abnormal ? abnormal.tone : (primary ? primary.tone : 'point-unassociated'),
         primaryStatus: primary ? primary.status : '',
+        primaryLabel: primary ? primary.label : '',
+        // 角标:最高优先级异常及数量;otherAbnormalCount = 其余异常**状态种数**(+N 种)。
+        abnormal,
+        otherAbnormalCount: summary.otherAbnormalCount || 0,
+        // 特效:与最高优先级异常一致;无异常不挂特效。每组最多一套(由徽章节点承载,不叠加成员环)。
+        effectStatus: abnormal ? abnormal.status : '',
+        effect: abnormal ? abnormal.effect : '',
+        // 类型:同质给具体行业(图案),混合给通用(typeLabel=混合、industryKey 为空)。
+        mixedIndustry: Boolean(group.mixedIndustry),
+        typeLabel: group.typeLabel || (group.mixedIndustry ? '混合' : '设备'),
+        industryKey: group.mixedIndustry ? '' : (group.primaryIndustry || ''),
+        types: group.industrySummary || [],
+        statuses,
+        tooltip: [
+            group.count + ' 台独立设备',
+            '类型:' + (typeText || '未标注'),
+            '状态:' + (statusText || '状态未发布'),
+            '最高优先级:' + highestText,
+        ].join('\n'),
     }
 }
 
@@ -228,7 +290,17 @@ export function planMemberList(group, { query = '', sort = 'risk' } = {}) {
     const filtered = q
         ? members.filter((item) => String(item.name || '').toLowerCase().includes(q) || String(item.code || '').toLowerCase().includes(q))
         : members
-    return sortRows(filtered, sort)
+    // 成员表要能回答「有哪些设备、什么类型、什么状态」:逐行补原生状态与类型的中文词。
+    const rows = filtered.map((item) => {
+        const visual = deviceVisualForStatus(item.status || '')
+        return {
+            ...item,
+            statusLabel: visual.label,
+            statusTone: visual.tone,
+            industryLabel: industryLabel(item.industry) || (item.industry || '未标注'),
+        }
+    })
+    return sortRows(rows, sort)
 }
 
 /**

+ 101 - 17
src/modules/cockpit/services/markerOverlay.js

@@ -47,7 +47,7 @@ import {
     ringScaleAt,
 } from '../domain/markerMetrics.js'
 // 票 83:几何读数(本体宽 / 绘制宽 / pad)与计划读数同一出口,走查不读 DOM 内部结构。
-import { markerGeometryDataset } from '../domain/markerPlan.js'
+import { markerGeometryDataset, innerIconFor } from '../domain/markerPlan.js'
 // 本票:未关联设备的屏幕拥挤聚合(纯 domain;本层只负责投影/渲染/点击)。
 import { AGGREGATE_KIND, aggregateBadge, canZoomAggregate, groupUnassociatedByScreen, planMemberList } from '../domain/pointAggregation.js'
 
@@ -906,30 +906,99 @@ export function markerLabelState(hovered) {
 
 // ---- 本票:未关联设备聚合徽章与成员列表 ----
 
-function buildUnassociatedAggregateNode(key, badge) {
+function badgeFingerprint(badge) {
+    const statusFp = (badge.statuses || []).map((item) => item.status + ':' + item.count).join(',')
+    const typeFp = (badge.types || []).map((item) => item.key + ':' + item.count).join(',')
+    return [
+        badge.count,
+        badge.primaryStatus,
+        badge.abnormal ? badge.abnormal.status : '',
+        badge.abnormal ? badge.abnormal.count : 0,
+        badge.otherAbnormalCount,
+        badge.mixedIndustry ? '1' : '0',
+        badge.industryKey,
+        badge.effect,
+        badge.tone,
+        statusFp,
+        typeFp,
+    ].join(FP_SEP)
+}
+
+/**
+ * 聚合徽章节点(规格 69–72):圆形 40px,常驻「类别 + 准确成员数」,
+ * 左上角是类型图案(同质单一行业)/通用“混”,右上角是最高优先级异常及数量(+N 种),
+ * 外圈按最高优先级异常挂**唯一一套**聚合级特效,title 汇总类型与状态分布。
+ */
+function buildUnassociatedAggregateNode(key, badge, tones) {
+    const palette = tones || {}
+    const toneHex = palette[badge.tone] || palette.neutral || '#01abea'
+
     const root = document.createElement('div')
     root.className = NODE_CLASS + ' ' + NODE_CLASS + '--aggregate'
     root.dataset.markerOverlayKey = key
     root.dataset.markerOverlayKind = AGGREGATE_KIND
     root.dataset.markerOverlayCode = key
     root.dataset.markerOverlayAggregate = 'yes'
-    root.dataset.aggregateCount = String(badge.count)
-    root.dataset.aggregateCategory = badge.category
-    root.style.cssText = 'position:absolute;left:0;top:0;pointer-events:auto;cursor:pointer;transform-origin:50% 50%;display:flex;flex-direction:column;align-items:center;gap:2px;'
+    root.style.cssText = 'position:absolute;left:0;top:0;width:40px;height:40px;pointer-events:auto;cursor:pointer;transform-origin:50% 50%;'
+    root.style.setProperty('--marker-tone', toneHex)
+    root.title = badge.tooltip || badge.label
+
+    // 聚合级特效:每组最多一套,与最高优先级异常一致(不叠加成员级光环)。
+    let fxHost = null
+    if (badge.effect && badge.effectStatus) {
+        const profile = effectProfileFor(badge.effectStatus)
+        if (profile && profile.effect === badge.effect) {
+            fxHost = buildFxLayers({ effect: profile.effect, profile, converge: null }, { draw: { width: 40 } }, toneHex, key)
+            root.appendChild(fxHost)
+        }
+    }
+
     const circle = document.createElement('div')
-    circle.style.cssText = 'display:flex;align-items:center;justify-content:center;width:40px;height:40px;border-radius:50%;border:2px solid #01abea;background:rgba(2,9,27,0.92);color:#e8f7ff;font:600 14px/1 monospace;box-shadow:0 0 10px rgba(1,171,234,0.55)'
+    circle.style.cssText = 'position:absolute;left:0;top:0;width:40px;height:40px;border-radius:50%;border:2px solid ' + toneHex + ';background:rgba(2,9,27,0.92);display:flex;align-items:center;justify-content:center;box-shadow:0 0 10px ' + toneHex + '66;'
     const countEl = document.createElement('span')
     countEl.textContent = String(badge.count)
+    countEl.style.cssText = 'color:#fff;font:600 15px/1 monospace;'
     circle.appendChild(countEl)
+    root.appendChild(circle)
+
+    // 类型图案:同质单一行业 → 该行业图案;混合 → 通用「混」。
+    const typeEl = document.createElement('div')
+    typeEl.style.cssText = 'position:absolute;left:-6px;top:-6px;width:18px;height:18px;border-radius:50%;background:rgba(2,9,27,0.96);border:1px solid rgba(1,171,234,0.55);display:flex;align-items:center;justify-content:center;overflow:hidden;color:#9fd8f2;font:600 10px/1 sans-serif;'
+    const iconKey = badge.industryKey ? innerIconFor(badge.industryKey) : ''
+    if (iconKey) {
+        const img = document.createElement('img')
+        img.alt = badge.typeLabel
+        img.style.cssText = 'width:14px;height:14px;display:block;'
+        renderInnerIconUrl(iconKey).then((url) => { img.src = url }).catch(() => {})
+        typeEl.appendChild(img)
+    } else {
+        typeEl.textContent = badge.mixedIndustry ? '混' : String(badge.typeLabel || '设').slice(0, 1)
+    }
+    typeEl.title = '类型:' + badge.typeLabel
+    root.appendChild(typeEl)
+
+    // 角标:最高优先级异常及数量;其余异常用 +N 种状态提示。
+    const statusEl = document.createElement('div')
+    if (badge.abnormal) {
+        statusEl.textContent = badge.abnormal.count + (badge.otherAbnormalCount > 0 ? ' +' + badge.otherAbnormalCount : '')
+        statusEl.title = badge.abnormal.label + ' ' + badge.abnormal.count
+            + (badge.otherAbnormalCount > 0 ? ' · 另有 ' + badge.otherAbnormalCount + ' 种异常状态' : '')
+        const abnormalTone = palette[badge.abnormal.tone] || toneHex
+        statusEl.style.cssText = 'position:absolute;right:-10px;top:-10px;min-width:16px;height:16px;padding:0 4px;border-radius:8px;background:' + abnormalTone + ';color:#02091b;font:700 10px/16px monospace;text-align:center;box-shadow:0 0 6px ' + abnormalTone + ';'
+    } else {
+        statusEl.style.display = 'none'
+    }
+    root.appendChild(statusEl)
+
     const label = document.createElement('span')
     label.textContent = badge.category
-    label.style.cssText = 'padding:0 4px;border-radius:3px;background:rgba(2,9,27,0.9);color:#9fd8f2;font:11px/1.4 sans-serif;white-space:nowrap'
-    root.appendChild(circle)
+    label.style.cssText = 'position:absolute;left:50%;top:42px;transform:translateX(-50%);padding:1px 5px;border-radius:3px;background:rgba(2,9,27,0.92);color:#9fd8f2;font:11px/1.4 sans-serif;white-space:nowrap;'
     root.appendChild(label)
-    return { root, countEl }
+
+    return { root, countEl, typeEl, statusEl, labelEl: label, fxHost, fp: badgeFingerprint(badge) }
 }
 
-function renderAggregates(groups) {
+function renderAggregates(groups, tones) {
     aggregateGroups.clear()
     const active = new Set()
     for (const group of groups || []) {
@@ -939,18 +1008,24 @@ function renderAggregates(groups) {
         active.add(key)
         aggregateGroups.set(key, group)
         let record = aggregatePool.get(key)
-        if (!record) {
-            record = buildUnassociatedAggregateNode(key, badge)
+        const fp = badgeFingerprint(badge)
+        if (!record || record.fp !== fp) {
+            if (record && record.root.parentNode) record.root.parentNode.removeChild(record.root)
+            record = buildUnassociatedAggregateNode(key, badge, tones)
             aggregatePool.set(key, record)
             hostNode.appendChild(record.root)
         }
         const transform = 'translate(' + group.screen.x + 'px, ' + group.screen.y + 'px) translate(-50%, -50%)'
         if (record.root.style.transform !== transform) record.root.style.transform = transform
-        if (record.root.style.display !== 'flex') record.root.style.display = 'flex'
-        // 走查读数:组成员数与屏幕离散(不参与业务)。
+        if (record.root.style.display !== 'block') record.root.style.display = 'block'
+        // 走查读数(不参与业务):数量/离散/可缩放/最高异常/+N/类型/特效。
+        record.root.dataset.aggregateCount = String(badge.count)
         record.root.dataset.aggregateSpread = String(Math.round(group.spreadPx))
         record.root.dataset.aggregateZoom = canZoomAggregate(group) ? 'yes' : 'no'
-        if (record.countEl.textContent !== String(group.count)) record.countEl.textContent = String(group.count)
+        record.root.dataset.aggregateStatus = badge.abnormal ? badge.abnormal.status : badge.primaryStatus
+        record.root.dataset.aggregateOther = String(badge.otherAbnormalCount)
+        record.root.dataset.aggregateType = badge.typeLabel
+        record.root.dataset.aggregateEffect = badge.effect
     }
     for (const [key, record] of aggregatePool.entries()) {
         if (active.has(key)) continue
@@ -986,6 +1061,13 @@ function openMemberList(group, onPick) {
     close.style.cssText = 'pointer-events:auto;background:transparent;border:1px solid rgba(1,171,234,0.5);color:#9fd8f2;border-radius:4px;padding:1px 6px;cursor:pointer;font:11px sans-serif'
     header.appendChild(title)
     header.appendChild(close)
+    // 类型与状态分布摘要:打开列表前就能看到「聚合了哪些类型、各是什么状态」。
+    const subtitle = document.createElement('div')
+    subtitle.style.cssText = 'color:#7fb8d8;font-size:11px;line-height:1.45;margin-bottom:6px;'
+    const typeText = (group.industrySummary || []).map((item) => item.label + ' ' + item.count).join(' / ')
+    const statusText = ((group.statusSummary && group.statusSummary.statuses) || []).map((item) => item.label + ' ' + item.count).join(' / ')
+    subtitle.textContent = '类型 ' + (typeText || '未标注') + ' · 状态 ' + (statusText || '状态未发布')
+    subtitle.title = subtitle.textContent
     const input = document.createElement('input')
     input.type = 'search'
     input.placeholder = '搜索名称 / 编码'
@@ -1010,7 +1092,7 @@ function openMemberList(group, onPick) {
             const name = document.createElement('span')
             name.textContent = row.name || row.code
             const meta = document.createElement('span')
-            meta.textContent = ' · ' + row.code + ' · ' + (row.status || '状态未发布')
+            meta.textContent = ' · ' + row.code + ' · ' + (row.industryLabel || '未标注') + ' · ' + (row.statusLabel || row.status || '状态未发布')
             meta.style.cssText = 'color:#7fb8d8;font-size:11px'
             button.appendChild(name)
             button.appendChild(meta)
@@ -1021,6 +1103,7 @@ function openMemberList(group, onPick) {
     input.addEventListener('input', () => renderRows(input.value))
     input.addEventListener('pointerdown', (event) => event.stopPropagation())
     root.appendChild(header)
+    root.appendChild(subtitle)
     root.appendChild(input)
     root.appendChild(list)
     renderRows('')
@@ -1163,7 +1246,7 @@ export function syncMarkerOverlay({ markers, devices, aggregates, facilities, se
     }
 
     // 本票:聚合徽章(未关联设备按屏幕拥挤合并后的显示入口)。
-    renderAggregates(badgeGroups)
+    renderAggregates(badgeGroups, tones)
 
     // 关联设备(票 47 维护者反馈②根因:设备是独立 billboard 图层,此前 DOM 只渲染
     // 摘要标记计划、关联设备根本没进 DOM)。行由引擎每帧投影产出(屏幕坐标真值 +
@@ -1483,3 +1566,4 @@ export function unmountMarkerOverlay() {
     aggregateSelectedCode = ''
     pool.clear()
 }
+