فهرست منبع

fix(cockpit): 关联设备定位越过宿主点位并强制展开详情

- pointLocateStore 对关联设备先打开宿主点位详情取设备卡坐标,
  飞到设备自身坐标(device 150m);卡片缺失退设备档案 archive
- detailStore.locateTarget 携带设备坐标对象,供设备图层临时揭示
- deviceLayerStore 收到 revealDevice 时即使设备当前 NORMAL/模式本应隐藏,
  也生成可上图行并临时绘制;关闭/换设备/切模式/改筛选恢复
- point-locate 回归补关联设备坐标与 NORMAL 揭示用例
ChenJZ 1 روز پیش
والد
کامیت
69e05f6a77

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

@@ -1231,6 +1231,8 @@ function syncDeviceLayer(options = {}) {
             .some((item) => item.code === selection.value.pointCode),
         maxFan,
         filterActive: deviceFilterActive.value,
+        // #131:关联设备定位时把揭示目标(含设备自身坐标)交给设备图层,正常/离线也能临时上图。
+        revealDevice: detailStore.locateTarget,
     })
 }
 
@@ -1356,7 +1358,10 @@ const modeLayerPlan = computed(() => planModeLayers({
 }))
 
 // 模式/图例筛选变化:定位揭示必须收场,旧目标不能越过新筛选继续强制显示。
-watch([mode, pointStatus], () => detailStore.clearLocateTarget())
+watch([mode, pointStatus], () => {
+    detailStore.clearLocateTarget()
+    if (selection.value.pointCode) syncDeviceLayer({ force: true })
+})
 
 // 设备状态池到达/刷新:关联设备图层按「基础属性 + 标签」显示状态重算。
 // 选中点位时设备池可能还没回来;池到达后不能停在旧的单一状态上。

+ 14 - 1
src/modules/cockpit/stores/detailStore.js

