Переглянути джерело

feat(cockpit): 顶部图例分组与按模式显示

ChenJZ 7 годин тому
батько
коміт
c9b96c046b

+ 196 - 96
src/modules/cockpit/components/MapCanvas.vue

@@ -25,78 +25,95 @@
             票 46:引导态仍不显示(规格 18:引导态没有图例/计数/详情)。
         -->
         <div class="map-holo__top">
-            <div v-if="entered" class="map-holo__legend" data-map-legend data-status-filter>
-                <button
-                    v-for="row in statusRows"
-                    :key="row.key"
-                    type="button"
-                    class="map-holo__legend-row"
-                    :class="{ 'is-selected': row.selected }"
-                    :style="{ '--legend-color': `var(--${row.tone})` }"
-                    :data-legend-key="row.key"
-                    :data-status-selected="row.selected ? 'yes' : 'no'"
-                    :data-status-count="row.count === null ? '' : String(row.count)"
-                    :title="row.title"
-                    :aria-pressed="row.selected"
-                    @click="toggleStatusFilter(row.key)"
-                >
-                    <!-- 批次 1 第三轮:状态行前置区分图标(语义色染色)。纯装饰,形状+颜色仍是第一线索。 -->
-                    <CockpitIcon v-if="row.icon" monochrome :name="row.icon" size="calc(14 * var(--u, 1px))" class="map-holo__legend-icon" />
-                    <StatusTag :tone="row.tone" :shape="row.shape" :label="row.label" />
-                    <span class="map-holo__legend-count" data-status-count>:{{ row.count === null ? '—' : row.count }}</span>
-                    <!--
-                        维护者 2026-11-05:「图例的预警 7 与图上坐标点 2 对不上」。
-                        这不是缺陷,但**界面必须自己说清楚**——两行数字的口径本来就不同:
-                          · 前面的计数=**设备**台账里有这种标签的台数(可按状态筛选的池子大小);
-                          · 这里的「上图 N」=当前模式**真正画上地图的对象数**(点位聚合 + 独立设备)。
-                        设备没有坐标(MISSING_LONGITUDE)、或它挂在的点位已按聚合状态显示成别的颜色,
-                        都会让 N < 计数。把两个数同时摆出来,读者不必去猜哪个是错的。
-                    -->
-                    <span v-if="row.onMap !== null" class="map-holo__legend-onmap" data-status-onmap-text>· 上图 {{ row.onMap }}</span>
-                </button>
-            </div>
-
             <!--
-                票 68:**设施图例(独立块 + 独立筛选维度)**。
-                与上面状态图例**换行分开**(两个容器、两套 data-* 断言面),不是塞进同一行:
-                  · 状态图例筛选监测点/设备(filterStore.pointStatus);
-                  · 本块筛选四类设施点(filterStore.facilityTypes),互不改写。
-                行常驻可点(计数 0 / 未发布的类型也可点,不造死胡同);
-                计数口径 = 全局档案数(不随筛选变化),「上图 N」= 当前图层可上图数。
+                票 05:顶部图例分两组——设备状态 / 设施类型。
+                组内是等宽网格(行宽由列宽决定,不再随文字长短参差);按一级模式只显示
+                当前模式相关的组(domain/mapLegend.js),隐藏组不改已生效的筛选。
+            -->
+            <!--
+                维护者 2026-11-18:总体概览两组并排时换行是预期;其余三个模式只有一组,
+                该组应独占图例条、一字排开且左对齐。单组模式靠 --single 修饰类切换网格,
+                不在这里判模式(模式可见性仍由 legendGroupsForMode 决定)。
             -->
             <div
                 v-if="entered"
-                class="map-holo__legend map-holo__legend--facility"
+                class="map-holo__legend-bar"
+                :class="{ 'map-holo__legend-bar--single': legendGroups.length === 1 }"
                 data-map-legend
-                data-facility-legend
-                data-facility-filter
             >
