Browse Source

fix(cockpit): 统一感知设备指标字号并精简类型卡小字

value-first 四卡不再按各卡文本长度逐卡缩字号,统一 22u;类型卡小字改为一条举例设备类型(供水/排水/燃气/窨井),未登记行业仍回退后端监测内容,避免长短不一与换行。
ChenJZ 23 hours ago
parent
commit
b447be89ef

+ 5 - 13
src/modules/cockpit/components/PanelBlocks.vue

@@ -1995,19 +1995,11 @@ onBeforeUnmount(() => {
     overflow: hidden;
 }
 
-/* 票 67 追加(2026-10-28):value-first 的读数**也**受宽度预算约束。
-   上面那条 min(22u, 34cqw) 是「不超过 22u、且不超过格宽 34%」的旧安全网;
-   但 34cqw 仍可能大于按**实际文本宽度**算出的可容字号(例如 8 位数字 78546.04),
-   于是 value-first 窄格里的长读数仍会画「…」。这里再叠一层:按 --kpi-reading-em
-   (含单位、见 domain/kpiFit.js)算出「刚好放得下」的字号,取两者更小的。
-   单独一条规则、放在原规则之后:同 specificity、后写的赢;原规则一字未动(t11 F9e 仍守它)。 */
-.panel-kpi--value-first .panel-kpi__value,
-.panel-kpi--value-first .panel-kpi__value--link {
-    font-size: min(
-        min(calc(22 * var(--u, 1px)), 34cqw),
-        calc((100cqw - calc(18 * var(--u, 1px))) / var(--kpi-reading-em, 5))
-    );
-}
+/* 维护者 2026-12-01:顶部四卡读数**必须同一字号**。
+   此前这里再叠了一层「按本卡文本长度(--kpi-reading-em)算刚好放得下」的字号,
+   于是「16 / 52 / 32 / 343」与「27.3%」各算出一个字号,同一排看起来大小不一。
+   现在只保留上面那条 `min(22u, 34cqw)`:四卡等宽 ⇒ 34cqw 同值 ⇒ 字号必然一致;
+   34cqw 仅作窄容器下的防出框兜底,不再按文本长度逐卡收缩。 */
 
 /* value-first 卡在画面上不显示单位(设计稿顶部四卡只有数字):
    数据层仍带单位(悬停 title 由 kpiReading 给「10 台」),只是不占视觉位。 */

+ 27 - 6
src/modules/cockpit/domain/overviewPanels.js

@@ -103,20 +103,19 @@ export function toPerception(raw) {
         onlineCount: numberish(totals.raw.onlineCount),
         offlineCount: numberish(totals.raw.offlineCount),
         onlineRate: toRatio(totals.raw.onlineRate),
-        // 类型卡:四项固定顺序由后端给;卡内小字 = `monitoringContent`。
-        // 维护者 2026-10-23:供水/排水这两张卡下的小字「尽可能精简」——
-        // 真实内容很长(供水 4 项、排水 8 项,如「排水瞬时流量监测 / 排水流速监测 / …」),
-        // 所以展示层压缩成「最多两项 + 等」,**完整原文进 title 悬停可读**,不丢信息。
+        // 类型卡:四项固定顺序由后端给;卡内小字=一条**举例设备类型**(维护者 2026-12-01),
+        // 未登记行业回退到后端监测内容的压缩结果。完整监测内容仍进 title 悬停可读。
         types: reader.optionalList('byType').map((item) => {
             const row = fieldReader(item, 'overviewPerception.byType')
             const monitoringContent = row.optionalStr('monitoringContent')
+            const label = row.optionalStr('name') || row.optionalStr('code')
             return {
                 code: row.optionalStr('code'),
-                label: row.optionalStr('name') || row.optionalStr('code'),
+                label,
                 count: numberish(row.raw.deviceCount) ?? 0,
                 onlineCount: numberish(row.raw.onlineCount),
                 offlineCount: numberish(row.raw.offlineCount),
-                note: conciseMonitoring(monitoringContent),
+                note: exampleDeviceType(label) || conciseMonitoring(monitoringContent),
                 noteTitle: monitoringContent,
             }
         }),
@@ -384,6 +383,28 @@ function conciseMonitoring(text) {
     return items.length > kept.length ? `${kept.join(' / ')} 等` : kept.join(' / ')
 }
 
+/**
+ * 类型卡小字的**举例设备类型**(维护者 2026-12-01)。
+ *
+ * 原先把后端 `monitoringContent` 压成「压力 / 瞬时流量 等」——那是**监测因子**,
+ * 四项长短不一(燃气那张会换行),一排卡看起来参差。维护者要的是「一条设备类型举例」,
+ * 四种行业各给一个代表型号,统一以「等」收尾,卡内小字因此等长、不换行。
+ * 未登记的行业仍回退到后端的监测内容(压缩后),不画空小字、也不编造型号。
+ */
+const TYPE_DEVICE_EXAMPLE = {
+    供水: '供水压力流量终端',
+    排水: '环境监测终端',
+    燃气: '可燃气体监测终端',
+    窨井: '窨井监测终端',
+}
+
+/** 卡名(如「供水设备」)→ 举例设备类型小字;认不出行业回空串。 */
+function exampleDeviceType(label) {
+    const name = String(label == null ? '' : label)
+    const industry = Object.keys(TYPE_DEVICE_EXAMPLE).find((prefix) => name.startsWith(prefix))
+    return industry ? `${TYPE_DEVICE_EXAMPLE[industry]} 等` : ''
+}
+
 /** 折线点列 → 纯数值列表(多序列 API 只要值,日期标签共用主轴的 points)。 */
 function trendOf(sevenDayTrend) {
     return (sevenDayTrend || []).map((point) => numberish(point.count) || 0)

+ 51 - 0
tests/overviewPerceptionCards.test.js

@@ -0,0 +1,51 @@
+import assert from 'node:assert/strict'
+import { readFileSync } from 'node:fs'
+import test from 'node:test'
+
+import { toPerception } from '../src/modules/cockpit/domain/overviewPanels.js'
+
+const raw = {
+    updatedAt: '2026-12-01 10:00:00',
+    totals: { deviceCount: 443, onlineCount: 300, offlineCount: 143, onlineRate: { state: 'OK', value: '0.6772' } },
+    byType: [
+        { code: '1', name: '供水设备', deviceCount: 16, onlineCount: 12, offlineCount: 4, monitoringContent: '供水压力监测 / 供水瞬时流量监测 / 供水漏失监测' },
+        { code: '2', name: '排水设备', deviceCount: 52, onlineCount: 40, offlineCount: 12, monitoringContent: '排水瞬时流量监测 / 排水流速监测 / 排水液位监测' },
+        { code: '3', name: '燃气设备', deviceCount: 32, onlineCount: 20, offlineCount: 12, monitoringContent: '可燃气体浓度监测 / 可燃气体温度监测' },
+        { code: '4', name: '窨井设备', deviceCount: 343, onlineCount: 228, offlineCount: 115, monitoringContent: '井盖倾斜监测 / 井盖水浸监测' },
+    ],
+    byDistrict: [],
+}
+
+test('类型卡小字按行业给一条举例设备类型,长短一致不再换行', () => {
+    const types = toPerception(raw).types
+    assert.deepEqual(types.map((row) => row.note), [
+        '供水压力流量终端 等',
+        '环境监测终端 等',
+        '可燃气体监测终端 等',
+        '窨井监测终端 等',
+    ])
+    // 完整监测内容仍保留在悬停标题里,信息不丢。
+    assert.equal(types[2].noteTitle, '可燃气体浓度监测 / 可燃气体温度监测')
+})
+
+test('未登记的行业仍回退到后端监测内容,不画空小字', () => {
+    const [row] = toPerception({
+        ...raw,
+        byType: [{ code: '9', name: '照明设备', deviceCount: 1, monitoringContent: '照明电流监测 / 照明电压监测 / 照明功率监测' }],
+    }).types
+    assert.equal(row.note, '照明电流 / 照明电压 等')
+})
+
+test('value-first 四卡读数统一字号,不再按每张卡的文本长度各自缩字号', () => {
+    const source = readFileSync(new URL('../src/modules/cockpit/components/PanelBlocks.vue', import.meta.url), 'utf8')
+    const style = source.match(/<style[^>]*>([\s\S]*?)<\/style>/)[1]
+    const readingRules = style
+        .split('}')
+        .map((rule) => rule.split('{'))
+        .filter(([selector, body]) => body && /panel-kpi--value-first/.test(selector) && /panel-kpi__value\b/.test(selector))
+    assert.ok(readingRules.length > 0, '应有 value-first 读数规则')
+    for (const [selector, body] of readingRules) {
+        assert.doesNotMatch(body, /--kpi-reading-em/, `这条规则仍按每卡文本长度收字号:${selector.trim()}`)
+    }
+    assert.ok(readingRules.some(([, body]) => /font-size:\s*min\(calc\(22 \* var\(--u, 1px\)\), 34cqw\)/.test(body)))
+})