| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- /**
- * #131 通用点位定位回归:设备/监测点/事件回联都从 `pointLocateStore.locateTarget` 进入;
- * 工单行保留 deviceCode 供定位按钮使用。
- */
- import assert from 'node:assert/strict'
- 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'
- const coordinate = { state: 'VALID', reason: null, renderable: true, crs: 'WGS84' }
- const device = {
- kind: 'unassociated-equipment',
- code: 'DEV-131',
- name: '测试设备',
- status: 'ALARM',
- longitude: 110.410194,
- latitude: 28.445044,
- coordinate,
- }
- const point = {
- kind: 'monitoring-point',
- code: 'MP-131',
- name: '测试点位',
- status: 'ALARM',
- industry: 'DRAINAGE',
- deviceCodes: ['DEV-131'],
- longitude: device.longitude,
- latitude: device.latitude,
- coordinate,
- }
- test('设备定位:走完整视角、打开设备详情并写揭示目标', async () => {
- setActivePinia(createPinia())
- const locator = usePointLocateStore()
- const calls = { fly: [], openDevice: [] }
- const result = await locator.locateTarget({ kind: 'map-object', code: 'DEV-131' }, {
- objects: [device],
- mapReady: true,
- flyPoint: async (object, options) => { calls.fly.push({ object, options }); return true },
- openDevice: async (code, options) => { calls.openDevice.push({ code, options }) },
- })
- assert.equal(result.result, 'ok')
- assert.equal(calls.fly.length, 1)
- assert.equal(calls.fly[0].object.code, 'DEV-131')
- assert.deepEqual(calls.openDevice[0], { code: 'DEV-131', options: { locateTarget: { code: 'DEV-131', deviceCode: '' } } })
- })
- test('关联设备定位:越过宿主点位飞到设备自身坐标,再进设备级', async () => {
- setActivePinia(createPinia())
- const locator = usePointLocateStore()
- const calls = { fly: [], openPoint: [], selectDevice: [] }
- const deviceTarget = {
- kind: 'monitoring-device',
- code: 'DEV-131',
- name: '测试设备',
- typeName: '环境监测终端(污水)',
- industry: 'DRAINAGE',
- status: 'NORMAL',
- longitude: device.longitude,
- latitude: device.latitude,
- coordinate,
- }
- const result = await locator.locateTarget({ kind: 'map-object', code: 'DEV-131' }, {
- objects: [point],
- mapReady: 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.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()
- const calls = { fly: [], highlight: [] }
- const event = { code: 'E-131', deviceCode: 'DEV-131', monitoringPointCode: null, coordinate: { validated: true, renderable: true } }
- const result = await locator.locateTarget({ kind: 'event', event }, {
- objects: [device],
- mapReady: true,
- flyPoint: async (object, options) => { calls.fly.push({ object, options }); return true },
- highlight: (codes) => { calls.highlight.push(codes); return 1 },
- })
- assert.equal(result.result, 'ok')
- assert.equal(calls.fly.length, 1)
- assert.equal(calls.fly[0].object.code, 'DEV-131')
- assert.ok(calls.highlight[0].includes('DEV-131'))
- })
- 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.equal(located.markers.some((marker) => marker.code === 'MP-131'), false, '不应强行补宿主点位标记(会盖住设备图标)')
- assert.equal(located.selection.visible, true, '定位揭示必须让 NORMAL 关联设备的详情可见')
- // 即使宿主点位本身在预警处置可见(ALARM),定位设备期间也要让位,避免点图标盖住设备图标。
- const attentionLocated = planModeLayers({
- ...base,
- objects: [{ ...host, status: 'ALARM' }],
- locateTarget: { code: 'MP-131', deviceCode: 'DEV-131' },
- })
- assert.equal(attentionLocated.markers.some((marker) => marker.code === 'MP-131'), false, '定位设备时应隐藏宿主点位标记')
- assert.equal(attentionLocated.selection.visible, true)
- })
|