Parcourir la source

fix(cockpit): 设备类型状态分布图例改为两列完整排版

多环共用图例原用 flex-wrap 且标签列固定 4em(--donut-label-ch 缺省 4),长标签被截成「窨井盖···」。改为与 stackedBlock 一致的 grid 两列 + flex 行,标签自然占满列宽,色点/名称/计数对齐。
ChenJZ il y a 8 heures
Parent
commit
b1e1ca4da4

+ 28 - 4
src/modules/cockpit/components/PanelBlocks.vue

@@ -3161,15 +3161,39 @@ onBeforeUnmount(() => {
 }
 
 .panel-donuts__legend {
-    display: flex;
-    flex-wrap: wrap;
-    justify-content: center;
-    gap: calc(2 * var(--u, 1px)) calc(10 * var(--u, 1px));
+    /* 与 stackedBlock 的参考排版**逐字同源**(维护者 2026-12-02):
+       auto-fill + minmax(96u,1fr) 自适应列宽、每列至少 96u;行是「色点 + 名称 + 计数」,
+       标签占满列宽,不再被截成「窨井盖···」。旧版 flex-wrap + 固定 4em 标签列
+       (--donut-label-ch 缺省 4)才是截断的根因。 */
+    display: grid;
+    grid-template-columns: repeat(auto-fill, minmax(calc(96 * var(--u, 1px)), 1fr));
+    gap: calc(2 * var(--u, 1px)) var(--space-2, 8px);
     margin: 0;
     padding: 0;
     list-style: none;
 }
 
+/* donut-grid 图例行与 stacked 行同款:flex 三段(色点 / 名称 / 计数)。
+   覆盖 .panel-donut__row 那条「四列网格 + 长条」规则 —— 那条是给**单环左右式**
+   图例用的(名称定宽、长条对齐),多环共用图例没有长条,套上去只会把名称压成 4 字。 */
+.panel-donuts__legend .panel-donut__row {
+    display: flex;
+    align-items: center;
+    gap: calc(4 * var(--u, 1px));
+    min-width: 0;
+}
+
+.panel-donuts__legend .panel-donut__label {
+    width: auto;
+    flex: 1 1 auto;
+    min-width: 0;
+}
+
+.panel-donuts__legend .panel-donut__count {
+    flex: none;
+    margin-left: auto;
+}
+
 /* 超宽模式:与 CockpitShell.vue 的栏内并排断点同源。基础规则在上、覆盖规则在下,
    同权重靠源码次序让 2×2 与放大尺寸真正生效。 */
 @media (min-aspect-ratio: 3456 / 1239) {

+ 57 - 0
tests/monitoringDonutLegend.test.js

@@ -0,0 +1,57 @@
+import assert from 'node:assert/strict'
+import { readFileSync } from 'node:fs'
+import test from 'node:test'
+
+/**
+ * 「设备类型状态分布」图例排版守卫(维护者 2026-12-02)。
+ *
+ * 症状:图一(donutGridBlock)的图例标签全被截成「窨井盖···343」「可燃···32」,
+ * 且行与行对不齐;图二(stackedBlock)两列、标签完整、色点+名称+计数对齐。
+ *
+ * 根因:donutGrid 的图例是 flex-wrap,且 `.panel-donut__label` 被固定成 4em
+ * (`--donut-label-ch` 默认 4,而 donutGridBlock 没算这个变量),长标签必被截断。
+ * 修法:让 donut-grid 图例复用 stacked 的 grid 两列 + flex 行排版,
+ * 标签列自然占满列宽,不再写死 4em。
+ */
+function styleOf(file) {
+    const source = readFileSync(new URL(`../${file}`, import.meta.url), 'utf8')
+    const match = source.match(/<style[^>]*>([\s\S]*?)<\/style>/)
+    assert.ok(match, `${file} 应有样式块`)
+    return match[1]
+}
+
+/** 取一条选择器的规则体(按声明块花括号配对),并剥离注释避免误判。 */
+function ruleBody(css, selector) {
+    const index = css.indexOf(selector)
+    assert.ok(index >= 0, `找不到规则:${selector}`)
+    const open = css.indexOf('{', index)
+    let depth = 0
+    for (let i = open; i < css.length; i += 1) {
+        if (css[i] === '{') depth += 1
+        else if (css[i] === '}') {
+            depth -= 1
+            if (depth === 0) return css.slice(open + 1, i).replace(/\/\*[\s\S]*?\*\//g, '')
+        }
+    }
+    throw new Error(`规则花括号不配对:${selector}`)
+}
+
+const css = styleOf('src/modules/cockpit/components/PanelBlocks.vue')
+
+test('donut-grid 图例用与 stacked 参考一致的 auto-fill 两列栅格,不再 flex-wrap', () => {
+    const body = ruleBody(css, '.panel-donuts__legend {')
+    assert.match(body, /display:\s*grid/, '图例容器应为 grid')
+    // 与图二 stackedBlock 同源:auto-fill + minmax(96u,1fr),列数随面板宽度自适应,
+    // 每列至少 96u 保证标签有足够宽度,不再被压成 4 字。
+    assert.match(body, /grid-template-columns:\s*repeat\(\s*auto-fill\s*,\s*minmax\(calc\(96 \* var\(--u, 1px\)\), 1fr\)\)/)
+    assert.doesNotMatch(body, /flex-wrap/, '不能再回到 flex-wrap')
+})
+
+test('donut-grid 图例行改为 flex(色点+名称+计数),不再用固定 4em 标签列', () => {
+    const row = ruleBody(css, '.panel-donuts__legend .panel-donut__row {')
+    assert.match(row, /display:\s*flex/, '图例行应为 flex')
+
+    const label = ruleBody(css, '.panel-donuts__legend .panel-donut__label {')
+    assert.match(label, /width:\s*auto/, '标签列应自动占满剩余宽度')
+    assert.doesNotMatch(label, /--donut-label-ch/, '不能再把标签宽度写死成字符数')
+})