| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- /**
- * 3D 视图「资产详情」的归属判据(维护者 2026-11-16)。
- *
- * 维护者原话:「『地下管线详情视图』中,右侧的『资产详情』TAB 只能够显示设备详情,
- * 无法显示设施详情…需要使资产详情根据当前选中的设备或设施来显示对应的详情信息,
- * 例如选中管道就显示管道详情,选择窨井(设备)就显示窨井设备详情,
- * 选中窨井(设施)就显示窨井设施详情。」
- *
- * 旧实现的判据是 `identity.id === object.code`:
- * 窨井设施的 identity.id 是 **UUID**(b410acff…),而 3D 对象的 code 是
- * **设施编码**(YL-YJ-003),两者永不相等 → 设施详情恒为 null → 永远显示设备分支。
- *
- * 正确判据:设施详情要归属到它自己的 3D 对象,可以按**编码**或**主键**任一相等;
- * 且明确的设施选择必须让位给设施详情(不能被上一次的设备选择压住)。
- */
- /** 设施 identity 与 3D 对象是否同一个设施。 */
- export function facilityBelongsToObject(identity, object) {
- if (!identity || !object) return false
- if (String(identity.kind || '') !== 'facility') return false
- const byId = String(identity.id || '')
- const candidates = [object.code, object.sourceId, object.id].map((v) => String(v || '')).filter(Boolean)
- return Boolean(byId) && candidates.includes(byId)
- }
- /**
- * 资产详情当前该显示哪一类。
- *
- * 与旧实现的差别:**设施优先**。用户是在 3D 视图里主动选了某个设施(窨井)才进来的,
- * 此时上一次残留的设备选择不该继续霸占详情位;两者都不成立才算没有资产。
- *
- * @param {{deviceCode?: string, facilityDetail?: object|null}} input
- * @returns {'device'|'facility'|''}
- */
- export function resolveAssetKind({ deviceCode = '', facilityDetail = null } = {}) {
- if (facilityDetail) return 'facility'
- if (deviceCode) return 'device'
- return ''
- }
- /**
- * 当前 3D 选中对象是否需要**现取一次**设施/管道详情(维护者 2026-11-16)。
- *
- * 两类资产进 3D 视图的路径不同,这就是「窨井能显示、管道不显示」的根源:
- * · 窨井(构件)—— 从设施点链进来,`entityDetailStore` 已有详情,
- * 3D 视图只要按主键认回即可(`facilityBelongsToObject`),**不能再取一次**;
- * · 管段(pipe)—— 从管线拾取链进来,`entityDetailStore` 从未被填充,
- * 资产详情恒空,必须现取 `PIPE_NETWORK` 详情。
- *
- * **取数主键是 `sourceId` 而不是 `code`**(实测):几何里管段的
- * `properties.code` 是业务编码(TCRQ202609080001),`properties.sourceId` 才是
- * `pipe_network_base` 的主键(raw_P11920)。用编码去查 `/infrastructure/entities/{id}/detail` 会 404。
- *
- * @param {{kind?: string, code?: string, sourceId?: string}|null} selection `pipeEnhancementStore.selected`
- * @param {Array<object>} [visiblePipes] 当前可上图管线(用于把编码补成主键)
- * @returns {{kind:'facility', id:string, category:'PIPE_NETWORK'}|null}
- */
- export function pipeEnhancementFacilityIdentity(selection, visiblePipes = []) {
- if (!selection) return null
- if (String(selection.kind || '') !== 'pipe') return null
- const code = typeof selection.code === 'string' ? selection.code.trim() : ''
- if (!code) return null
- // 优先用选中对象自带的 sourceId;退回可见管线里按编码查出的 sourceId;
- // 两者都没有时**不猜**(返回 null,资产详情显示取数提示好过发一个注定 404 的请求)。
- const own = typeof selection.sourceId === 'string' ? selection.sourceId.trim() : ''
- let sourceId = own
- if (!sourceId) {
- const pipe = (Array.isArray(visiblePipes) ? visiblePipes : []).find((row) => row && row.code === code)
- sourceId = pipe && typeof pipe.sourceId === 'string' ? pipe.sourceId.trim() : ''
- }
- return sourceId ? { kind: 'facility', id: sourceId, category: 'PIPE_NETWORK' } : null
- }
|