-                <button
-                    v-for="row in facilityRows"
-                    :key="row.key"
-                    type="button"
-                    class="map-holo__legend-row"
-                    :class="{ 'is-selected': row.selected }"
-                    :style="{ '--legend-color': 'var(--cyan)' }"
-                    :data-facility-key="row.key"
-                    :data-facility-selected="row.selected ? 'yes' : 'no'"
-                    :data-facility-count="row.count === null ? '' : String(row.count)"
-                    :data-facility-onmap="String(row.onMap)"
-                    :data-facility-state="row.state"
-                    :title="row.title"
-                    :aria-pressed="row.selected"
-                    @click="toggleFacilityFilter(row.key)"
+                <section
+                    v-if="showDeviceLegend"
+                    class="map-holo__legend-group"
+                    data-legend-group="device"
+                    data-status-filter
+                    aria-label="设备状态图例"
                 >
-                    <CockpitIcon
-                        v-if="row.symbol"
-                        :name="row.symbol"
-                        size="calc(13 * var(--u, 1px))"
-                        class="map-holo__legend-icon"
-                    />
-                    <span class="map-holo__legend-label">{{ row.label }}</span>
-                    <span class="map-holo__legend-count" data-facility-count-text>:{{ row.countText }}</span>
-                    <span class="map-holo__legend-onmap" data-facility-onmap-text>· 上图 {{ row.onMap }}</span>
-                </button>
+                    <h3 class="map-holo__legend-title" data-legend-group-title>设备状态</h3>
+                    <div class="map-holo__legend-grid">
+                        <button
+                            v-for="row in statusRows"
+                            :key="row.key"
+                            type="button"
+                            class="map-holo__legend-row"
+                            :class="{ 'is-selected': row.selected }"
+                            :style="{ '--legend-color': `var(--${row.tone})` }"
+                            :data-legend-key="row.key"
+                            :data-status-selected="row.selected ? 'yes' : 'no'"
+                            :data-status-count="row.count === null ? '' : String(row.count)"
+                            :title="row.title"
+                            :aria-pressed="row.selected"
+                            @click="toggleStatusFilter(row.key)"
+                        >
+                            <!-- 批次 1 第三轮:状态行前置区分图标(语义色染色)。纯装饰,形状+颜色仍是第一线索。 -->
+                            <CockpitIcon v-if="row.icon" monochrome :name="row.icon" size="calc(9 * var(--u, 1px))" class="map-holo__legend-icon" />
+                            <StatusTag :tone="row.tone" :shape="row.shape" :label="row.label" />
+                            <span class="map-holo__legend-count" data-status-count>:{{ row.count === null ? '—' : row.count }}</span>
+                        </button>
+                    </div>
+                </section>
+
+                <!--
+                    票 68:设施图例是**独立筛选维度**(filterStore.facilityTypes),与设备状态互不改写。
+                    行常驻可点(计数 0 / 未发布的类型也可点,不造死胡同);
+                    计数口径 = 全局档案数(不随筛选变化),「上图 N」= 当前图层可上图数。
+                -->
+                <section
+                    v-if="showFacilityLegend"
+                    class="map-holo__legend-group"
+                    data-legend-group="facility"
+                    data-facility-legend
+                    data-facility-filter
+                    aria-label="设施类型图例"
+                >
+                    <h3 class="map-holo__legend-title" data-legend-group-title>设施类型</h3>
+                    <div class="map-holo__legend-grid">
+                        <button
+                            v-for="row in facilityRows"
+                            :key="row.key"
+                            type="button"
+                            class="map-holo__legend-row"
+                            :class="{ 'is-selected': row.selected }"
+                            :style="{ '--legend-color': 'var(--cyan)' }"
+                            :data-facility-key="row.key"
+                            :data-facility-selected="row.selected ? 'yes' : 'no'"
+                            :data-facility-count="row.count === null ? '' : String(row.count)"
+                            :data-facility-onmap="String(row.onMap)"
+                            :data-facility-state="row.state"
+                            :title="row.title"
+                            :aria-pressed="row.selected"
+                            @click="toggleFacilityFilter(row.key)"
+                        >
+                            <CockpitIcon
+                                v-if="row.icon || row.symbol"
+                                :name="row.icon || row.symbol"
+                                size="calc(9 * var(--u, 1px))"
+                                class="map-holo__legend-icon"
+                            />
+                            <span class="map-holo__legend-label">{{ row.label }}</span>
+                            <span class="map-holo__legend-count" data-facility-count-text>:{{ row.countText }}</span>
+                        </button>
+                    </div>
+                </section>
             </div>
         </div>
 