@@ -103,8 +103,13 @@ export const useDetailStore = defineStore('detailStore', () => {
     /** 写入/清除定位揭示目标;调用方只在定位成功的打开动作里传对象。 */
     function setLocateTarget(target) {
         const code = String((target && target.code) || '').trim()
+        const device = target && target.device && typeof target.device === 'object' ? { ...target.device } : null
         locateTarget.value = code
-            ? { code, deviceCode: String(target.deviceCode || '').trim() }
+            ? {
+                code,
+                deviceCode: String(target.deviceCode || '').trim(),
+                ...(device ? { device } : {}),
+            }
             : null
     }
 
@@ -112,6 +117,13 @@ export const useDetailStore = defineStore('detailStore', () => {
         locateTarget.value = null
     }
 
+    /** 从已加载的点位详情里取某台设备的**原始卡片**(含自身坐标/校验);找不到回 null。 */
+    function deviceCard(pointCode, deviceCode) {
+        const data = sections.value.pointDetail && sections.value.pointDetail.data
+        if (!data || data.code !== pointCode || !Array.isArray(data.devices)) return null
+        return data.devices.find((item) => item && item.code === deviceCode) || null
+    }
+
     /**
      * 把 `mapStore` 的渐进加载状态同步成「地图摘要」分区状态(票 08)。
      *
@@ -465,6 +477,7 @@ export const useDetailStore = defineStore('detailStore', () => {
         setSection,
         setLocateTarget,
         clearLocateTarget,
+        deviceCard,
         syncMapSnapshotSection,
         loadSharedSections,
         loadPointDetail,

+ 57 - 5
src/modules/cockpit/stores/deviceLayerStore.js

@@ -19,7 +19,10 @@ import { markRaw, ref, shallowRef } from 'vue'
 import { defineStore } from 'pinia'
 import {
     DEVICE_LAYER_KIND,
+    DEVICE_PLACEMENT,
+    DEVICE_PLACEMENT_TEXT,
     associatedLegend,
+    countPlacements,
     crossEndpointNotice,
     planAssociatedDevices,
     uniqueCodes,
@@ -113,6 +116,37 @@ export const useDeviceLayerStore = defineStore('deviceLayerStore', () => {
         return list.filter((row) => row.placement === 'drawn')
     }
 
+    /** #131:定位关联设备时,即使它在当前模式/状态本应隐藏,也生成一条可上图行。 */
+    function revealRow(device, pointCode) {
+        if (!device || !Number.isFinite(device.longitude) || !Number.isFinite(device.latitude)) return null
+        const visual = deviceVisualForStatus(device.status)
+        const asset = planDeviceAsset({ device })
+        return {
+            code: device.code,
+            pointCode,
+            name: device.name || device.code,
+            typeName: '',
+            status: device.status || '',
+            statusLabel: visual.label,
+            statusReasons: [],
+            longitude: device.longitude,
+            latitude: device.latitude,
+            coordinate: device.coordinate,
+            industry: '',
+            placement: DEVICE_PLACEMENT.DRAWN,
+            placementText: DEVICE_PLACEMENT_TEXT[DEVICE_PLACEMENT.DRAWN],
+            reason: 'LOCATE_REVEAL',
+            inSnapshot: true,
+            shape: asset.shape,
+            size: asset.size,
+            assetMode: asset.mode,
+            assetReason: asset.reason,
+            assetReasonText: asset.reasonText,
+            visualKey: asset.visualKey,
+            tone: visual.tone,
+        }
+    }
+
     function planKeyOf(code, drawn, maxFan = 10, effects = null) {
         return JSON.stringify([code, maxFan, effects, drawn.map((row) => [
             row.code, row.longitude, row.latitude, row.status, row.shape, row.size,
@@ -258,14 +292,32 @@ export const useDeviceLayerStore = defineStore('deviceLayerStore', () => {
         })
 
         pointCode.value = code
-        rows.value = markRaw(withAssets)
-        counts.value = plan.counts
+        // #131:关联设备定位时,即使它当前状态(NORMAL)/模式本应隐藏,也临时补一条可上图行。
+        const reveal = options.revealDevice && options.revealDevice.deviceCode ? options.revealDevice : null
+        let layerRows = withAssets
+        if (reveal) {
+            const forced = reveal.device ? revealRow(reveal.device, reveal.code) : null
+            if (forced) {
+                layerRows = [...layerRows.filter((row) => row.code !== reveal.deviceCode), forced]
+            } else {
+                layerRows = layerRows.map((row) => (row.code === reveal.deviceCode && row.placement !== DEVICE_PLACEMENT.DRAWN
+                    ? {
+                        ...row,
+                        placement: DEVICE_PLACEMENT.DRAWN,
+                        placementText: DEVICE_PLACEMENT_TEXT[DEVICE_PLACEMENT.DRAWN],
+                        reason: 'LOCATE_REVEAL',
+                    }
+                    : row))
+            }
+        }
+        rows.value = markRaw(layerRows)
+        counts.value = countPlacements(layerRows)
         // 总数=当前快照去重 deviceCodes 条数(**不是** rows.length:清单含详情独有那几行)。
         total.value = plan.total
-        legend.value = associatedLegend(plan.counts)
-        notice.value = crossEndpointNotice(plan.rows)
+        legend.value = associatedLegend(counts.value)
+        notice.value = crossEndpointNotice(layerRows)
 
-        const drawn = renderableRows(withAssets)
+        const drawn = renderableRows(layerRows)
         const groups = groupOverlappingDevices(drawn, { maxFan: options.maxFan, total: plan.total })
         const activeGroups = groups.filter((group) => group && group.k > 1)
         overlap.value = {

+ 57 - 4
src/modules/cockpit/stores/pointLocateStore.js

@@ -57,6 +57,42 @@ export const usePointLocateStore = defineStore('pointLocateStore', () => {
         return [...associated, ...(mapStore.summary.objects || [])]
     }
 
+    /** 关联设备卡(点位详情 `devices[]` 的原始行)→ 可飞行的设备坐标对象。 */
+    function deviceFromCard(card) {
+        if (!card || !Number.isFinite(card.longitude) || !Number.isFinite(card.latitude)) return null
+        if (card.coordinate && card.coordinate.renderable === false) return null
+        return {
+            kind: 'monitoring-device',
+            code: card.code,
+            name: card.name || card.code,
+            status: card.status || '',
+            longitude: card.longitude,
+            latitude: card.latitude,
+            coordinate: card.coordinate || { state: 'VALID', renderable: true, crs: 'WGS84' },
+        }
+    }
+
+    /** 设备卡缺失/无坐标时的兜底:设备档案的经纬度。 */
+    async function deviceFromAggregate(deviceCode) {
+        try {
+            const section = await detailStore.loadEquipmentAggregate(deviceCode)
+            const archive = section && section.data && section.data.sections
+                && section.data.sections.archive && section.data.sections.archive.data
+            if (!archive || !Number.isFinite(archive.longitude) || !Number.isFinite(archive.latitude)) return null
+            return {
+                kind: 'monitoring-device',
+                code: deviceCode,
+                name: archive.deviceName || deviceCode,
+                status: '',
+                longitude: archive.longitude,
+                latitude: archive.latitude,
+                coordinate: { state: 'VALID', renderable: true, crs: archive.coordinateSystem || 'WGS84' },
+            }
+        } catch {
+            return null
+        }
+    }
+
     async function locateMapObject(code, options = {}) {
         const objects = options.objects || mapStore.summary.objects
         const mapReady = options.mapReady === undefined ? !!getCameraState() : !!options.mapReady
@@ -75,17 +111,34 @@ export const usePointLocateStore = defineStore('pointLocateStore', () => {
         }
         if (plan.result !== LOCATE_RESULT.OK) return setLocate(base)
 
+        // #131 补充:关联设备要**越过宿主监测点**直接飞到设备自己的坐标。
+        // 设备坐标不在 map-snapshot(关联设备不带坐标),必须先打开宿主点位详情,
+        // 从设备卡取 `longitude/latitude/coordinateValidation`;卡片缺失再退到设备档案。
+        let device = options.device || null
+        if (plan.object.kind === MAP_OBJECT_KIND.MONITORING_POINT && plan.deviceCode) {
+            await openPoint(plan.object.code)
+            if (!device) device = deviceFromCard(detailStore.deviceCard(plan.object.code, plan.deviceCode))
+            if (!device) device = await deviceFromAggregate(plan.deviceCode)
+        }
+
         let failure = TERRAIN_LOCATE_REASON.MAP
-        const applied = await flyPoint(plan.object, { onFailure: (reason) => { failure = reason } })
+        const applied = await flyPoint(device || plan.object, {
+            ...(device ? { tier: 'device' } : {}),
+            onFailure: (reason) => { failure = reason },
+        })
         if (applied !== true) {
             return setLocate({ ...base, result: LOCATE_RESULT.UNAVAILABLE, reasonText: locateFailureText(failure) })
         }
 
-        // 揭示目标 = 实际飞到的地图对象(关联设备是宿主点位),由 #127 的模式计划临时放行。
-        const reveal = { code: plan.object.code, deviceCode: plan.deviceCode || '' }
+        // 揭示目标 = 实际飞到的对象;关联设备把设备坐标一起带给设备图层,
+        // 使它在当前模式/状态(例如 NORMAL)下也能临时画出并锚定详情。
+        const reveal = {
+            code: plan.object.code,
+            deviceCode: plan.deviceCode || '',
+            ...(device ? { device } : {}),
+        }
         if (plan.object.kind === MAP_OBJECT_KIND.MONITORING_POINT) {
             if (plan.deviceCode) {
-                await openPoint(plan.object.code)
                 await selectDevice(plan.deviceCode, { locateTarget: reveal })
             } else {
                 await openPoint(plan.object.code, { locateTarget: reveal })

+ 48 - 7
tests/point-locate.test.js

@@ -8,6 +8,7 @@ import { createPinia, setActivePinia } from 'pinia'
 
 import { usePointLocateStore } from '../src/modules/cockpit/stores/pointLocateStore.js'
 import { workOrderRows } from '../src/modules/cockpit/domain/equipmentDetailView.js'
+import { planModeLayers } from '../src/modules/cockpit/domain/modeLayerPlan.js'
 
 const coordinate = { state: 'VALID', reason: null, renderable: true, crs: 'WGS84' }
 const device = {
@@ -46,23 +47,35 @@ test('设备定位:走完整视角、打开设备详情并写揭示目标', as
     assert.deepEqual(calls.openDevice[0], { code: 'DEV-131', options: { locateTarget: { code: 'DEV-131', deviceCode: '' } } })
 })
 
-test('关联设备定位:先开宿主点位、再进设备级,揭示宿主点位', async () => {
+test('关联设备定位:越过宿主点位飞到设备自身坐标,再进设备级', async () => {
     setActivePinia(createPinia())
     const locator = usePointLocateStore()
-    const calls = { openPoint: [], selectDevice: [] }
+    const calls = { fly: [], openPoint: [], selectDevice: [] }
+    const deviceTarget = {
+        kind: 'monitoring-device',
+        code: 'DEV-131',
+        name: '测试设备',
+        status: 'NORMAL',
+        longitude: device.longitude,
+        latitude: device.latitude,
+        coordinate,
+    }
     const result = await locator.locateTarget({ kind: 'map-object', code: 'DEV-131' }, {
         objects: [point],
         mapReady: true,
-        flyPoint: async () => true,
+        device: deviceTarget,
+        flyPoint: async (object, options) => { calls.fly.push({ object, options }); return true },
         openPoint: async (code, options) => { calls.openPoint.push({ code, options }) },
         selectDevice: async (code, options) => { calls.selectDevice.push({ code, options }) },
     })
     assert.equal(result.result, 'ok')
+    assert.equal(calls.fly[0].object.code, 'DEV-131', '应飞设备自身坐标,而不是宿主点位')
+    assert.equal(calls.fly[0].options.tier, 'device')
     assert.deepEqual(calls.openPoint[0], { code: 'MP-131', options: undefined })
-    assert.deepEqual(calls.selectDevice[0], {
-        code: 'DEV-131',
-        options: { locateTarget: { code: 'MP-131', deviceCode: 'DEV-131' } },
-    })
+    assert.equal(calls.selectDevice[0].code, 'DEV-131')
+    assert.equal(calls.selectDevice[0].options.locateTarget.code, 'MP-131')
+    assert.equal(calls.selectDevice[0].options.locateTarget.deviceCode, 'DEV-131')
+    assert.deepEqual(calls.selectDevice[0].options.locateTarget.device, deviceTarget)
 })
 
 test('事件回联:走完整视角飞行 + 高亮,不再只换中心', async () => {
@@ -86,4 +99,32 @@ test('工单行保留设备编码,供工单卡定位按钮使用', () => {
     const rows = workOrderRows([{ code: 'WO-131', deviceName: '测试设备', deviceCode: 'DEV-131', stateCode: 3 }])
     assert.equal(rows[0].deviceCode, 'DEV-131')
     assert.ok(rows[0].deviceLabel.includes('DEV-131'))
+})
+
+test('关联设备 NORMAL:定位揭示必须让详情越过模式暂停', () => {
+    const host = {
+        kind: 'monitoring-point',
+        code: 'MP-131',
+        name: '测试点位',
+        status: 'NORMAL',
+        deviceCodes: ['DEV-131'],
+        longitude: device.longitude,
+        latitude: device.latitude,
+        coordinate,
+    }
+    const row = { code: 'DEV-131', pointCode: 'MP-131', status: 'NORMAL', placement: 'drawn' }
+    const selection = { level: 'equipment', pointCode: 'MP-131', deviceCode: 'DEV-131' }
+    const base = {
+        mode: 'warningResponse',
+        objects: [host],
+        abnormalDevices: [],
+        deviceFacts: [{ deviceCode: 'DEV-131', base: 'NORMAL', tags: [] }],
+        associatedDevices: [row],
+        selection,
+        entered: true,
+    }
+    assert.equal(planModeLayers(base).selection.visible, false, '未定位时 NORMAL 关联设备在预警处置应暂停')
+    const located = planModeLayers({ ...base, locateTarget: { code: 'MP-131', deviceCode: 'DEV-131' } })
+    assert.ok(located.markers.some((marker) => marker.code === 'MP-131'), '定位揭示应把宿主点位标记临时放行')
+    assert.equal(located.selection.visible, true, '定位揭示必须让 NORMAL 关联设备的详情可见')
 })