|
|
@@ -26,8 +26,10 @@ import {
|
|
|
locateFacilityPoint,
|
|
|
locateMonitoringPoint,
|
|
|
} from '../services/mapService.js'
|
|
|
-import { LOCATE_RESULT, locateFailureText, planLocate } from '../domain/mapLocate.js'
|
|
|
+import { LOCATE_RESULT, locateFailureText } from '../domain/mapLocate.js'
|
|
|
import { EVENT_DETAIL_RESULT, planEventLocate } from '../domain/eventDetail.js'
|
|
|
+// 定位的判定收在 domain(`planMapObjectLocate`),本 store 只按计划执行三件事。
|
|
|
+import { DETAIL_STEP, planMapObjectLocate } from '../domain/locateSteps.js'
|
|
|
import { TERRAIN_LOCATE_REASON } from '../domain/pointLocate.js'
|
|
|
import { MAP_OBJECT_KIND } from '../domain/mapSummary.js'
|
|
|
import { facilityIdentity, resolveFacilityPoint } from '../domain/facilitySelection.js'
|
|
|
@@ -100,35 +102,94 @@ export const usePointLocateStore = defineStore('pointLocateStore', () => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async function locateMapObject(code, options = {}) {
|
|
|
- const objects = options.objects || mapStore.summary.objects
|
|
|
- const mapReady = options.mapReady === undefined ? !!getCameraState() : !!options.mapReady
|
|
|
- const flyPoint = options.flyPoint || locateMonitoringPoint
|
|
|
- const openPoint = options.openPoint || ((value, opts) => detailStore.openPoint(value, opts))
|
|
|
- const openDevice = options.openDevice || ((value, opts) => detailStore.openDevice(value, opts))
|
|
|
- const selectDevice = options.selectDevice || ((value, opts) => detailStore.selectDevice(value, opts))
|
|
|
+ /**
|
|
|
+ * 关联设备 / 未关联设备:解析"揭示来源"要的那一行设备(点位设备卡 → 设备档案)。
|
|
|
+ * 关联设备**无论调用方是否已经给了设备行**都要先打开宿主点位详情:那一份点位摘要是
|
|
|
+ * 设备卡片与「返回点位」的依据,不是可省的中间态(t131 闸门钉着这一步)。
|
|
|
+ */
|
|
|
+ async function resolveLocateDevice(plan, deps, preset = null) {
|
|
|
+ const object = plan.object
|
|
|
+ if (!object) return preset
|
|
|
+ // 未关联设备:它自己就是设备行,坐标已在摘要里。
|
|
|
+ if (object.kind !== MAP_OBJECT_KIND.MONITORING_POINT) return preset || object
|
|
|
+ // 关联设备:设备坐标不在摘要里,先打开宿主点位详情取设备卡,卡片缺失再退设备档案。
|
|
|
+ await deps.openPoint(object.code)
|
|
|
+ if (preset) return preset
|
|
|
+ const pointDetail = detailStore.sections && detailStore.sections.pointDetail
|
|
|
+ && detailStore.sections.pointDetail.data
|
|
|
+ // 设备卡没有 industry,内层类型徽标继承所属点位(与正常关联设备行同一口径)。
|
|
|
+ const pointIndustry = (pointDetail && pointDetail.industry) || object.industry || ''
|
|
|
+ const device = deviceFromCard(detailStore.deviceCard(object.code, plan.deviceCode), pointIndustry)
|
|
|
+ || await deviceFromAggregate(plan.deviceCode, pointIndustry)
|
|
|
+ return device && !device.industry ? { ...device, industry: pointIndustry } : device
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 按计划展开详情(第三件事)。设备级保留宿主点位编码,供「返回点位」使用。 */
|
|
|
+ async function openLocateDetail(open, reveal, deps) {
|
|
|
+ if (!open) return
|
|
|
+ if (open.level === DETAIL_STEP.DEVICE) {
|
|
|
+ if (open.pointCode) return deps.selectDevice(open.deviceCode, { locateTarget: reveal })
|
|
|
+ return deps.openDevice(open.deviceCode, { locateTarget: reveal })
|
|
|
+ }
|
|
|
+ if (open.level === DETAIL_STEP.POINT) return deps.openPoint(open.pointCode, { locateTarget: reveal })
|
|
|
+ }
|
|
|
|
|
|
- const plan = planLocate({ objects, pointCode: code, mapReady })
|
|
|
+ /**
|
|
|
+ * 一次定位的**统一执行**:① 相机飞到目标坐标 ② 揭示目标点 ③ 展开详情。
|
|
|
+ * 后两件与飞行**并行**,且不依赖飞行结果 —— 地形/引擎导致的飞行失败不该连带详情也打不开
|
|
|
+ * (维护者 2026-12-02:只飞到位置、看不到设备详情)。
|
|
|
+ * @returns {Promise<{applied:boolean, failure:string}>}
|
|
|
+ */
|
|
|
+ async function runLocateSteps(plan, deps) {
|
|
|
+ const device = deps.device || null
|
|
|
+ let failure = TERRAIN_LOCATE_REASON.MAP
|
|
|
+ const camera = device || plan.object
|
|
|
+ const flying = camera
|
|
|
+ ? Promise.resolve()
|
|
|
+ .then(() => deps.flyPoint(camera, {
|
|
|
+ ...(device && plan.cameraTier === 'device' ? { tier: 'device' } : {}),
|
|
|
+ onFailure: (reason) => { failure = reason },
|
|
|
+ }))
|
|
|
+ .catch(() => false)
|
|
|
+ : Promise.resolve(false)
|
|
|
+ const reveal = plan.reveal ? { ...plan.reveal, ...(device ? { device } : {}) } : null
|
|
|
+ await openLocateDetail(plan.open, reveal, deps)
|
|
|
+ const applied = await flying
|
|
|
+ return { applied, failure }
|
|
|
+ }
|
|
|
+
|
|
|
+ async function locateMapObject(code, options = {}) {
|
|
|
+ const deps = {
|
|
|
+ flyPoint: options.flyPoint || locateMonitoringPoint,
|
|
|
+ openPoint: options.openPoint || ((value, opts) => detailStore.openPoint(value, opts)),
|
|
|
+ openDevice: options.openDevice || ((value, opts) => detailStore.openDevice(value, opts)),
|
|
|
+ selectDevice: options.selectDevice || ((value, opts) => detailStore.selectDevice(value, opts)),
|
|
|
+ }
|
|
|
+ const plan = planMapObjectLocate({
|
|
|
+ code,
|
|
|
+ objects: options.objects || mapStore.summary.objects,
|
|
|
+ mapReady: options.mapReady === undefined ? !!getCameraState() : !!options.mapReady,
|
|
|
+ })
|
|
|
const base = {
|
|
|
result: plan.result,
|
|
|
code,
|
|
|
pointCode: plan.pointCode,
|
|
|
- deviceCode: plan.deviceCode || '',
|
|
|
+ deviceCode: plan.deviceCode,
|
|
|
reasonText: plan.reasonText,
|
|
|
}
|
|
|
+
|
|
|
+ // 目标还没上图:退到设备档案取坐标;档案也拿不到就如实报原结果(不伪造定位成功)。
|
|
|
if (plan.result !== LOCATE_RESULT.OK) {
|
|
|
- // 目标不在当前地图摘要里(还没上图 / 被筛选掉):关联设备仍可以从**设备档案**取坐标。
|
|
|
- // 不补这条,「点定位设备」的表现就是什么都没发生(维护者 2026-12-02)。
|
|
|
- const archive = await deviceFromAggregate(code)
|
|
|
+ const archive = await deviceFromAggregate(plan.archiveCode)
|
|
|
if (!archive) return setLocate(base)
|
|
|
- let failure = TERRAIN_LOCATE_REASON.MAP
|
|
|
- const flying = Promise.resolve()
|
|
|
- .then(() => flyPoint(archive, { tier: 'device', onFailure: (reason) => { failure = reason } }))
|
|
|
- .catch(() => false)
|
|
|
- // 揭示目标带上设备行与设备编码:图层能补点,详情面板的可见性判据也认得出它。
|
|
|
- const reveal = { code, deviceCode: archive.code || code, device: archive }
|
|
|
- await openDevice(code, { locateTarget: reveal })
|
|
|
- const applied = await flying
|
|
|
+ const fallback = {
|
|
|
+ ...plan,
|
|
|
+ object: archive,
|
|
|
+ cameraTier: 'device',
|
|
|
+ open: { level: DETAIL_STEP.DEVICE, pointCode: '', deviceCode: code },
|
|
|
+ reveal: { code, deviceCode: archive.code || code },
|
|
|
+ }
|
|
|
+ const { applied, failure } = await runLocateSteps(fallback, { ...deps, device: archive })
|
|
|
return setLocate({
|
|
|
result: applied === true ? LOCATE_RESULT.OK : LOCATE_RESULT.UNAVAILABLE,
|
|
|
code,
|
|
|
@@ -138,56 +199,8 @@ export const usePointLocateStore = defineStore('pointLocateStore', () => {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- // #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)
|
|
|
- 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 }
|
|
|
- }
|
|
|
-
|
|
|
- // 独立设备没有宿主点位:对象自身就是设备,把它作为揭示来源交给设备图层,
|
|
|
- // 否则揭示目标里没有设备行,图层无处可画(表现就是「定位成功但图标丢了」)。
|
|
|
- if (!device && plan.object.kind !== MAP_OBJECT_KIND.MONITORING_POINT) device = plan.object
|
|
|
-
|
|
|
- // 揭示目标 = 要看的对象;关联设备把设备坐标一起带给设备图层,
|
|
|
- // 使它在当前模式/状态(例如 NORMAL)下也能临时画出并锚定详情。
|
|
|
- const reveal = {
|
|
|
- code: plan.object.code,
|
|
|
- deviceCode: plan.deviceCode || '',
|
|
|
- ...(device ? { device } : {}),
|
|
|
- }
|
|
|
-
|
|
|
- // 飞行与开详情**并行**,而且开详情不依赖飞行结果:
|
|
|
- // 定位的意义是「看到它」,地形/引擎导致的飞行失败不该连带详情也打不开
|
|
|
- // (维护者 2026-12-02:只飞到位置、看不到设备详情)。
|
|
|
- let failure = TERRAIN_LOCATE_REASON.MAP
|
|
|
- const flying = Promise.resolve()
|
|
|
- .then(() => flyPoint(device || plan.object, {
|
|
|
- ...(device ? { tier: 'device' } : {}),
|
|
|
- onFailure: (reason) => { failure = reason },
|
|
|
- }))
|
|
|
- .catch(() => false)
|
|
|
-
|
|
|
- if (plan.object.kind === MAP_OBJECT_KIND.MONITORING_POINT) {
|
|
|
- if (plan.deviceCode) {
|
|
|
- await selectDevice(plan.deviceCode, { locateTarget: reveal })
|
|
|
- } else {
|
|
|
- await openPoint(plan.object.code, { locateTarget: reveal })
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 独立设备没有宿主点位:直接用设备编码进设备级详情(openDevice('') 打不开任何东西)。
|
|
|
- await openDevice(plan.pointCode || code, { locateTarget: reveal })
|
|
|
- }
|
|
|
-
|
|
|
- const applied = await flying
|
|
|
+ const device = plan.needsDevice ? await resolveLocateDevice(plan, deps, options.device || null) : null
|
|
|
+ const { applied, failure } = await runLocateSteps(plan, { ...deps, device })
|
|
|
if (applied !== true) {
|
|
|
return setLocate({ ...base, result: LOCATE_RESULT.UNAVAILABLE, reasonText: locateFailureText(failure) })
|
|
|
}
|