@@ -143,6 +160,8 @@ import { selectMonitoringPoint } from '../pointSelection.js'
 import { legendVisuals } from '../domain/pointStatus.js'
 // 票 68:设施图例会数据(档案口径 + 可上图数)与选中集合的唯一来源。
 import { facilityLegendRows } from '../domain/facilityPoints.js'
+// 票 05:图例分组与按一级模式的可见性(纯领域函数,组件不自己判模式)。
+import { LEGEND_GROUP, legendGroupsForMode } from '../domain/mapLegend.js'
 import { storeToRefs } from 'pinia'
 import { useDeviceLayerStore } from '../stores/deviceLayerStore.js'
 import { useEntityDetailStore } from '../stores/entityDetailStore.js'
@@ -310,6 +329,12 @@ const modePlan = computed(() => props.plan || EMPTY_PLAN)
 /** 引导态(计划层以 `entered` 表达):图例/计数浮标/降级面板都门控掉。 */
 const entered = computed(() => modePlan.value.entered === true)
 
+// 票 05:图例组可见性跟图层走——总体概览两组、基础设施仅设施、运行监测/预警处置仅设备。
+// 只决定显示哪组,不读写 filterStore;隐藏组时已生效的筛选保持原样。
+const legendGroups = computed(() => legendGroupsForMode(modePlan.value.mode))
+const showDeviceLegend = computed(() => legendGroups.value.includes(LEGEND_GROUP.DEVICE))
+const showFacilityLegend = computed(() => legendGroups.value.includes(LEGEND_GROUP.FACILITY))
+
 watch(() => [entityDetailStore.open, entityDetailStore.identity, modePlan.value.facilityPoints], () => {
     setFacilitySelection(entityDetailStore.open ? entityDetailStore.identity : null)
 }, { flush: 'sync' })
