| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643 |
- /**
- * 关联监测设备临时图层(票 42)。
- *
- * ── 为什么单独一个 store,而不是塞进 detailStore 或 mapStore ──
- * 这条图层的输入**横跨两个既有 store**:设备编码清单来自 `mapStore`(当前快照该点位的
- * `deviceCodes`),状态与坐标来自 `detailStore`(点位详情的 `devices[]`)。两边都不该为了
- * 对方长出依赖(票 10 的 F4、票 02 的层次纪律),所以由本 store 做**唯一的合成点**:
- * 它读两边、按 `domain/deviceLayer.js` 的纯函数判定,再把「可上图的行」交给地图服务。
- *
- * ── 四条规格硬要求,各自落在哪一行 ──
- * ① **跟随选择**:`syncForSelection()` 是唯一入口,选中即加载、关闭/换点即撤下;
- * ② **并行不阻塞**:它不 await 相机飞行,设备数据一到就渲染(票 41 已把定位与详情解耦);
- * ③ **迟到响应不得覆盖**:与详情同级——每次同步领一个序号,回来时序号变了就整批丢弃;
- * ④ **同快照翻页不重建**:重算的输入是「当前快照的 `deviceCodes` + 详情卡片」,
- * 翻页只往合并态追加对象;**同一点位、同一份清单**算出的计划不变,就不重画
- * (见 `lastPlanKey`),所以翻页不会让设备图层闪烁或重取。
- */
- import { markRaw, ref, shallowRef } from 'vue'
- import { defineStore } from 'pinia'
- import {
- DEVICE_LAYER_KIND,
- DEVICE_PLACEMENT,
- DEVICE_PLACEMENT_TEXT,
- associatedLegend,
- countPlacements,
- crossEndpointNotice,
- planAssociatedDevices,
- uniqueCodes,
- } from '../domain/deviceLayer.js'
- // 票 46:模式可见性判据**唯一**来自 `domain/modeLayerPlan.js`(规格 18:不做第二次过滤)。
- // `deviceLayer.isVisibleInMode` 保留为该判据的别名引用(t42 闸门仍在用)。
- import { isAssociatedDeviceVisible as isDeviceVisibleInModePlan } from '../domain/modeLayerPlan.js'
- import { DEVICE_FLIGHT, DIM_THRESHOLD, planDeviceFlight } from '../domain/deviceCorrespondence.js'
- // 票 44:资产计划与设备状态词表(判定与资产都在这一层合成,两处共用同一份行)。
- import { planDeviceAsset } from '../domain/deviceAssets.js'
- import { deviceDisplayStatusIndex, deviceVisualForStatus } from '../domain/deviceStatus.js'
- import { groupOverlappingDevices } from '../domain/overlapDevices.js'
- // 票 47:设备状态动效计划(映射/门控/30 台降级判定都在 domain)。
- import { planDeviceEffects } from '../domain/deviceEffects.js'
- import { DETAIL_LEVEL } from '../domain/detailFlow.js'
- import {
- clearAssociatedDevices,
- clearOverlapNudge as clearOverlapNudgeService,
- getLifecycleStats,
- nudgeOverlap as nudgeOverlapService,
- resolveDeviceEffectsOptions,
- locateMonitoringPoint,
- cancelPointLocate,
- setHoveredDevice,
- setSelectedDevice,
- syncAssociatedDevices,
- syncDeviceReactions as syncDeviceReactionsService,
- getEffectsAbnormalBase,
- // 票 70(2026-10-27):上一份计划是否已落地 —— 指纹短路的自愈条件。
- isDeviceApplyPending,
- } from '../services/mapService.js'
- import { TERRAIN_STATE } from '../domain/mapLayers.js'
- import { useDetailStore } from './detailStore.js'
- import { useMapStore } from './mapStore.js'
- import { useDeviceStatusStore } from './deviceStatusStore.js'
- export const useDeviceLayerStore = defineStore('deviceLayerStore', () => {
- /** 当前图层所归属的监测点编码(空串=没有活动图层)。 */
- const pointCode = ref('')
- /** 全部关联设备行(**保留全部**,含不上图的;界面清单与计数都读它)。 */
- const rows = shallowRef([])
- /** 互斥计数(`drawn`/`no-location`/`hidden`/`pending`/`inconsistent`/`unavailable`)。 */
- const counts = ref({})
- /**
- * **关联总数**:当前快照该点位去重后的 `deviceCodes` 条数(规格:总数只认它)。
- *
- * 刻意与 `rows.length` 分开:清单会**多出**「详情独有」的行(那些设备不在当前快照里),
- * 拿清单行数当总数会虚报关联设备数。界面两个数都显示、各有明确含义。
- */
- const total = ref(0)
- /** 独立设备图例(与摘要图例分开)。 */
- const legend = ref([])
- /**
- * 票 45:重叠呈现摘要。`k`=可逐台绘制设备数,`n`=快照关联总数;
- * `degraded` 组只逐台摊开 maxFan 个,其余继续留在清单,不虚报逐台已上图。
- */
- const overlap = ref({ k: 0, n: 0, maxFan: 10, groups: [], active: false, degraded: false })
- /**
- * 票 47:设备状态动效计划(`{ enabled, limit, abnormalCount, degraded, animated, staticAbnormal }`)。
- * 界面据此显示降级提示「N 台异常」;关掉特效**不隐藏静态状态表达**(色/形/文字仍在)。
- */
- const effectsPlan = ref(null)
- /** 跨端点不同步的风险提示(规格强制行为,不得静默删除)。 */
- const notice = ref({ risky: false, text: '' })
- /** 正在加载(界面只做轻提示;成败由 `rows`/`counts` 如实体现)。 */
- const loading = ref(false)
- /** 最近一次同步是否真的把设备画到了地图上。 */
- const painted = ref(false)
- /** 每次同步的序号:换点/关闭/刷新时旧的在途结果整批作废(与详情同款纪律)。 */
- let token = 0
- /**
- * 上一份已上图的计划指纹(`pointCode + 已上图编码序列`)。
- * **只有它变了才重画** —— 这就是「同一 `snapshotAt` 翻页不重建设备图层」的落点:
- * 翻页只追加摘要对象,本点位的 `deviceCodes` 与详情卡片不变 ⇒ 指纹不变 ⇒ 不重画。
- */
- let lastPlanKey = ''
- /** 只留可上图的那些行给引擎(判定已在 domain 收口,这里不再二次过滤业务语义)。 */
- function renderableRows(list) {
- 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: device.typeName || '',
- status: device.status || '',
- statusLabel: visual.label,
- statusReasons: [],
- longitude: device.longitude,
- latitude: device.latitude,
- coordinate: device.coordinate,
- // 内层类型徽标靠 industry;强制行也必须带上,否则中心只剩母版水滴。
- industry: device.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,
- row.assetMode, row.assetReason, row.tone,
- ])])
- }
- /**
- * 依据当前选择与快照重算设备图层。**这是唯一入口**(选择变化、详情到达、快照变化都调它)。
- * @param {object} [options] `{ force, mode, entered, filterActive }`
- * · `force` 强制重画(快照换了要撤旧图层时用);
- * · `mode` 一级模式(可见性判据的唯一来源是 `domain/modeLayerPlan.js`);
- * · `entered` 票 46:`false` = 引导态,关联设备图层整体不画(计划层输出全空的同款纪律);
- * · `filterActive` 票 14:设备级筛选生效(行业/范围/类型)——快照清单是命中子集时,
- * 详情独有按「未命中当前筛选」归类(另有 N 台),而不是「与当前快照不一致」。
- * 只有快照对象确实已加载时才生效(翻页没到该点位时无从判断命中)。
- */
- // 引擎未就绪时的重试(最多 40 次 × 250ms ≈ 10s,覆盖冷启动;成功后清零)。
- let engineRetryTimer = null
- let engineRetryCount = 0
- const ENGINE_RETRY_LIMIT = 40
- function clearEngineRetry() {
- if (engineRetryTimer) clearTimeout(engineRetryTimer)
- engineRetryTimer = null
- engineRetryCount = 0
- }
- function scheduleEngineRetry(options = {}) {
- if (engineRetryTimer || engineRetryCount >= ENGINE_RETRY_LIMIT) return
- engineRetryCount += 1
- engineRetryTimer = setTimeout(() => {
- engineRetryTimer = null
- syncForSelection({ ...options, force: true })
- }, 250)
- }
- function syncForSelection(options = {}) {
- const detailStore = useDetailStore()
- const mapStore = useMapStore()
- // #127:关联设备也按「基础属性 + 可叠加标签」的显示状态归类与着色;
- // 状态池未就绪时索引为空,statusOf 回退设备卡原值(不伪造)。
- const statusStore = useDeviceStatusStore()
- const statusIndex = deviceDisplayStatusIndex(statusStore.pools.devices)
- const statusOf = (card) => {
- const code = String((card && card.code) || '').trim()
- return (code && statusIndex.get(code)) || (card && card.status) || ''
- }
- // 票 46:引导态(进入前)不显示任何业务对象 —— 关联设备图层直接撤下。
- // 数据仍可预取(详情/快照照常),只是**呈现**被门控。
- if (options.entered === false || options.parentVisible === false) {
- token += 1
- pointCode.value = ''
- rows.value = []
- counts.value = {}
- total.value = 0
- legend.value = []
- overlap.value = { k: 0, n: 0, maxFan: 10, groups: [], active: false, degraded: false }
- effectsPlan.value = null
- notice.value = { risky: false, text: '' }
- painted.value = false
- lastPlanKey = ''
- clearAssociatedDevices()
- return { total: 0, drawn: 0 }
- }
- const selected = detailStore.selection
- const code = selected && selected.pointCode ? selected.pointCode : ''
- /**
- * 独立设备(没有宿主点位)也要能上图。
- *
- * 这类目标 `pointCode` 为空,早先会直接落到下面的「没有点位级选择 → 图层撤下」分支,
- * 于是揭示行**根本没机会生成**:点「定位设备」只飞相机,图标与锚定都没有依据
- * (维护者 2026-12-02:Elements 里 data-enhancement-device-status 为 0 of 0)。
- * 这里在撤下之前先认一次定位目标自带的设备行。
- */
- const revealDevice = options.revealDevice && options.revealDevice.device
- ? revealRow(options.revealDevice.device, options.revealDevice.code)
- : null
- if (!code) {
- if (revealDevice) {
- token += 1
- pointCode.value = ''
- rows.value = markRaw([revealDevice])
- counts.value = countPlacements([revealDevice])
- total.value = 1
- legend.value = associatedLegend(counts.value)
- overlap.value = { k: 1, n: 1, maxFan: 10, groups: [], active: false, degraded: false }
- effectsPlan.value = null
- notice.value = { risky: false, text: '' }
- painted.value = false
- lastPlanKey = ''
- return { total: 1, drawn: 1 }
- }
- token += 1
- pointCode.value = ''
- rows.value = []
- counts.value = {}
- total.value = 0
- legend.value = []
- overlap.value = { k: 0, n: 0, maxFan: 10, groups: [], active: false, degraded: false }
- effectsPlan.value = null
- notice.value = { risky: false, text: '' }
- painted.value = false
- lastPlanKey = ''
- clearAssociatedDevices()
- return { total: 0, drawn: 0 }
- }
- // 当前快照该点位的 `deviceCodes`:这是**总数**的唯一依据。
- const object = (mapStore.summary.objects || []).find(
- (item) => item && item.kind === 'monitoring-point' && item.code === code,
- )
- const snapshotCodes = object && Array.isArray(object.deviceCodes) ? uniqueCodes(object.deviceCodes) : []
- // 票 14:命中子集语义只在「快照对象确实已加载」时成立——翻页没到该点位时
- // deviceCodes 缺失是"还没取到",不是"被筛选裁剪",详情独有仍按快照不一致呈现。
- const filterActive = options.filterActive === true && !!object
- // 详情卡片:来自已加载的点位摘要分区(未取到或不属于本点位时给空数组)。
- const section = detailStore.sections.pointDetail
- const data = (section && section.data) || null
- const cards = data && data.code === code && Array.isArray(data.devices) ? data.devices : []
- // 地形是否就绪(票 44):**坐标有效但地形未就绪**要单列"位置待确认",
- // 不能算坐标无效、也不能算已上图。地形状态由地图服务如实给出。
- //
- // 三态语义(与票 41 的投影取同一口径):
- // `none` = 本部署没配地形 → 设备按椭球面贴地,**可以上图**(不是"待确认");
- // `ready` = 已就绪 → 可以上图;
- // `invalid`= 加载失败 → 位置待确认(不上图,但保留清单)。
- const terrainState = getLifecycleStats().terrain
- const terrainReady = terrainState !== TERRAIN_STATE.INVALID
- const plan = planAssociatedDevices({
- snapshotCodes,
- cards,
- mode: options.mode || '',
- pointCode: code,
- // 批次 3:内层行业图标继承点位 industry(设备卡契约实测无此字段)。
- pointIndustry: (mapStore.summary.objects.find((item) => item.kind === 'monitoring-point' && item.code === code) || {}).industry || '',
- terrainReady,
- filterActive,
- statusOf,
- })
- // 票 44:**资产计划在这里就一起算好**,让清单行自带 `shape`/`size`/`assetMode`/`assetReason`。
- //
- // 为什么不能只在地图服务里算(本票实测抓到的缺陷):`mapService` 只在**引擎就绪**时
- // 才把资产计划写回它自己那份 `deviceRows`;而详情卡片读的是**本 store 的行**。
- // 两处各持一份 ⇒ 引擎没起来时(或纯逻辑断言里)清单行永远没有资产字段,
- // 详情卡片也就永远显示不出"正式图片素材未提供"这类原因 —— 而那正是验收第 5 条要的。
- // 判定与资产都是同一层的**纯数据**,所以在这里合成一次、两处共用。
- const withAssets = plan.rows.map((row) => {
- const asset = planDeviceAsset({ device: row, color: '' })
- return {
- ...row,
- // 行里已有的状态形状优先(`planAssociatedDevices` 已按设备词表给出),资产层只补尺寸与降级。
- shape: row.shape || asset.shape,
- size: asset.size,
- assetMode: asset.mode,
- assetReason: asset.reason,
- assetReasonText: asset.reasonText,
- visualKey: asset.visualKey,
- tone: deviceVisualForStatus(row.status).tone,
- }
- })
- pointCode.value = code
- // #131:关联设备定位时,即使它当前状态(NORMAL)/模式本应隐藏,也临时补一条可上图行。
- // 揭示判据认 code 也认 deviceCode:独立设备定位时 deviceCode 是空的(它靠 code 揭示),
- // 只认 deviceCode 会让这类目标永远补不上图层。
- const reveal = options.revealDevice && (options.revealDevice.code || options.revealDevice.deviceCode) ? options.revealDevice : null
- let layerRows = withAssets
- if (reveal) {
- const forced = reveal.device ? revealRow(reveal.device, reveal.code) : null
- if (forced) {
- const exclude = reveal.deviceCode || (reveal.device && reveal.device.code) || reveal.code || ''
- layerRows = [...layerRows.filter((row) => row.code !== exclude), 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(counts.value)
- notice.value = crossEndpointNotice(layerRows)
- 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 = {
- k: groups.reduce((sum, group) => sum + (group.k || 0), 0),
- n: plan.total,
- maxFan: options.maxFan || 10,
- groups,
- active: activeGroups.length > 0,
- degraded: activeGroups.some((group) => group.degraded),
- }
- // 票 47:设备状态动效计划(映射/门控/30 台降级都在 domain,本层只提供输入)。
- // 只对**已绘制**的设备算动效 —— 清单里那些没上图的设备没有实体可动。
- // 票 85:降级阈值按三类对象**合计**判定,所以把另外两类(监测点/未关联设备)的异常数带进来。
- const effects = planDeviceEffects({ devices: drawn, ...resolveDeviceEffectsOptions(), extraAbnormalCount: getEffectsAbnormalBase() })
- effectsPlan.value = effects
- const key = planKeyOf(code, drawn, options.maxFan || 10, effects)
- // 同点位的同一份计划**不重画**(翻页/无关重渲染都不会让设备层闪烁)。
- // `force` 用于「快照换了、旧图层必须先撤下」这条路径(规格要求先撤后取)。
- //
- // 票 70(2026-10-27):短路必须让开「已下单但还没落地」的情况 ——
- // `syncAssociatedDevices` 是先入队再返回 true,若那份订单随后被清层吃掉,
- // 指纹相同会让后续同步永久跳过,只剩 force(刷新地图)能救。
- if (!options.force && key === lastPlanKey && !isDeviceApplyPending()) {
- return { total: plan.total, drawn: drawn.length }
- }
- lastPlanKey = key
- loading.value = true
- const mine = token
- // 地图服务是同步下发,但**序号纪律仍然要在**:换点后旧的一次同步不得再写读数。
- painted.value = syncAssociatedDevices(drawn, { maxFan: options.maxFan, overlapGroups: groups, effects })
- // 2026-10-27 走查修正:引擎未就绪时 sync 返回 false,但上面已写入 lastPlanKey ——
- // 若不同时安排重试,之后同一点位会被"计划未变"短路掉,表现为「子设备点要刷新地图才出现」。
- if (painted.value) clearEngineRetry()
- else scheduleEngineRetry(options)
- // 图层的实体是**整份重建**的,所以重建后必须刷新一次反应 —— 否则选中/hover/弱化
- // 会停在重建前的值(新实体默认 scale 1、无外环),表现为"翻一页选中态就没了"。
- syncDeviceReactions()
- if (mine === token) loading.value = false
- return { total: plan.total, drawn: drawn.length }
- }
- /**
- * 快照变化(刷新 / 筛选重载 / 快照失效)时的收场:**先撤下旧图层**,再等新的快照与详情到达。
- * 规格原句:「刷新或快照失效时先撤下旧设备图层,以便旧快照的设备不会被误读为新范围的数据」。
- * @param {object} [options] 透传给 `syncForSelection`(含票 14 的 `filterActive`)。
- */
- function invalidateForSnapshot(options = {}) {
- token += 1
- lastPlanKey = ''
- rows.value = []
- counts.value = {}
- total.value = 0
- legend.value = []
- notice.value = { risky: false, text: '' }
- painted.value = false
- clearAssociatedDevices()
- return syncForSelection({ force: true, ...options })
- }
- /**
- * 票 42(规格 14:刷新核对链):刷新**发起**或快照失效时的挂起——撤下旧设备图层,
- * 但**不**按当前摘要立即重算(此刻摘要还是旧的,重算等于把旧层画回来)。
- * 图层在挂起期间保持撤下;新快照首页到达后由既有的快照/对象监听自然重算,
- * 或由核对链在点位重载后恢复。
- */
- function suspendForSnapshot() {
- token += 1
- lastPlanKey = ''
- rows.value = []
- counts.value = {}
- total.value = 0
- legend.value = []
- notice.value = { risky: false, text: '' }
- overlap.value = { k: 0, n: 0, maxFan: 10, groups: [], active: false, degraded: false }
- effectsPlan.value = null
- painted.value = false
- clearAssociatedDevices()
- }
- // ---- 票 43:面板与三维设备点的对应反应 ----
- /** 当前选中设备编码(空串=没选设备;`data-map-device-picked` 读它)。 */
- const selectedDevice = ref('')
- /** 当前三维 hover 设备编码(瞬态;`data-map-device-hovered` 读它)。 */
- const hoveredDevice = ref('')
- /** 上一次的详情层级与设备编码 —— 镜头联动判"该怎么动"要拿它做对照。 */
- let lastLevel = DETAIL_LEVEL.NONE
- let lastDeviceCode = ''
- let pendingDeviceTier = false
- let deviceFlightToken = 0
- /** 是否需要弱化(该点位设备数 ≥ 阈值)。界面按它决定要不要给"其余设备压暗"的样式。 */
- const dimming = ref(false)
- /**
- * 选中一台设备(**面板卡片与三维点选共用这一个入口**)。
- *
- * 三件事分开做,顺序有意:
- * ① 选中态写进服务层(它负责把反应画到三维,并写 `data-map-device-picked`);
- * ② 进设备级详情(复用 `detailStore.selectDevice`,取数链路不变);
- * ③ 按**层级变化**决定镜头怎么动(`planDeviceFlight` 纯判定:首次飞设备档、
- * A→B 只换中心、返回点位回点位档)。
- * @param {string} deviceCode 设备编码
- * @param {object} [options] `{ fly }` 传 false 表示只换选中不联动镜头(三维 hover 不调它)
- */
- function selectDevice(deviceCode, options = {}) {
- const code = typeof deviceCode === 'string' ? deviceCode.trim() : ''
- if (!code) return ''
- const detailStore = useDetailStore()
- const before = { level: lastLevel, deviceCode: lastDeviceCode }
- selectedDevice.value = code
- setSelectedDevice(code)
- // 进设备级(**唯一**的取数入口,票 11 的契约)。
- void detailStore.selectDevice(code)
- const flight = planDeviceFlight({
- fromLevel: before.level,
- toLevel: DETAIL_LEVEL.EQUIPMENT,
- fromDeviceCode: before.deviceCode,
- toDeviceCode: code,
- })
- if (options.fly !== false) applyDeviceFlight(flight, code)
- lastLevel = DETAIL_LEVEL.EQUIPMENT
- lastDeviceCode = code
- syncDeviceReactions()
- return code
- }
- /**
- * 按层级变化驱动镜头(规格的三段行为)。
- *
- * `DEVICE_TIER` = 飞设备档(`mapService` 的定位入口用**配置里的** `map.locate.device`);
- * `CENTER_ONLY` = 只换中心不重飞;`POINT_TIER` = 回点位档。
- * 有意不在这里写死 range 数字 —— 数值归票 03 的 `map.locate` 配置。
- */
- function applyDeviceFlight(flight, code) {
- if (flight === DEVICE_FLIGHT.NONE) return ''
- const mine = ++deviceFlightToken
- if (flight === DEVICE_FLIGHT.DEVICE_TIER) pendingDeviceTier = true
- const device = rows.value.find((row) => row.code === code) || null
- if (!device || device.placement !== 'drawn') {
- cancelPointLocate()
- return ''
- }
- const centerOnly = flight === DEVICE_FLIGHT.CENTER_ONLY && !pendingDeviceTier
- void locateMonitoringPoint(device, { tier: 'device', centerOnly }).then((applied) => {
- if (applied && mine === deviceFlightToken && !centerOnly) pendingDeviceTier = false
- })
- return flight
- }
- /** 选中设备的引线要在选中后立刻跟上(服务层的 `syncDeviceReactions` 已负责画)。 */
- function syncDeviceLeadTo() {
- syncDeviceReactions()
- }
- /** hover 一台设备(三维 pointermove 与面板卡片 hover 共用)。 */
- function hoverDevice(deviceCode) {
- const code = typeof deviceCode === 'string' ? deviceCode.trim() : ''
- if (code === hoveredDevice.value) return code
- hoveredDevice.value = code
- setHoveredDevice(code)
- return code
- }
- /** 「返回点位」:清设备强化、回点位级(**监测点仍选中**,不是取消选中)。 */
- function backToPointLevel() {
- deviceFlightToken += 1
- pendingDeviceTier = false
- cancelPointLocate()
- const detailStore = useDetailStore()
- const before = { level: lastLevel, deviceCode: lastDeviceCode }
- detailStore.backToPoint()
- selectedDevice.value = ''
- setSelectedDevice('')
- const flight = planDeviceFlight({
- fromLevel: before.level,
- toLevel: DETAIL_LEVEL.POINT,
- fromDeviceCode: before.deviceCode,
- toDeviceCode: '',
- })
- lastLevel = DETAIL_LEVEL.POINT
- lastDeviceCode = ''
- if (flight === DEVICE_FLIGHT.POINT_TIER) {
- const point = useMapStore().summary.objects.find((item) => item.kind === 'monitoring-point' && item.code === pointCode.value)
- if (point) void locateMonitoringPoint(point)
- }
- syncDeviceReactions()
- return flight
- }
- /** 详情层级变了(外壳订阅)→ 同步内部对照值,避免下一次判定拿错"变化前"。 */
- function noteLevel(level, deviceCode) {
- if (level !== DETAIL_LEVEL.EQUIPMENT) {
- deviceFlightToken += 1
- pendingDeviceTier = false
- }
- if (level === DETAIL_LEVEL.NONE) cancelPointLocate()
- lastLevel = level || DETAIL_LEVEL.NONE
- lastDeviceCode = deviceCode || ''
- }
- /**
- * 票 45:面板 hover 聚合行 → 三维聚合符号弱提示(不摊开、不写设备选中态)。
- * group 查找收在 store(它持有 `overlap.groups`),组件只递行对象、不碰服务层。
- * @returns {boolean} 是否真的对聚合组做了弱提示(false = 该行不属于聚合组)
- */
- function nudgeOverlapRow(row) {
- const code = row && row.code
- if (!code) return false
- const group = (overlap.value.groups || []).find((g) => (g.rows || []).some((r) => r.code === code))
- if (!group || group.k < 2) return false
- return nudgeOverlapService(group.key) === true
- }
- /** 票 45:面板离开聚合行 → 清除三维弱提示(无弱提示时调用也安全)。 */
- function clearOverlapNudge() {
- return clearOverlapNudgeService()
- }
- /** 按当前选中/hover 重算反应(设备行或选中变化后调)。 */
- function syncDeviceReactions() {
- const plan = syncDeviceReactionsService({ devices: rows.value })
- dimming.value = plan.dimming
- return plan
- }
- /** 仅测试/走查用:彻底复位(含地图上的图层)。 */
- function reset() {
- token += 1
- pointCode.value = ''
- rows.value = []
- counts.value = {}
- total.value = 0
- legend.value = []
- overlap.value = { k: 0, n: 0, maxFan: 10, groups: [], active: false, degraded: false }
- effectsPlan.value = null
- notice.value = { risky: false, text: '' }
- loading.value = false
- painted.value = false
- lastPlanKey = ''
- // 票 43:选中/hover/层级对照一并复位。
- selectedDevice.value = ''
- hoveredDevice.value = ''
- dimming.value = false
- lastLevel = DETAIL_LEVEL.NONE
- lastDeviceCode = ''
- pendingDeviceTier = false
- deviceFlightToken += 1
- cancelPointLocate()
- clearAssociatedDevices()
- }
- return {
- KIND: DEVICE_LAYER_KIND,
- pointCode,
- rows,
- counts,
- total,
- legend,
- overlap,
- effectsPlan,
- notice,
- loading,
- painted,
- // 票 43
- selectedDevice,
- hoveredDevice,
- dimming,
- dimThreshold: DIM_THRESHOLD,
- selectDevice,
- hoverDevice,
- backToPointLevel,
- noteLevel,
- // 票 45:聚合 hover 弱提示(component 经 store 调 mapService,维护票 10 F4 纪律)。
- nudgeOverlapRow,
- clearOverlapNudge,
- syncDeviceReactions,
- syncForSelection,
- invalidateForSnapshot,
- suspendForSnapshot,
- reset,
- }
- })
|