Kaynağa Gözat

feat(cockpit): 关联信息支持打开对应详情

- 关联行仅展示后端真实关联,不再补造自身或预警类型
- 预警/报警/工单关联行提供「查看详情」按钮,交由外壳切换详情
- 工单关联信息不再出现自己;无关联设备以外数据时如实为空
ChenJZ 1 gün önce
ebeveyn
işleme
5cd3e8e67a

+ 20 - 1
src/modules/cockpit/CockpitShell.vue

@@ -377,7 +377,7 @@
                 -->
                 <PipeColorLegend :counts="pipeColorCountsView" />
                 <!-- 实体详情只占中央一张图;按来源栏靠近对应侧边,绝不覆盖侧栏。 -->
-                <EntityDetailDrawer v-if="!introVisible && !facilityDetailOpen" :side="entityDetailSide" @locate-device="locateDeviceFromDetail" @focus-network="focusNetworkFromDetail" @open-work-order="openWorkOrderFromDetail" />
+                <EntityDetailDrawer v-if="!introVisible && !facilityDetailOpen" :side="entityDetailSide" @locate-device="locateDeviceFromDetail" @focus-network="focusNetworkFromDetail" @open-work-order="openWorkOrderFromDetail" @open-relation="openRelationFromDetail" />
             </section>
 
             <PipeEnhancement
@@ -1055,6 +1055,25 @@ function openWorkOrderFromDetail(workOrderCode) {
     return entityDetailStore.show({ kind: 'work-order', id: workOrderCode })
 }
 
