Просмотр исходного кода

fix(cockpit): 修字典加载被二次归一化吞掉,管网聚焦不再弹空详情卡

浏览器走查发现两处:

1. 六类字典全部没生效,风险等级显示成原码 1。
   根因:fetchSection 的 toData 已经把响应转成 {码:标签} 表,loadDictionaries 又对结果过一次
   toDictLabels(它只认行数组),于是六类都被当成「认不出的行」跳过,内存字典始终为空。
   改为直接交 setDictLabels(两种形状都收);测试同步改成真实形状,并补一条行数组用例,
   避免再用与线上不同的形状假绿。

2. 聚焦管网能飞到管段中点,但顺带弹出一个「设施详情未取到」的空卡。
   根因:定位走的是设施链路,会先按 facility 请求详情;管网是线段对象,详情接口 404。
   给 select 加 openDetail:false —— 只定位、不开详情;定位点仍由 resolveFacilityPoint
   从管线图层算出,不依赖详情。
ChenJZ 1 день назад
Родитель
Сommit
5c57b166e6

+ 2 - 1
src/modules/cockpit/CockpitShell.vue

@@ -1050,7 +1050,8 @@ function locateDeviceFromDetail(deviceCode) {
 function focusNetworkFromDetail(networkCode) {
     if (!networkCode) return false
     if (facilityDetailOpen.value) entityDetailStore.close()
-    return pointLocateStore.locateTarget({ kind: 'facility', code: networkCode, category: 'PIPE_NETWORK' })
+    // 管网是线段对象:只定位、不开设施详情(按 facility 请求详情会 404,弹出空卡)。
+    return pointLocateStore.locateTarget({ kind: 'facility', code: networkCode, category: 'PIPE_NETWORK' }, { openDetail: false })
 }
 
 function openLedgerCard(pointCode) {

+ 4 - 3
src/modules/cockpit/services/cockpitDict.js

@@ -82,9 +82,10 @@ export async function loadDictionaries(options = {}) {
     DICT_TYPE_LIST.forEach((type, index) => {
         const section = sections[index]
         if (!section || section.state !== 'success') return
-        const map = toDictLabels(section.data)
-        if (!map) return
-        setDictLabels(type, map)
+        // `fetchSection` 已经用 `toDictLabels` 把响应转成了标签表,
+        // 这里**不能**再过一遍行归一化(那样会把标签表当成"认不出的行"丢掉)。
+        // `setDictLabels` 两种形状都收,接不住就返回 false。
+        if (!setDictLabels(type, section.data)) return
         refreshed.push(type)
     })
     if (refreshed.length) saveDictSnapshot(options)

+ 20 - 7
src/modules/cockpit/stores/facilityPointStore.js

@@ -60,26 +60,39 @@ export const useFacilityPointStore = defineStore('facilityPointStore', () => {
         cancelPointLocate()
         useDetailStore().closeDetail()
         locate.value = { result: 'ok', pointCode: '', reasonText: '', at: Date.now() }
-        await entityStore.show(identity, prefill, options)
-        if (mine !== selectToken || !entityStore.open || !sameEntity(entityStore.identity, identity)) return false
-        const point = selectedPoint.value
+        /**
+         * `openDetail: false` = 只定位、不开设施详情。
+         *
+         * 关联管网聚焦要走这条:管网是线段对象,按 `facility` 去请求详情会 404,
+         * 用户看到的会是一个「设施详情未取到」的空卡。定位点本身仍由
+         * `resolveFacilityPoint` 从管线图层算出,不依赖详情。
+         */
+        const inline = options.openDetail === false
+        if (!inline) await entityStore.show(identity, prefill, options)
+        if (mine !== selectToken) return false
+        if (!inline && (!entityStore.open || !sameEntity(entityStore.identity, identity))) return false
+        const point = inline
+            ? resolveFacilityPoint({ identity, network: pipeStore.layer.data })
+            : selectedPoint.value
         const finish = (result, reasonText = '') => {
             locate.value = { result, pointCode: point?.code || identity.id, reasonText, at: Date.now() }
             return locate.value
         }
         if (!point || point.placement === 'pending') return finish('unavailable', point?.reasonText || '设施位置尚未取到,请稍后重试')
         if (point.placement !== 'drawn') return finish('blocked', point.reasonText || '设施没有可定位的地图位置')
-        if (!(renderPoints.value || []).some(row => row.key === point.key)) return finish('missing', '设施不在当前筛选范围,请调整筛选后定位')
+        // 只定位时不做「当前筛选内」的检查:管网本来就不在设施点图层里。
+        if (!inline && !(renderPoints.value || []).some(row => row.key === point.key)) return finish('missing', '设施不在当前筛选范围,请调整筛选后定位')
         let failure = TERRAIN_LOCATE_REASON.MAP
         let applied = false
         try {
             applied = await (options.fly || locateFacilityPoint)(point, {
                 tier: 'device', onFailure: reason => { failure = reason },
-                isCurrent: () => mine === selectToken && entityStore.open && sameEntity(entityStore.identity, identity)
-                    && (renderPoints.value || []).some(row => row.key === point.key),
+                isCurrent: () => mine === selectToken && (inline || (entityStore.open && sameEntity(entityStore.identity, identity)
+                    && (renderPoints.value || []).some(row => row.key === point.key))),
             })
         } catch { applied = false }
-        if (mine !== selectToken || !entityStore.open || !sameEntity(entityStore.identity, identity)) return false
+        if (mine !== selectToken) return false
+        if (!inline && (!entityStore.open || !sameEntity(entityStore.identity, identity))) return false
         return finish(applied === true ? 'ok' : 'unavailable', applied === true ? '' : locateFailureText(failure))
     }
 

+ 15 - 2
tests/cockpitDict.test.js

@@ -38,8 +38,9 @@ test('接口刷新成功后覆盖内存并写回快照', async () => {
     const result = await loadDictionaries({
         storage,
         now: () => 42,
+        // 真实形状:fetchSection 的 toData 已经把行数组转成了 { 码: 标签 } 表。
         fetchDict: async (type) => (type === DICT_TYPES.riskLevel
-            ? { state: 'success', data: [{ dictValue: '2', dictLabel: '一般风险' }] }
+            ? { state: 'success', data: { 2: '一般风险' } }
             : { state: 'failed', data: null }),
     })
     assert.deepEqual(result.refreshed, [DICT_TYPES.riskLevel])
@@ -75,12 +76,24 @@ test('快照损坏或版本不符时当作没有快照,界面回原码(字
     assert.equal(dictLabel(DICT_TYPES.riskLevel, '1'), '')
 })
 
+test('取数层直接给行数组时也能接住(两种形状都不丢)', async () => {
+    resetDictLabelsForTest()
+    const result = await loadDictionaries({
+        storage: null,
+        fetchDict: async (type) => (type === DICT_TYPES.riskLevel
+            ? { state: 'success', data: [{ dictValue: '0', dictLabel: '重大风险' }] }
+            : { state: 'failed', data: null }),
+    })
+    assert.deepEqual(result.refreshed, [DICT_TYPES.riskLevel])
+    assert.equal(dictLabel(DICT_TYPES.riskLevel, '0'), '重大风险')
+})
+
 test('localStorage 不可用(隐私模式)时退化为内存,不抛错', async () => {
     resetDictLabelsForTest()
     const result = await loadDictionaries({
         storage: null,
         fetchDict: async (type) => (type === DICT_TYPES.riskLevel
-            ? { state: 'success', data: [{ dictValue: '3', dictLabel: '低风险' }] }
+            ? { state: 'success', data: { 3: '低风险' } }
             : { state: 'failed', data: null }),
     })
     assert.deepEqual(result.refreshed, [DICT_TYPES.riskLevel])