ソースを参照

fix(cockpit): 删除关联管网主键展示并让管段资产详情按sourceId取数

ChenJZ 6 時間 前
親
コミット
77401e6e84

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

@@ -593,7 +593,7 @@ import { selectMonitoringPoint } from './pointSelection.js'
 import { planModeLayers, planModeSelectionTransition } from './domain/modeLayerPlan.js'
 import { PIPE_ENHANCEMENT_KIND, planPipeEnhancement } from './domain/pipeEnhancement.js'
 import { facilityAsComponent, facilityUndergroundTarget } from './domain/facilityUnderground.js'
-import { facilityBelongsToObject } from './domain/assetDetailKind.js'
+import { facilityBelongsToObject, pipeEnhancementFacilityIdentity } from './domain/assetDetailKind.js'
 // 票 48:图例计数纯函数(色值/词条/计数与地图管线同源的 domain 单源)。
 import { pipeColorCounts } from './domain/pipeVisual.js'
 import { usePipeEnhancementStore } from './stores/pipeEnhancementStore.js'
@@ -689,6 +689,7 @@ const enhancementFacilityState = computed(() => {
         error: Boolean(entityDetailStore.error),
     }
 })
+
 const runtimeStore = useRuntimeStore()
 const statusPanelExpanded = ref(false)
 const { mode, expandedPanelIds } = storeToRefs(uiStore)
@@ -1206,6 +1207,36 @@ const introVisible = ref(intro.value.enabled)
 const pipeEnhancementStore = usePipeEnhancementStore()
 const enhancementDevicesStore = useEnhancementDevicesStore()
 const { selected: pipeEnhancementSelection, radiusM: pipeEnhancementRadius } = storeToRefs(pipeEnhancementStore)
+
+/**
+ * 管段选中 → 现取一次「管道详情」(维护者 2026-11-16)。
+ *
+ * 用 `watch` 而不是只挂在点击处理函数上:3D 里的管段可以从多条路径被选中
+ * (管线拾取、附近管道列表、外部的 `pipeEnhancementStore.select`),
+ * 挂在单一入口必漏。取数沿用 `facilityPointStore.select`(同一条只读详情端点)。
+ *
+ * 取数主键用 `sourceId` 而不是 `code`:几何里管段
+ * `properties.code` 是业务编码、`properties.sourceId` 才是 `pipe_network_base` 主键,
+ * 拿编码去查详情会 404(实测 TCRQ202609080001 → raw_P11920)。
+ * `pipeEnhancementFacilityIdentity()` 负责从选中对象或可见管线里补出主键。
+ */
+watch(
+    () => `${pipeEnhancementSelection.value?.kind || ''}|${pipeEnhancementSelection.value?.code || ''}`,
+    () => {
+        const identity = pipeEnhancementFacilityIdentity(
+            pipeEnhancementSelection.value,
+            pipeNetworkStore.pipelines?.value ?? pipeNetworkStore.pipelines ?? [],
+        )
+        if (!identity) return
+        const current = entityDetailStore.identity
+        // 同一管段已取过就不重复请求(半径/筛选变化会反复触发本 watch)。
+        if (current && String(current.kind) === 'facility'
+            && String(current.category) === identity.category
+            && String(current.id) === identity.id) return
+        facilityPointStore.select(identity, null, { side: 'right' })
+    },
+    { immediate: true },
+)
 /** 选中的图例行 → 命中的设备编码集(与图例同一份设备台账;空集=不筛)。 */
 const deviceFilter = computed(() => deviceStatusStore.filterDeviceCodes(pointStatus.value))
 
@@ -1352,6 +1383,28 @@ function selectPipeEnhancement(hit) {
           : ''
     if (!kind) return
     pipeEnhancementStore.select(kind, hit.code)
+    loadPipeAssetDetail(kind, hit.code)
+}
+
+/**
+ * 管段选中时按自己的链现取一次「管道详情」(维护者 2026-11-16)。
+ *
+ * 为什么窨井不用这一步:窨井从设施点链进来,`entityDetailStore` 已有详情,
+ * 3D 视图按主键认回即可。管段从管线拾取链进来,`entityDetailStore` 从未被填充,
+ * 资产详情因此恒空 —— 这就是「井盖能显示、管道不显示」的根源。
+ *
+ * 详情取数沿用既有的 `facilityPointStore.select`(同一条 `/entities/{id}/detail` 只读端点),
+ * 不新造取数路径;失败按既有降级(资产详情显示取数提示,不阻塞 3D 场景)。
+ */
+function loadPipeAssetDetail(kind, code) {
+    const identity = pipeEnhancementFacilityIdentity({ kind, code })
+    if (!identity) return
+    const current = entityDetailStore.identity
+    // 同一个管段已经取过就不重复请求(切换半径/筛选时会被反复触发)。
+    if (current && String(current.kind) === 'facility'
+        && String(current.category) === identity.category
+        && String(current.id) === identity.id) return
+    facilityPointStore.select(identity, null, { side: 'right' })
 }
 
 /** 资产详情页签的设施重试:沿用实体详情的既有重试入口,不另造取数路径。 */

