assetDetailKind.js 4.0 KB

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