@@ -661,7 +686,11 @@ onBeforeUnmount(() => {
     display: grid;
     gap: calc(6 * var(--u, 1px));
     justify-items: center;
-    max-width: 92%;
+    /* 只占左右业务栏之间的中央可见区:一张图铺满主体背景,两栏压在它上面;
+       若按 92% 全宽排,图例两侧会被侧栏盖住。 */
+    width: 100%;
+    max-width: min(92%, calc(100% - 2 * var(--column-w, 330px) - calc(16 * var(--u, 1px))), 1600px);
+    container-type: inline-size;
     text-align: center;
     pointer-events: none;
 }
@@ -669,53 +698,118 @@ onBeforeUnmount(() => {
 
 
 
-/* 图例容器:标签外观由 StatusTag 提供(颜色取自 token,语义与颜色不再硬编码在这里) */
-.map-holo__legend {
-    display: flex;
-    gap: calc(8 * var(--u, 1px));
+/* 图例条:两组(设备状态 / 设施类型)并排。
+   维护者复验:①图例行要有对应图标;②两组大小以设施类型为准、去掉「上图 N」;
+   ③颜色语义清晰、不靠降低不透明度压存在感。故两组共用同一张网格模板与同一档行尺寸,
+   颜色用语义色描边 + 低透明底板(不降行本身 opacity),视野占用靠几何尺寸而非淡化。 */
+.map-holo__legend-bar {
+    display: grid;
+    grid-template-columns: repeat(2, minmax(0, 1fr));
+    gap: calc(10 * var(--u, 1px));
+    width: auto;
+    max-width: 100%;
+    align-items: start;
     justify-content: center;
-    flex-wrap: wrap;
 }
 
-/* 票 68:设施图例是**独立一块**——容器、data-* 断言面、筛选维度都与上面的状态图例分开
-   (父容器是 grid,两块天然各占一行,不是靠 CSS 换行 trick 挤在一条线上)。 */
-.map-holo__legend--facility {
-    margin-top: calc(2 * var(--u, 1px));
+.map-holo__legend-group {
+    display: grid;
+    gap: calc(4 * var(--u, 1px));
+    min-width: 0;
+    padding: 0;
+    border: 0;
+    background: none;
+    box-shadow: none;
 }
 
-.map-holo__legend-label {
-    font-size: var(--fs-caption, 11.5px);
+.map-holo__legend-title {
+    margin: 0;
+    color: var(--cyan, #01abea);
+    font-size: var(--fs-note, 9.2px);
+    font-weight: 600;
+    letter-spacing: 0.08em;
+    line-height: 1.2;
+    text-align: left;
+    white-space: nowrap;
 }
 
-/* 「上图 N」是设施点图层的能力数(不随筛选变化);与档案计数用弱化小字区分,
-   避免两个数被读成同一套口径(票面「计数口径写清」的界面落点)。 */
-.map-holo__legend-onmap {
-    color: var(--text-2, #88b7e8);
-    font-family: var(--num, monospace);
+/* 两组并排时(总体概览)共用同一张 5 列网格:设施类型 9 项 → 5+4,设备状态 7 项 → 5+2。
+   行宽由列宽决定,两组行尺寸完全一致(以设施类型的行为准)。 */
+.map-holo__legend-grid {
+    display: grid;
+    grid-template-columns: repeat(5, minmax(0, 1fr));
+    gap: calc(3 * var(--u, 1px));
+    min-width: 0;
+}
+
+/* 单组模式(基础设施 / 运行监测 / 预警处置):该组独占图例条。
+   · 图例条从「两列、内容宽、居中」改成「一列、整条满宽、靠左」——
+     原先只渲染一组时它仍被塞进第一列(半宽)并被居中,看起来既没左对齐、尺寸也比总览小;
+   · 组内改成**单行**(grid-auto-flow: column + 内容宽度),一行排开不再换行;
+     列宽用 max-content 而不是 1fr:保持与总览里同一档行宽,两组大小由此对应。 */
+.map-holo__legend-bar--single {
+    grid-template-columns: minmax(0, 1fr);
+    width: 100%;
+    justify-self: start;
+    justify-content: start;
+}
+
+.map-holo__legend-bar--single .map-holo__legend-grid {
+    grid-template-columns: none;
+    grid-auto-flow: column;
+    grid-auto-columns: max-content;
+    justify-content: start;
+}
+
+.map-holo__legend-label {
+    min-width: 0;
+    overflow: hidden;
+    color: var(--text-1, #d7ecff);
     font-size: var(--fs-note, 9.2px);
+    text-overflow: ellipsis;
+    white-space: nowrap;
+}
+
+/* 中央可见区放不下两组并排时,改成上下两组(各自仍是 5 列等宽网格)。 */
+@container (max-width: 900px) {
+    .map-holo__legend-bar {
+        grid-template-columns: minmax(0, 1fr);
+    }
+}
+
+/* 单组且中央区偏窄时,单行内容宽会横向溢出:退回到 5 列换行(仍是同一档行宽)。 */
+@container (max-width: 820px) {
+    .map-holo__legend-bar--single .map-holo__legend-grid {
+        grid-template-columns: repeat(5, minmax(0, 1fr));
+        grid-auto-flow: row;
+        grid-auto-columns: auto;
+    }
 }
 
 /* 票 14:状态栏行是**按钮**(全局筛选入口)。抹掉按钮默认外观,保留可聚焦/hover/选中反馈。 */
 .map-holo__legend-row {
     pointer-events: auto;
-    display: inline-flex;
+    display: grid;
+    grid-template-columns: auto minmax(0, 1fr) auto;
     align-items: center;
     gap: calc(3 * var(--u, 1px));
-    padding: 3px 8px;
+    min-width: 0;
+    padding: calc(3 * var(--u, 1px)) calc(5 * var(--u, 1px));
     border: 1px solid var(--legend-color, var(--neutral));
-    border-radius: 999px;
-    background: rgba(2, 9, 27, .86);
+    border-radius: calc(3 * var(--u, 1px));
+    background: color-mix(in srgb, var(--legend-color, var(--neutral)) 12%, rgba(2, 9, 27, 0.88));
     color: var(--legend-color, var(--neutral));
     font: inherit;
+    font-size: var(--fs-note, 9.2px);
+    text-align: left;
     cursor: pointer;
-    opacity: 0.9;
-    transition: opacity 0.16s, filter 0.16s, box-shadow 0.16s, background-color 0.16s;
+    transition: filter 0.16s, box-shadow 0.16s, background-color 0.16s;
 }
 
-/* 批次 1 第三轮:状态行前置图标。弱辉光避免在地图亮部糊掉。 */
+/* 状态行前置图标:缩小到 9u,弱辉光避免在地图亮部糊掉。 */
 .map-holo__legend-icon {
     flex: none;
-    filter: drop-shadow(0 0 4px rgba(2, 9, 27, 0.9));
+    filter: drop-shadow(0 0 3px rgba(2, 9, 27, 0.9));
 }
 
 .map-holo__legend-row:hover,
@@ -735,11 +829,9 @@ onBeforeUnmount(() => {
  */
 .map-holo__legend-row.is-selected {
     opacity: 1;
-    background: color-mix(in srgb, var(--legend-color, var(--cyan)) 22%, rgba(2, 9, 27, 0.86));
-    box-shadow:
-        inset 0 0 0 1px var(--legend-color, var(--cyan)),
-        0 0 8px color-mix(in srgb, var(--legend-color, var(--cyan)) 55%, transparent);
-    filter: drop-shadow(0 0 6px rgba(1, 171, 234, 0.45));
+    background: color-mix(in srgb, var(--legend-color, var(--cyan)) 26%, rgba(2, 9, 27, 0.72));
+    box-shadow: inset 0 0 0 1px var(--legend-color, var(--cyan));
+    filter: none;
 }
 
 /* 选中行的标签文字与形状都转本行语义色:StatusTag 是 scoped 子组件,
@@ -761,7 +853,8 @@ onBeforeUnmount(() => {
 .map-holo__legend-count {
     color: var(--text-2, #88b7e8);
     font-family: var(--num, monospace);
-    font-size: var(--fs-caption, 11.5px);
+    font-size: var(--fs-note, 9.2px);
+    white-space: nowrap;
 }
 
 /* 票 35 续:生产形态把底部摘要行也收进**右下角状态日志**那一摞,
@@ -786,7 +879,14 @@ onBeforeUnmount(() => {
     padding: 0;
     border: 0;
     background: transparent;
+    min-width: 0;
+    overflow: hidden;
 }
 .map-holo__legend-row :deep(.status-tag__shape) { display: none; }
+.map-holo__legend-row :deep(.status-tag__label) {
+    overflow: hidden;
+    text-overflow: ellipsis;
+    white-space: nowrap;
+}
 .map-holo__legend-icon { color: var(--legend-color); }
 </style>

+ 22 - 1
src/modules/cockpit/domain/facilityPoints.js

@@ -396,6 +396,25 @@ export function facilityInventory(archivePayload, points) {
     })
 }
 
+/**
+ * 设施图例行的图标(票 05 复验:图例中也要有对应图标)。
+ *
+ * 与运行信息九卡共用同一套 icon.kpi.* 资源:类型 → CockpitIcon 语义名一一对应,
+ * 不再用旧的 pipeSpecial 泛指闸门/调蓄/消火栓(它未在图标注册表登记,等于没图标)。
+ * 图例与九卡看见的是同一枚剪影、同一档语义色,靠结构而不是约定保持一致。
+ */
+export const FACILITY_LEGEND_ICON = Object.freeze({
+    PIPE_NETWORK: 'kpiPipeSegment',
+    WATER_PLANT: 'kpiPlant',
+    PUMP_STATION: 'kpiPump',
+    WATER_SOURCE: 'kpiSource',
+    WATER_USER: 'kpiUser',
+    WATER_FIRE_HYDRANT: 'kpiHydrant',
+    DRAINAGE_GATE: 'kpiGate',
+    DRAINAGE_STORAGE: 'kpiStorage',
+    MANHOLE: 'kpiManhole',
+})
+
 function legendHint(row) {
     if (!row) return ''
     if (row.state === FACILITY_LEGEND_STATE.UNAVAILABLE) return '设施点数据未取到'
@@ -434,6 +453,8 @@ export function facilityLegendRows(inventory, selected) {
             label: row.label,
             unit: row.unit,
             symbol: row.symbol,
+            // 图例专用图标(与九卡同源);没有对应类型时留空,渲染层再回落到 symbol。
+            icon: FACILITY_LEGEND_ICON[row.key] || '',
             count: row.archiveCount,
             countText,
             onMap: row.mappableCount,
@@ -470,4 +491,4 @@ export function facilityPointCoordinateExtra(points) {
             reasonText: row.reasonText || NO_MAP_LOCATION_TEXT,
         })),
     }
-}
+}

+ 46 - 0
src/modules/cockpit/domain/mapLegend.js

@@ -0,0 +1,46 @@
+/**
+ * 顶部图例的分组与按一级模式可见性(票 05)。
+ *
+ * 两组图例对应两类对象,筛选维度互不改写:
+ *   · 设备状态:监测点/设备的八桶状态(`filterStore.pointStatus`);
+ *   · 设施类型:九类设施(`filterStore.facilityTypes`)。
+ *
+ * 可见性跟图层走,不另造一套判据:设施点只在总体概览/基础设施上图,监测点与设备只在
+ * 总体概览/运行监测/预警处置上图(见 `domain/modeLayerPlan.js` 的 `planNonPointLayers`
+ * 与 `visibleMapObjects`)。所以隐藏图例时,被隐藏的那组筛选本来也不会作用于当前画面;
+ * 本函数**只决定显示哪组,不读写 filterStore**。
+ */
+import { MODE_LAYER } from './modeLayerPlan.js'
+
+export const LEGEND_GROUP = Object.freeze({
+    DEVICE: 'device',
+    FACILITY: 'facility',
+})
+
+/** 组的展示顺序与标题(标题是界面词,不是筛选值)。 */
+export const LEGEND_GROUPS = Object.freeze([
+    { key: LEGEND_GROUP.DEVICE, label: '设备状态' },
+    { key: LEGEND_GROUP.FACILITY, label: '设施类型' },
+])
+
+/**
+ * 当前一级模式该显示哪些图例组。
+ *
+ * 未知模式按总体概览处理(两组都显示)——与 `planModeLayers` 的兜底一致,
+ * 不让一个脏模式把图例整块抹掉。
+ *
+ * @param {string} mode 一级模式键
+ * @returns {string[]} `LEGEND_GROUP` 的可见组
+ */
+export function legendGroupsForMode(mode) {
+    if (mode === MODE_LAYER.INFRASTRUCTURE) return [LEGEND_GROUP.FACILITY]
+    if (mode === MODE_LAYER.MONITORING || mode === MODE_LAYER.WARNING_RESPONSE) {
+        return [LEGEND_GROUP.DEVICE]
+    }
+    return [LEGEND_GROUP.DEVICE, LEGEND_GROUP.FACILITY]
+}
+
+/** 某一组在给定模式下是否可见(组件逐组判定的唯一入口)。 */
+export function legendGroupVisible(mode, group) {
+    return legendGroupsForMode(mode).includes(group)
+}