+ 34 - 0
src/modules/cockpit/domain/assetDetailKind.js

@@ -37,3 +37,37 @@ export function resolveAssetKind({ deviceCode = '', facilityDetail = null } = {}
     if (deviceCode) return 'device'
     return ''
 }
+
+/**
+ * 当前 3D 选中对象是否需要**现取一次**设施/管道详情(维护者 2026-11-16)。
+ *
+ * 两类资产进 3D 视图的路径不同,这就是「窨井能显示、管道不显示」的根源:
+ *   · 窨井(构件)—— 从设施点链进来,`entityDetailStore` 已有详情,
+ *     3D 视图只要按主键认回即可(`facilityBelongsToObject`),**不能再取一次**;
+ *   · 管段(pipe)—— 从管线拾取链进来,`entityDetailStore` 从未被填充,
+ *     资产详情恒空,必须现取 `PIPE_NETWORK` 详情。
+ *
+ * **取数主键是 `sourceId` 而不是 `code`**(实测):几何里管段的
+ * `properties.code` 是业务编码(TCRQ202609080001),`properties.sourceId` 才是
+ * `pipe_network_base` 的主键(raw_P11920)。用编码去查 `/entities/{id}/detail` 会 404。
+ *
+ * @param {{kind?: string, code?: string, sourceId?: string}|null} selection `pipeEnhancementStore.selected`
+ * @param {Array<object>} [visiblePipes] 当前可上图管线(用于把编码补成主键)
+ * @returns {{kind:'facility', id:string, category:'PIPE_NETWORK'}|null}
+ */
+export function pipeEnhancementFacilityIdentity(selection, visiblePipes = []) {
+    if (!selection) return null
+    if (String(selection.kind || '') !== 'pipe') return null
+    const code = typeof selection.code === 'string' ? selection.code.trim() : ''
+    if (!code) return null
+
+    // 优先用选中对象自带的 sourceId;退回可见管线里按编码查出的 sourceId;
+    // 两者都没有时**不猜**(返回 null,资产详情显示取数提示好过发一个注定 404 的请求)。
+    const own = typeof selection.sourceId === 'string' ? selection.sourceId.trim() : ''
+    let sourceId = own
+    if (!sourceId) {
+        const pipe = (Array.isArray(visiblePipes) ? visiblePipes : []).find((row) => row && row.code === code)
+        sourceId = pipe && typeof pipe.sourceId === 'string' ? pipe.sourceId.trim() : ''
+    }
+    return sourceId ? { kind: 'facility', id: sourceId, category: 'PIPE_NETWORK' } : null
+}

+ 0 - 1
src/modules/cockpit/domain/entityDetail.js

@@ -351,7 +351,6 @@ const ASSET_FIELD_ROWS = {
         { label: '井形', key: 'manholeShape', format: (v) => codedText(v, MANHOLE_SHAPE_TEXT) },
         { label: '材质', key: 'material' },
         { label: '权属单位', key: 'ownershipUnit' },
-        { label: '关联管网', key: 'networkId', format: (v) => (typeof v === 'string' && v.trim() ? v.trim() : '未关联') },
         { label: '备注', key: 'remark', wide: true },
     ],
     WATER_PLANT: [

+ 3 - 0
src/modules/cockpit/domain/facilityUnderground.js

@@ -38,6 +38,9 @@ export function facilityAsComponent(facility) {
     return {
         kind: type,
         code,
+        // 主键一路带到 3D 对象上(维护者 2026-11-16):资产详情的归属判据要按主键比对,
+        // 只有 code(设施编码)时,identity.id(UUID)与它永不相等,设施详情就永远是空。
+        sourceId: typeof facility.id === 'string' ? facility.id : '',
         name: facility.name || code,
         industry: type,
         position: [facility.longitude, facility.latitude],