Kaynağa Gözat

fix(cockpit): 关联设备定位行保留行业,补回中心类型徽标

设备卡契约没有 industry,强制揭示行 \`revealRow\` 又把它写成空串,
planMarker 的 innerIconFor('') 为空,DOM 标记只剩母版水滴、中心类型徽标丢失。
- pointLocateStore 从设备卡/档案补 industry,缺省继承所属点位
- deviceLayerStore.revealRow 透传 industry/typeName
- point-locate 补“设备卡无 industry 时继承点位”用例
ChenJZ 5 saat önce
ebeveyn
işleme
0a1e390ef4

+ 3 - 2
src/modules/cockpit/stores/deviceLayerStore.js

@@ -125,14 +125,15 @@ export const useDeviceLayerStore = defineStore('deviceLayerStore', () => {
             code: device.code,
             pointCode,
             name: device.name || device.code,
-            typeName: '',
+            typeName: device.typeName || '',
             status: device.status || '',
             statusLabel: visual.label,
             statusReasons: [],
             longitude: device.longitude,
             latitude: device.latitude,
             coordinate: device.coordinate,
-            industry: '',
+            // 内层类型徽标靠 industry;强制行也必须带上,否则中心只剩母版水滴。
+            industry: device.industry || '',
             placement: DEVICE_PLACEMENT.DRAWN,
             placementText: DEVICE_PLACEMENT_TEXT[DEVICE_PLACEMENT.DRAWN],
             reason: 'LOCATE_REVEAL',

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

@@ -58,13 +58,16 @@ export const usePointLocateStore = defineStore('pointLocateStore', () => {
     }
 
     /** 关联设备卡(点位详情 `devices[]` 的原始行)→ 可飞行的设备坐标对象。 */
-    function deviceFromCard(card) {
+    function deviceFromCard(card, fallbackIndustry = '') {
         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,
+            typeName: card.typeName || '',
+            // 设备卡契约实测没有 industry;必须继承所属点位,否则 DOM 标记中心的内层类型徽标会空。
+            industry: card.industry || fallbackIndustry || '',
             status: card.status || '',
             longitude: card.longitude,
             latitude: card.latitude,
@@ -73,7 +76,7 @@ export const usePointLocateStore = defineStore('pointLocateStore', () => {
     }
 
     /** 设备卡缺失/无坐标时的兜底:设备档案的经纬度。 */
-    async function deviceFromAggregate(deviceCode) {
+    async function deviceFromAggregate(deviceCode, fallbackIndustry = '') {
         try {
             const section = await detailStore.loadEquipmentAggregate(deviceCode)
             const archive = section && section.data && section.data.sections
@@ -83,6 +86,8 @@ export const usePointLocateStore = defineStore('pointLocateStore', () => {
                 kind: 'monitoring-device',
                 code: deviceCode,
                 name: archive.deviceName || deviceCode,
+                typeName: archive.typeName || '',
+                industry: fallbackIndustry || '',
                 status: '',
                 longitude: archive.longitude,
                 latitude: archive.latitude,
@@ -117,8 +122,13 @@ export const usePointLocateStore = defineStore('pointLocateStore', () => {
         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)
+            const pointDetail = detailStore.sections && detailStore.sections.pointDetail
+                && detailStore.sections.pointDetail.data
+            // 设备卡没有 industry,内层类型徽标继承所属点位(与正常关联设备行同一口径)。
+            const pointIndustry = (pointDetail && pointDetail.industry) || plan.object.industry || ''
+            if (!device) device = deviceFromCard(detailStore.deviceCard(plan.object.code, plan.deviceCode), pointIndustry)
+            if (!device) device = await deviceFromAggregate(plan.deviceCode, pointIndustry)
+            if (device && !device.industry) device = { ...device, industry: pointIndustry }
         }
 
         let failure = TERRAIN_LOCATE_REASON.MAP

+ 38 - 0
tests/point-locate.test.js

@@ -7,6 +7,7 @@ import { test } from 'node:test'
 import { createPinia, setActivePinia } from 'pinia'
 
 import { usePointLocateStore } from '../src/modules/cockpit/stores/pointLocateStore.js'
+import { useDetailStore } from '../src/modules/cockpit/stores/detailStore.js'
 import { workOrderRows } from '../src/modules/cockpit/domain/equipmentDetailView.js'
 import { planModeLayers } from '../src/modules/cockpit/domain/modeLayerPlan.js'
 
@@ -25,6 +26,7 @@ const point = {
     code: 'MP-131',
     name: '测试点位',
     status: 'ALARM',
+    industry: 'DRAINAGE',
     deviceCodes: ['DEV-131'],
     longitude: device.longitude,
     latitude: device.latitude,
@@ -55,6 +57,8 @@ test('关联设备定位:越过宿主点位飞到设备自身坐标,再进
         kind: 'monitoring-device',
         code: 'DEV-131',
         name: '测试设备',
+        typeName: '环境监测终端(污水)',
+        industry: 'DRAINAGE',
         status: 'NORMAL',
         longitude: device.longitude,
         latitude: device.latitude,
@@ -75,9 +79,43 @@ test('关联设备定位:越过宿主点位飞到设备自身坐标,再进
     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.equal(calls.selectDevice[0].options.locateTarget.device.industry, 'DRAINAGE')
     assert.deepEqual(calls.selectDevice[0].options.locateTarget.device, deviceTarget)
 })
 
+test('关联设备卡没有 industry 时继承点位,类型徽标不空', async () => {
+    setActivePinia(createPinia())
+    const detail = useDetailStore()
+    detail.setSection('pointDetail', {
+        state: 'success',
+        data: {
+            code: 'MP-131',
+            devices: [{
+                code: 'DEV-131',
+                name: '测试设备',
+                typeName: '环境监测终端(污水)',
+                status: 'NORMAL',
+                longitude: device.longitude,
+                latitude: device.latitude,
+                coordinate,
+            }],
+        },
+    })
+    const locator = usePointLocateStore()
+    let flown = null
+    const result = await locator.locateTarget({ kind: 'map-object', code: 'DEV-131' }, {
+        objects: [point],
+        mapReady: true,
+        openPoint: async () => {},
+        flyPoint: async (object) => { flown = object; return true },
+        selectDevice: async () => {},
+    })
+    assert.equal(result.result, 'ok')
+    assert.equal(flown.code, 'DEV-131')
+    assert.equal(flown.industry, 'DRAINAGE', '设备卡无 industry 时必须继承点位行业')
+    assert.equal(flown.typeName, '环境监测终端(污水)')
+})
+
 test('事件回联:走完整视角飞行 + 高亮,不再只换中心', async () => {
     setActivePinia(createPinia())
     const locator = usePointLocateStore()