Jelajahi Sumber

fix(cockpit): 关联联动三项独占整行,管网聚焦改独立飞行入口,工单按主键打开

- 隐患台账「关联信息」的管网/设备/工单三项各自独占整行:三项都是「名称(编码)+ 联动按钮」,
  半栏放不下会折行。
- 聚焦管网不再复用设施定位入口:那条路走 facilityPointStore.select 的竞态令牌,
  详情关闭或并发选择会把本次调用判成过期并返回 false,界面只看到「设施定位未完成」。
  新增 pointLocateStore.focusFacilityPoint:只解析点位 + 飞行,不参与令牌;
  失败时如实给出「地图尚未就绪」或「尚未取到该对象的可定位几何」。
- 关联工单:工单详情按**数字主键**取(后端按工单号请求实测 400),
  打开前先用工单列表按编号反查出主键,取不到才退回按编号打开并如实显示「详情暂未取到」。
ChenJZ 1 hari lalu
induk
melakukan
c8c34ca594

+ 30 - 5
src/modules/cockpit/CockpitShell.vue

@@ -631,6 +631,7 @@ 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 { loadDictionaries } from './services/cockpitDict.js'
+import { fetchWorkOrderList } from './services/detailApi.js'
 import { setPumpTypeLabels } from './domain/facilityTypeDict.js'
 import {
     atHome,
@@ -1048,11 +1049,31 @@ function locateDeviceFromDetail(deviceCode) {
  * `resolveFacilityPoint` 对 PIPE_NETWORK 已按 sourceId/networkId 从管线图层解析位置,
  * 所以管网走的就是同一条飞行与高亮链;解析不到时由统一反馈如实说明原因,不静默。
  */
-/** 详情里的「关联工单」:打开只读工单详情(与台账卡同一入口)。 */
-function openWorkOrderFromDetail(workOrderCode) {
+/**
+ * 关联工单只给了工单号,而工单详情是按**数字主键**取的(后端实测按编号请求 400)。
+ * 工单列表总量只有几十条,取一页足够大的再按编号匹配出主键即可,不必翻页。
+ */
+async function resolveWorkOrderId(workOrderCode) {
+    try {
+        const section = await fetchWorkOrderList({ page: 1, pageSize: 200 })
+        const orders = (section && section.data && section.data.orders) || []
+        const hit = orders.find((order) => order.code === workOrderCode)
+        return hit && hit.id ? String(hit.id) : ''
+    } catch {
+        return ''
+    }
+}
+
+/** 详情里的「关联工单」:反查主键后打开只读工单详情(与台账卡同一入口)。 */
+async function openWorkOrderFromDetail(workOrderCode) {
     if (!workOrderCode) return false
     if (facilityDetailOpen.value) entityDetailStore.close()
-    return entityDetailStore.show({ kind: 'work-order', id: workOrderCode })
+    const orderId = await resolveWorkOrderId(workOrderCode)
+    // 反查不到(工单被删或超出列表范围)时仍按编号打开,由卡片如实说「详情暂未取到」。
+    return entityDetailStore.show(
+        { kind: 'work-order', id: orderId || workOrderCode },
+        orderId ? { orderId } : {},
+    )
 }
 
 /** 关联信息行 → 对应详情;预警/报警按业务编号,工单优先内部 orderId。 */
@@ -1085,8 +1106,12 @@ async function focusNetworkFromDetail(networkCode) {
             // 取不到就让下面的定位把原因如实说出来,不静默。
         }
     }
-    // 管网是线段对象:只定位、不开设施详情(按 facility 请求详情会 404,弹出空卡)。
-    return pointLocateStore.locateTarget({ kind: 'facility', code: networkCode, category: 'PIPE_NETWORK' }, { openDetail: false })
+    // 只飞行、不开详情:走独立入口,不参与设施定位的竞态令牌
+    // (旧路径会因详情关闭/并发选择被判过期,表现为「设施定位未完成」)。
+    return pointLocateStore.focusFacilityPoint(
+        { kind: 'facility', id: networkCode, category: 'PIPE_NETWORK' },
+        { network: pipeNetworkStore.layer.data },
+    )
 }
 
 function openLedgerCard(pointCode) {

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

@@ -609,9 +609,10 @@ const ASSET_FIELD_ROWS = {
 
 /** 危险源的三个业务引用:单独成一张表,放进「关联信息」页签。 */
 const HAZARD_RELATED_ROWS = [
-    { label: '关联管网', key: 'network' },
-    { label: '关联设备', key: 'equipment' },
-    { label: '关联工单', key: 'workOrder' },
+    // 每项独占整行(维护者 2026-12-01):三项都带「名称(编码)」+ 联动按钮,半栏放不下。
+    { label: '关联管网', key: 'network', wide: true },
+    { label: '关联设备', key: 'equipment', wide: true },
+    { label: '关联工单', key: 'workOrder', wide: true },
 ]
 
 /** 读数 + 单位(认不出的值留给 field() 变占位符,不拼半截 "— m")。 */

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

@@ -23,12 +23,14 @@ import {
     getAssociatedDeviceState,
     getCameraState,
     highlightMapObject,
+    locateFacilityPoint,
     locateMonitoringPoint,
 } from '../services/mapService.js'
 import { LOCATE_RESULT, locateFailureText, planLocate } from '../domain/mapLocate.js'
 import { EVENT_DETAIL_RESULT, planEventLocate } from '../domain/eventDetail.js'
 import { TERRAIN_LOCATE_REASON } from '../domain/pointLocate.js'
 import { MAP_OBJECT_KIND } from '../domain/mapSummary.js'
+import { facilityIdentity, resolveFacilityPoint } from '../domain/facilitySelection.js'
 
 const EMPTY_RESULT = { result: '', code: '', pointCode: '', deviceCode: '', reasonText: '', at: 0 }
 
@@ -213,6 +215,43 @@ export const usePointLocateStore = defineStore('pointLocateStore', () => {
         })
     }
 
+    /**
+     * 只把相机飞到某个设施/线段对象,**不开详情**。
+     *
+     * 为什么不复用 `locateFacility`:那条路走 `facilityPointStore.select` 的竞态令牌,
+     * 详情关闭或其它选择会让本次调用被判成过期而返回 false(界面表现为「设施定位未完成」)。
+     * 关联管网聚焦只需要「解析点位 + 飞行」,单开一条不参与令牌的入口最稳。
+     *
+     * @param {object} identityInput `{ kind: 'facility', id, category }`
+     * @param {{ network?: object }} [options] `network` 是管线图层数据(算线段中点用)
+     */
+    async function focusFacilityPoint(identityInput, options = {}) {
+        const identity = facilityIdentity(identityInput)
+        if (!identity.valid) {
+            return setLocate({ result: LOCATE_RESULT.UNAVAILABLE, code: (identityInput && identityInput.id) || '', reasonText: '该对象没有可定位的类型' })
+        }
+        const point = resolveFacilityPoint({ identity, network: options.network })
+        if (!point || point.placement === 'pending') {
+            return setLocate({ result: LOCATE_RESULT.UNAVAILABLE, code: identity.id, reasonText: point?.reasonText || '尚未取到该对象的可定位几何' })
+        }
+        if (point.placement !== 'drawn') {
+            return setLocate({ result: LOCATE_RESULT.BLOCKED, code: identity.id, reasonText: point.reasonText || '该对象没有可定位的地图位置' })
+        }
+        let failure = TERRAIN_LOCATE_REASON.MAP
+        let applied = false
+        try {
+            applied = await locateFacilityPoint(point, { tier: 'device', onFailure: (reason) => { failure = reason } })
+        } catch {
+            applied = false
+        }
+        return setLocate({
+            result: applied === true ? LOCATE_RESULT.OK : LOCATE_RESULT.UNAVAILABLE,
+            code: identity.id,
+            pointCode: point.code || identity.id,
+            reasonText: applied === true ? '' : locateFailureText(failure),
+        })
+    }
+
     /**
      * 唯一入口:按目标身份定位。`options` 只给测试/特殊链路注入(objects / flyPoint / openPoint…),
      * 业务调用方不传。
@@ -224,5 +263,5 @@ export const usePointLocateStore = defineStore('pointLocateStore', () => {
         return locateMapObject(target.code, options)
     }
 
-    return { locate, locateTarget, clearLocate }
+    return { locate, locateTarget, focusFacilityPoint, clearLocate }
 })