+/** 关联信息行 → 对应详情;预警/报警按业务编号,工单优先内部 orderId。 */
+function openRelationFromDetail(item) {
+    if (!item || !item.kind) return false
+    if (entityDetailStore.open) entityDetailStore.close()
+    if (item.kind === 'work-order') {
+        const id = item.orderId || item.detailId || item.code
+        if (!id) return false
+        return entityDetailStore.show({ kind: 'work-order', id: String(id) }, { orderId: String(id) })
+    }
+    if (item.kind === 'warning' || item.kind === 'alarm') {
+        const id = item.detailId || item.code
+        if (!id) return false
+        const family = item.kind === 'warning' ? 'WARNING' : 'ALARM'
+        eventStore.closeEvent()
+        return entityDetailStore.show({ kind: 'event', id: String(id), family }, {}, { side: entityDetailStore.sourceSide || 'right' })
+    }
+    return false
+}
+
 function focusNetworkFromDetail(networkCode) {
     if (!networkCode) return false
     if (facilityDetailOpen.value) entityDetailStore.close()

+ 2 - 2
src/modules/cockpit/components/EntityDetailDrawer.vue

@@ -23,7 +23,7 @@
                 详情暂未取到,已保留列表摘要。
                 <button type="button" @click="store.retry">重试</button>
             </p>
-            <div class="entity-drawer__body"><EntityDetailSections :detail="store.detail" @locate-device="(code) => emit('locate-device', code)" @focus-network="(code) => emit('focus-network', code)" @open-work-order="(code) => emit('open-work-order', code)" /></div>
+            <div class="entity-drawer__body"><EntityDetailSections :detail="store.detail" @locate-device="(code) => emit('locate-device', code)" @focus-network="(code) => emit('focus-network', code)" @open-work-order="(code) => emit('open-work-order', code)" @open-relation="(item) => emit('open-relation', item)" /></div>
         </aside>
     </Transition>
 </template>
@@ -33,7 +33,7 @@ import { entityDetailView } from '../domain/entityDetail.js'
 import { useEntityDetailStore } from '../stores/entityDetailStore.js'
 import EntityDetailSections from './EntityDetailSections.vue'
 defineProps({ side: { type: String, default: 'right' } })
-const emit = defineEmits(['locate-device', 'focus-network', 'open-work-order'])
+const emit = defineEmits(['locate-device', 'focus-network', 'open-work-order', 'open-relation'])
 const store = useEntityDetailStore()
 const view = computed(() => entityDetailView(store.detail))
 </script>

+ 19 - 1
src/modules/cockpit/components/EntityDetailSections.vue

@@ -55,6 +55,7 @@
                     <span v-if="item.code" class="entity-sections__relation-code">{{ item.code }}</span>
                     <span v-if="item.status" class="entity-sections__relation-status">{{ item.status }}</span>
                     <small v-if="item.meta">{{ item.meta }}</small>
+                    <button v-if="isOpenableRelation(item)" type="button" class="entity-sections__locate entity-sections__relation-open" @click.stop="openRelation(item)">查看详情</button>
                     <button v-if="item.locateCode" type="button" class="entity-sections__locate" :data-locate-device="item.locateCode" @click.stop="locateDevice(item.locateCode)">定位 {{ item.locateCode }}</button>
                 </li>
             </ul>
@@ -107,7 +108,7 @@ import { entityDetailView } from '../domain/entityDetail.js'
 import WorkOrderTimeline from './WorkOrderTimeline.vue'
 import ImageGallery from './ImageGallery.vue'
 const props = defineProps({ detail: { type: Object, default: null }, presentation: { type: String, default: 'entity' } })
-const emit = defineEmits(['locate-device', 'focus-network', 'open-work-order'])
+const emit = defineEmits(['locate-device', 'focus-network', 'open-work-order', 'open-relation'])
 
 /** 明细里的联动按钮文案;认不出的动作不渲染按钮。 */
 const ACTION_TEXT = { 'focus-network': '聚焦管网', 'locate-equipment': '定位设备', 'open-work-order': '查看工单' }
@@ -168,6 +169,23 @@ function locateDevice(code) {
     if (!code) return
     emit('locate-device', code)
 }
+
+function isOpenableRelation(item) {
+    if (!item) return false
+    if (!['warning', 'alarm', 'work-order'].includes(item.kind)) return false
+    return Boolean(item.detailId || item.orderId || item.code)
+}
+
+/** 关联行打开对应详情:把领域身份交给外壳,组件不跑路由、不认识详情 store。 */
+function openRelation(item) {
+    if (!isOpenableRelation(item)) return
+    emit('open-relation', {
+        kind: item.kind,
+        code: item.code,
+        detailId: item.detailId || item.orderId || item.code,
+        orderId: item.orderId || (item.kind === 'work-order' ? item.detailId : null),
+    })
+}
 </script>
 <style scoped>
 .entity-sections { display: grid; gap: 8px; min-width: 0; font-size: calc(12.5 * var(--u, 1px)); }

+ 13 - 21
src/modules/cockpit/domain/entityDetail.js

@@ -786,6 +786,7 @@ function normalizeEvent(identity, source) {
         disposalHistory: envelope.disposalHistory || basic.disposalHistory,
         attachmentList: envelope.attachmentList || basic.attachmentList,
         alarmList: envelope.alarmList || basic.alarmList,
+        relations: envelope.relations || basic.relations,
         gisLocation: envelope.gisLocation || basic.gisLocation,
     }
     const family = String(identity.family || source.family || source.eventFamily || (source.alarmId || source.alarmNo ? 'ALARM' : source.warningId || source.warningNo ? 'WARNING' : '')).toUpperCase()
@@ -801,7 +802,7 @@ function normalizeEvent(identity, source) {
     // 报警族的处置记录/附件在不同后端版本字段不一,这里做兼容收集(预警族字段不变)。
     const auditRecords = collectAuditRecords(source)
     const attachments = collectAttachmentItems(source)
-    const relations = eventRelations(family, source)
+    const relations = Array.isArray(source.relations) ? source.relations : eventRelations(family, source)
     return {
         ...identity,
         name,
@@ -912,23 +913,24 @@ function alarmRelation(item) {
         code,
         name: name || code,
         status: text(item && (item.status || item.alarmStatusName)) || '',
-        meta: '',
+        meta: '查看报警详情',
+        detailId: code,
     }
 }
 
 function warningRelation(source) {
-    const actualWarning = text(source.warningNo || source.warningId)
-    const code = text(actualWarning || source.warningCode)
+    // warning_code 是报警类型;没有真实 warning_no/warning_id 时不冒充关联预警。
+    const code = text(source.warningNo || source.warningId)
+    if (!code) return null
     const name = text(source.warningName || source.warningTypeName || source.warningContent)
-    if (!code && !name) return null
     return {
         kind: 'warning',
-        // 只有真实预警编号才叫「预警」;仅有 warning_code 时它是预警类型,不能冒充关联预警。
-        kindLabel: actualWarning ? '预警' : '预警类型',
+        kindLabel: '预警',
         code,
         name: name || code,
         status: eventStatusText(source.warningStatus || source.status, 'WARNING'),
-        meta: '',
+        meta: '查看预警详情',
+        detailId: code,
     }
 }
 
@@ -967,19 +969,9 @@ function normalizeWorkOrder(identity, source) {
         track = trackOf(toWorkOrderTimeline(source))
     }
     const stateText = order.stateName || workOrderStateName(order.stateCode)
-    const relations = []
-    const device = deviceRelation(order)
-    if (device) relations.push(device)
-    if (order.code) {
-        relations.push({
-            kind: 'work-order',
-            kindLabel: '工单',
-            code: order.code,
-            name: order.description || order.code,
-            status: stateText,
-            meta: order.orderLevel === null ? '' : `优先级 ${orderLevelText(order.orderLevel)}`,
-        })
-    }
+    const relations = Array.isArray(source.relations) && source.relations.length
+        ? source.relations
+        : [deviceRelation(order)].filter(Boolean)
     return {
         ...identity,
         name: order.description || order.code || '工单名称未提供',

+ 2 - 1
tests/entityDetailWorkOrder.test.js

@@ -46,7 +46,8 @@ test('工单详情保留时间线过程图片与维修前后图片', () => {
     assert.equal(view.devices[0].name, '平升压力流量计-测试01')
     assert.equal(view.tabs.some((item) => item.label === '关联信息'), true)
     assert.equal(view.tabs.some((item) => item.label === '设备信息'), false)
-    assert.equal(view.relations.length, 2)
+    assert.equal(view.relations.length, 1)
+    assert.equal(view.relations[0].kind, 'device')
     assert.equal(view.track.steps.length, 1)
     assert.deepEqual(view.track.steps[0].attachImages, ['/upload/process-1.png', '/upload/process-2.png'])
     assert.equal(view.track.steps[0].operatedAt, '2026-12-01 09:30:00')