Browse Source

fix(cockpit): 关联项独占整行生效,聚焦管网补出设施卡与图标,独立设备补开详情

- 上一轮三处关联项设了 wide 却没生效:assetRows 里引用的 return 把 wide 硬编码成 false,
  覆盖了字段表里的标记。改为沿用 row.wide,并补一条断言防止再退化。
- 聚焦管网补全「设施定位那三件事」:打开设施详情卡(内容先用管线图层的名称/类型/管径/坐标做 prefill,
  详情端点对管网是 404,失败时卡片保留这份摘要而不是空白)+ 设施图标(由选中点派生)+ 飞到管段中点。
  飞行仍走不参与竞态令牌的 focusFacilityPoint。
- 独立设备定位:plan.pointCode 为空时用设备编码自己进设备级详情,否则 openDevice('') 打不开任何东西。
  揭示目标的 deviceCode 语义不动(modeLayerPlan 用它区分「关联设备」与「独立设备」,后者靠 code 揭示)。
ChenJZ 1 day ago
parent
commit
1dcded46fa

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

@@ -1095,6 +1095,43 @@ function openRelationFromDetail(item) {
     return false
 }
 
+/**
+ * 管段 → 设施详情卡的 prefill。
+ *
+ * 管网没有自己的详情端点(实测按 category=PIPE_NETWORK 请求 404),所以卡片内容
+ * 先从管线图层带出来;随后那次详情请求失败时,卡片保留这份摘要,而不是一片空白。
+ */
+function networkPrefill(networkCode) {
+    const pipes = (pipeNetworkStore.layer.data && pipeNetworkStore.layer.data.pipes) || []
+    const pipe = pipes.find((item) => item && item.code === networkCode)
+    if (!pipe) return null
+    const line = Array.isArray(pipe.sourceCoordinates) ? pipe.sourceCoordinates : []
+    const first = line[0] || null
+    const last = line[line.length - 1] || null
+    return {
+        code: pipe.code,
+        name: pipe.name || pipe.code,
+        category: 'PIPE_NETWORK',
+        location: pipe.remark || '',
+        coordinates: first && last
+            ? { longitude: first[0], latitude: first[1], endLongitude: last[0], endLatitude: last[1] }
+            : null,
+        attributes: {
+            networkType: pipe.networkType,
+            networkLevel: pipe.networkLevel,
+            diameterMillimeters: pipe.diameter,
+            remark: pipe.remark,
+        },
+    }
+}
+
+/**
+ * 关联管网聚焦 = 复用设施那条链的三件事:**打开设施详情卡 + 画出设施图标 + 飞到管段中点**。
+ *
+ * 为什么不用 `locateFacility`:那条路走 `facilityPointStore.select` 的竞态令牌,
+ * 详情关闭或并发选择会把本次调用判成过期并返回 false(表现为「设施定位未完成」)。
+ * 这里把三件事拆开各自确定性执行,飞行交给不参与令牌的 `focusFacilityPoint`。
+ */
 async function focusNetworkFromDetail(networkCode) {
     if (!networkCode) return false
     if (facilityDetailOpen.value) entityDetailStore.close()
@@ -1106,12 +1143,13 @@ async function focusNetworkFromDetail(networkCode) {
             // 取不到就让下面的定位把原因如实说出来,不静默。
         }
     }
