Selaa lähdekoodia

feat(cockpit): 泵站类型字典透传与中文译码

ChenJZ 18 tuntia sitten
vanhempi
commit
dfdcbf26f1

+ 6 - 0
src/modules/cockpit/CockpitShell.vue

@@ -615,6 +615,8 @@ import { useMapStore } from './stores/mapStore.js'
 import { useRefreshStore } from './stores/refreshStore.js'
 import { MAP_OBJECT_KIND, MAP_SUMMARY_PHASE } from './domain/mapSummary.js'
 import { getCockpitConfigState, loadCockpitConfig, withUrlDataSourceOverride } from './services/cockpitConfig.js'
+import { fetchPumpStationTypeDict } from './services/facilityDictApi.js'
+import { setPumpTypeLabels } from './domain/facilityTypeDict.js'
 import {
     atHome,
     getAreaLimits,
@@ -2259,6 +2261,10 @@ onMounted(() => {
                 })
             }
         }
+        // 票 02:泵站类型字典独立于面板取数;只在成功后注入,失败保持「类型未发布」不猜。
+        fetchPumpStationTypeDict({ config: result.config }).then((section) => {
+            if (section.state === 'success') setPumpTypeLabels(section.data)
+        })
         lifecycleReady.value = true
         // 首屏只取当前模式;其它模式在第一次切过去时再取(筛选变化会清缓存)。
         ensureModePanelsLoaded(mode.value)

+ 2 - 3
src/modules/cockpit/domain/entityDetail.js

@@ -9,6 +9,7 @@ import { DEFAULT_TONE } from './statusTones.js'
 import { toWorkOrder, toWorkOrderTimeline, workOrderStateName } from './workOrder.js'
 import { trackOf } from './workOrderTimeline.js'
 import { facilityStatusTone } from './facilityStatus.js'
+import { pumpStationTypeText } from './facilityTypeDict.js'
 export { facilityStatusTone } from './facilityStatus.js'
 
 export const ENTITY_DETAIL_KIND = Object.freeze({
@@ -274,8 +275,6 @@ const NETWORK_LEVEL_TEXT = { '0': '污水', '1': '雨水' }
 const ENGINEERING_FACILITY_TYPE_TEXT = { '0': '闸门', '1': '调蓄设施', '2': '泵站' }
 /** 窨井井形(manhole_shape):码值直译,认不出回原码(与上面几条同一纪律)。 */
 const MANHOLE_SHAPE_TEXT = { '0': '圆形', '1': '方形', '2': '矩形' }
-/** 泵站表供水/排水共用(后端 PumpStationType:water_supply / drainage),码值直译;认不出回原码。 */
-const PUMP_STATION_TYPE_TEXT = { water_supply: '供水泵站', drainage: '排水泵站' }
 /** 类别中文名:界面上用「中文 + 英文码」,只印英文等于把接口词汇漏上大屏。 */
 const FACILITY_CATEGORY_TEXT = {
     PIPE_NETWORK: '管网',
@@ -379,7 +378,7 @@ const ASSET_FIELD_ROWS = {
         { label: '备注', key: 'remark', wide: true },
     ],
     PUMP_STATION: [
-        { label: '泵站类型', key: 'stationType', format: (v) => codedText(v, PUMP_STATION_TYPE_TEXT) },
+        { label: '泵站类型', key: 'stationType', format: (v) => pumpStationTypeText(v) },
         { label: '水泵数量', key: 'pumpCount' },
         { label: '设计流量', key: 'designFlow' },
         { label: '设计扬程', key: 'designHead' },

+ 58 - 0
src/modules/cockpit/domain/facilityTypeDict.js

@@ -0,0 +1,58 @@
+/**
+ * 泵站类型字典(票 02)。
+ *
+ * 物理值 0/1 由后端 sys_dict_data 定义,前端不再内置 water_supply/drainage 词表。
+ * 字典取不到时如实说「类型未发布」;取到但码不认识时只说「未知」,绝不回显英文枚举。
+ */
+export const PUMP_TYPE_DICT_TYPE = 'pump_station_type'
+export const PUMP_TYPE_UNAVAILABLE_TEXT = '类型未发布'
+export const PUMP_TYPE_UNKNOWN_TEXT = '未知'
+
+let labels = null
+
+const field = (row, camel, snake) => {
+    if (!row || typeof row !== 'object') return ''
+    const value = row[camel] !== undefined ? row[camel] : row[snake]
+    return value === null || value === undefined ? '' : String(value).trim()
+}
+
+/** sys_dict_data 行 → { dictValue: dictLabel };只收本字典,认不出行回 null。 */
+export function toPumpTypeLabels(raw) {
+    const rows = Array.isArray(raw) ? raw
+        : (raw && Array.isArray(raw.rows) ? raw.rows : (raw && Array.isArray(raw.data) ? raw.data : []))
+    const result = {}
+    for (const row of rows) {
+        const type = field(row, 'dictType', 'dict_type')
+        // 请求已按 dict_type 过滤;响应里缺字段或类型不符的行一律不收,防止脏行覆盖正式标签。
+        if (type !== PUMP_TYPE_DICT_TYPE) continue
+        const value = field(row, 'dictValue', 'dict_value')
+        const label = field(row, 'dictLabel', 'dict_label')
+        if (value && label) result[value] = label
+    }
+    return Object.keys(result).length ? result : null
+}
+
+/** 只看「键非空、值为字符串」的纯标签表,避免把任意对象当字典。 */
+function isLabelMap(value) {
+    if (!value || typeof value !== 'object' || Array.isArray(value)) return false
+    const entries = Object.entries(value)
+    return entries.length > 0 && entries.every(([key, label]) => key !== '' && typeof label === 'string')
+}
+
+/** 成功取到字典后由启动链注入;兼容原始 sys_dict_data 行与已解析的标签表。 */
+export function setPumpTypeLabels(value) {
+    labels = toPumpTypeLabels(value) || (isLabelMap(value) ? { ...value } : null)
+}
+
+/** 仅测试用:回到「字典未取到」。 */
+export function resetPumpTypeLabelsForTest() {
+    labels = null
+}
+
+/** 泵站类型码 → 中文;字典不可用、未知码都不猜、不回显英文。 */
+export function pumpStationTypeText(value) {
+    const code = value === null || value === undefined ? '' : String(value).trim()
+    if (!code) return ''
+    if (!labels) return PUMP_TYPE_UNAVAILABLE_TEXT
+    return Object.prototype.hasOwnProperty.call(labels, code) ? labels[code] : PUMP_TYPE_UNKNOWN_TEXT
+}

+ 5 - 0
src/modules/cockpit/mocks/contractMocks.js

@@ -3212,6 +3212,11 @@ const PAYLOADS = {
     '/equipments/*/freshness': (s, requested) => freshnessPayload(s, requested),
     '/equipments/*/archive': (s) => (s === 'empty' ? null : ARCHIVE),
     // 票 17:基础设施模式四块面板的面板级聚合读模型(各块独立成败,互不牵连)。
+    // 票 02:泵站类型字典(cockpit 域透传),只按本字典给 0/1 两行。
+    '/dict/pump_station_type': (s) => (s === 'empty' ? [] : [
+        { dictType: 'pump_station_type', dictValue: '0', dictLabel: '供水泵站' },
+        { dictType: 'pump_station_type', dictValue: '1', dictLabel: '排水泵站' },
+    ]),
     '/infrastructure/base-archives': (s, _requested, context) => baseArchivesPayload(s, context.query),
     '/infrastructure/operating-information': (s, _requested, context) => operatingInformationPayload(s, context.query),
     '/infrastructure/management-information': (s, _requested, context) => managementInformationPayload(s, context.query),

+ 20 - 0
src/modules/cockpit/services/facilityDictApi.js

@@ -0,0 +1,20 @@
+/**
+ * 泵站类型字典的 cockpit 域接口(票 02)。
+ * 只拼领域路径,地址与 mock/real 切换由统一出口负责;前端不直连管理平台。
+ */
+import { fetchSection } from './domainRequest.js'
+import { PUMP_TYPE_DICT_TYPE, toPumpTypeLabels } from '../domain/facilityTypeDict.js'
+
+export const FACILITY_DICT_PATHS = Object.freeze({
+    pumpStationType: '/dict/pump_station_type',
+})
+
+export function fetchPumpStationTypeDict(options = {}) {
+    return fetchSection(FACILITY_DICT_PATHS.pumpStationType, {
+        params: { dictType: PUMP_TYPE_DICT_TYPE },
+        toData: toPumpTypeLabels,
+        isEmpty: (payload) => toPumpTypeLabels(payload) === null,
+        config: options.config,
+        fetchImpl: options.fetchImpl,
+    })
+}