-    // 只飞行、不开详情:走独立入口,不参与设施定位的竞态令牌
-    // (旧路径会因详情关闭/并发选择被判过期,表现为「设施定位未完成」)。
-    return pointLocateStore.focusFacilityPoint(
-        { kind: 'facility', id: networkCode, category: 'PIPE_NETWORK' },
-        { network: pipeNetworkStore.layer.data },
-    )
+    const identity = { kind: 'facility', id: networkCode, category: 'PIPE_NETWORK' }
+    // 打开卡片与飞行并行:卡片一打开,设施图标就由 facilityPointStore 的选中点派生出来。
+    const [located] = await Promise.all([
+        pointLocateStore.focusFacilityPoint(identity, { network: pipeNetworkStore.layer.data }),
+        entityDetailStore.show(identity, networkPrefill(networkCode)),
+    ])
+    return located
 }
 
 function openLedgerCard(pointCode) {

+ 8 - 6
src/modules/cockpit/domain/entityDetail.js

@@ -783,22 +783,24 @@ function assetRows(rows, category, a) {
         // 码值字段:业务库字典是唯一权威,没取到就回原码(不回显 0/1/2 之外的编造词)。
         if (row.dict) return field(row.label, dictOrCode(row.dict, a[row.key]), row.wide === true)
         // 关联管网:后端下发 name + code 时显示「名称(编码)」并给聚焦入口;否则如实「未提供」。
+        // 引用行沿用字段表里的 wide 标记:三类引用都是「名称(编码)+ 按钮」,必须独占整行。
+        const wide = row.wide === true
         if (row.key === 'network') {
             const ref = networkReference(a)
-            if (!ref) return field(row.label, '未提供')
-            return field(row.label, ref.label, false, { action: ref.code ? { kind: 'focus-network', code: ref.code } : null })
+            if (!ref) return field(row.label, '未提供', wide)
+            return field(row.label, ref.label, wide, { action: ref.code ? { kind: 'focus-network', code: ref.code } : null })
         }
         // 关联设备:显示「名称(编码)」,有编码才能定位。
         if (row.key === 'equipment') {
             const ref = equipmentReference(a)
-            if (!ref) return field(row.label, '未提供')
-            return field(row.label, ref.label, false, { action: ref.code ? { kind: 'locate-equipment', code: ref.code } : null })
+            if (!ref) return field(row.label, '未提供', wide)
+            return field(row.label, ref.label, wide, { action: ref.code ? { kind: 'locate-equipment', code: ref.code } : null })
         }
         // 关联工单:显示工单号并可打开卡片。
         if (row.key === 'workOrder') {
             const ref = workOrderReference(a)
-            if (!ref) return field(row.label, '未提供')
-            return field(row.label, ref.label, false, { action: { kind: 'open-work-order', code: ref.code } })
+            if (!ref) return field(row.label, '未提供', wide)
+            return field(row.label, ref.label, wide, { action: { kind: 'open-work-order', code: ref.code } })
         }
         // 风险因素:能解析成键值就出网格;非法 JSON / 纯文本原样展示。
         if (row.pairs) {

+ 2 - 1
src/modules/cockpit/stores/pointLocateStore.js

@@ -156,7 +156,8 @@ export const usePointLocateStore = defineStore('pointLocateStore', () => {
                 await openPoint(plan.object.code, { locateTarget: reveal })
             }
         } else {
-            await openDevice(plan.pointCode, { locateTarget: reveal })
+            // 独立设备没有宿主点位:直接用设备编码进设备级详情(openDevice('') 打不开任何东西)。
+            await openDevice(plan.pointCode || code, { locateTarget: reveal })
         }
         return setLocate({ ...base, result: LOCATE_RESULT.OK, reasonText: '' })
     }

+ 8 - 0
tests/entityDetailHazard.test.js

@@ -86,6 +86,14 @@ test('字典没取到时回原码,不编「未知」', () => {
     assert.equal(view.levelTone, 'risk-2')
 })
 
+test('关联信息三项各占整行(名称+编码+按钮,半栏放不下)', () => {
+    const rows = relatedRows(hazardView())
+    for (const label of ['关联管网', '关联设备', '关联工单']) {
+        const row = rows.find((item) => item.label === label)
+        assert.equal(row.wide, true, label + ' 没有独占整行')
+    }
+})
+
 test('关联设备显示「名称(编码)」并给定位入口', () => {
     const row = relatedOf(hazardView(), '关联设备')
     assert.equal(row.value, '可燃气体-022(2607230190000022)')