Explorar o código

feat(cockpit): 危险源详情码值翻译、隐患图片归档与三类关联联动

- 隐患类型/等级/来源改走 hazard_type / hazard_level / hazard_source 三类字典(按线上 /dict/* 实测值),匹配不到回原码,不再把 0/1/2 直接上屏。
- 关联设备、关联管网、关联工单改按后端业务引用(票 06 的 {code,name} / {code})显示:
  设备「名称(编码)」可定位、管网「名称(编码)」可聚焦、工单显示工单号可打开;
  无关联一律「未提供」,任何情况下都不渲染内部 id。
- 隐患图片从明细行移出,由附件区承载(共享 ImageGallery:缩略图 + 点击放大);
  附件分区并入「业务详情」页签(规格 §2)。
- 资产详情时刻按值的实际粒度展示:落在 00:00:00 占位上的只显示日期(维护者 2026-12-01 时间规则),
  同步更新票 02 里把 00:00:00 当真实时刻的旧断言。
- 防护目标的关联管网字段键由 networkId 改为 network,与危险源共用同一条引用取法。
ChenJZ hai 1 día
pai
achega
56b8d2ba49

+ 9 - 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" />
+                <EntityDetailDrawer v-if="!introVisible && !facilityDetailOpen" :side="entityDetailSide" @locate-device="locateDeviceFromDetail" @focus-network="focusNetworkFromDetail" @open-work-order="openWorkOrderFromDetail" />
             </section>
 
             <PipeEnhancement
@@ -503,6 +503,7 @@
                     :underground-ready="facilityUndergroundReady"
                     @locate-device="locateDeviceFromDetail"
                     @focus-network="focusNetworkFromDetail"
+                    @open-work-order="openWorkOrderFromDetail"
                     @open-underground="openFacilityUnderground"
                 />
                 <PointDetailCard v-else :location-reason="fixedLocationReason" @locate-device="locateDeviceFromDetail" />
@@ -1047,6 +1048,13 @@ function locateDeviceFromDetail(deviceCode) {
  * `resolveFacilityPoint` 对 PIPE_NETWORK 已按 sourceId/networkId 从管线图层解析位置,
  * 所以管网走的就是同一条飞行与高亮链;解析不到时由统一反馈如实说明原因,不静默。
  */
+/** 详情里的「关联工单」:打开只读工单详情(与台账卡同一入口)。 */
+function openWorkOrderFromDetail(workOrderCode) {
+    if (!workOrderCode) return false
+    if (facilityDetailOpen.value) entityDetailStore.close()
+    return entityDetailStore.show({ kind: 'work-order', id: workOrderCode })
+}
+
 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)" /></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)" /></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'])
+const emit = defineEmits(['locate-device', 'focus-network', 'open-work-order'])
 const store = useEntityDetailStore()
 const view = computed(() => entityDetailView(store.detail))
 </script>

+ 9 - 6
src/modules/cockpit/components/EntityDetailSections.vue

@@ -107,10 +107,10 @@ 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'])
+const emit = defineEmits(['locate-device', 'focus-network', 'open-work-order'])
 
 /** 明细里的联动按钮文案;认不出的动作不渲染按钮。 */
-const ACTION_TEXT = { 'focus-network': '聚焦管网' }
+const ACTION_TEXT = { 'focus-network': '聚焦管网', 'locate-equipment': '定位设备', 'open-work-order': '查看工单' }
 const view = computed(() => entityDetailView(props.detail))
 
 // 分区图标:静态内联 SVG(不引第三方图标库),统一当前色 14px。
@@ -150,15 +150,18 @@ const showDevices = computed(() => {
     return !activeTab.value || activeTab.value === 'overview' || activeTab.value === 'devices'
 })
 const showRecords = computed(() => activeTab.value === 'records')
-const showAttachments = computed(() => activeTab.value === 'attachments')
+// 图片附件并入「业务详情」页签(规格 §2):隐患图片/设备图片跟在业务详情字段末尾。
+const showAttachments = computed(() => activeTab.value === 'business' || activeTab.value === 'attachments')
 const showFlow = computed(() => activeTab.value === 'flow')
 const showRelated = computed(() => activeTab.value === 'related')
 const showAlarms = computed(() => activeTab.value === 'alarms')
 
-/** 关联设备定位:沿用运行监测「设备台账」的定位方法(由外壳转给 monitoringStore)。 */
-/** 明细里的联动出口(目前只有管网聚焦):组件不认识地图,交给外壳。 */
+/** 明细里的联动出口:组件不认识地图也不认识工单,一律交给外壳。 */
 function runAction(action) {
-    if (action && action.kind === 'focus-network' && action.code) emit('focus-network', action.code)
+    if (!action || !action.code) return
+    if (action.kind === 'focus-network') emit('focus-network', action.code)
+    else if (action.kind === 'locate-equipment') emit('locate-device', action.code)
+    else if (action.kind === 'open-work-order') emit('open-work-order', action.code)
 }
 
 function locateDevice(code) {

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

@@ -19,7 +19,7 @@
                 设施详情未取到,已保留现有信息。
                 <button type="button" class="facility-detail__action" @click="store.retry()">重试</button>
             </p>
-            <EntityDetailSections :detail="store.detail" presentation="device" @locate-device="code => emit('locate-device', code)" @focus-network="code => emit('focus-network', code)">
+            <EntityDetailSections :detail="store.detail" presentation="device" @locate-device="code => emit('locate-device', code)" @focus-network="code => emit('focus-network', code)" @open-work-order="code => emit('open-work-order', code)">
                 <!-- 维护者 2026-11-16:「查看详情」放在「基本信息/业务信息/关联信息」TAB 行右侧。 -->
                 <template #tabs-action>
                     <button
@@ -48,7 +48,7 @@ const props = defineProps({
     // 面板只负责画按钮,不自己再算一遍下钻条件。
     undergroundReady: { type: Boolean, default: false },
 })
-const emit = defineEmits(['locate-device', 'focus-network', 'open-underground'])
+const emit = defineEmits(['locate-device', 'focus-network', 'open-work-order', 'open-underground'])
 const store = useEntityDetailStore()
 const view = computed(() => entityDetailView(store.detail))
 const code = computed(() => store.detail?.displayCode || '未提供')

+ 64 - 10
src/modules/cockpit/domain/entityDetail.js

@@ -516,27 +516,29 @@ const ASSET_FIELD_ROWS = {
         { label: '设备图片', key: 'image' },
         { label: '备注', key: 'remark', wide: true },
     ],
+    // 隐患类型/等级/来源是业务库字典码(0/1/2 不能直接上屏);
+    // 三个关联对象是后端下发的业务引用(票 06),不再有 equipmentId/networkId/workOrderId。
+    // 隐患图片不进明细:它以附件区(缩略图 + 放大)出现在业务详情末尾。
     HAZARD: [
-        { label: '隐患类型', key: 'hazardType' },
-        { label: '隐患等级', key: 'level' },
-        { label: '来源', key: 'source' },
+        { label: '隐患类型', key: 'hazardType', dict: DICT_TYPES.hazardType },
+        { label: '隐患等级', key: 'level', dict: DICT_TYPES.hazardLevel },
+        { label: '来源', key: 'source', dict: DICT_TYPES.hazardSource },
         { label: '隐患描述', key: 'description', wide: true },
-        { label: '关联管网', key: 'networkId' },
-        { label: '关联设备', key: 'equipmentId' },
-        { label: '关联工单', key: 'workOrderId' },
+        { label: '关联管网', key: 'network' },
+        { label: '关联设备', key: 'equipment' },
+        { label: '关联工单', key: 'workOrder' },
         { label: '报告单位', key: 'reportUnit' },
         { label: '报告时间', key: 'reportTime' },
         { label: '整改方案', key: 'rectifyPlan', wide: true },
         { label: '整改期限', key: 'rectifyDeadline' },
         { label: '整改人', key: 'rectifyPerson' },
         { label: '整改反馈', key: 'rectifyFeedback', wide: true },
-        { label: '隐患图片', key: 'images', wide: true },
         { label: '备注', key: 'remark', wide: true },
     ],
     // 风险等级与风险颜色不再进明细:已由抬头那一个「风险等级」徽标承担(规格 §5)。
     // 风险因素改成键值网格,不再把一整串 JSON 打在页面上。
     PROTECTION_TARGET: [
-        { label: '关联管网', key: 'networkId' },
+        { label: '关联管网', key: 'network' },
         { label: '风险分值', key: 'riskScore' },
         { label: '评估模型', key: 'assessmentModel' },
         { label: '评估时间', key: 'assessmentTime' },
@@ -612,6 +614,34 @@ function riskFactorPairs(value) {
     return null
 }
 
+/** 业务库字典 → 中文;字典没取到就回原码(不编「未知」,也不回显英文枚举)。 */
+function dictOrCode(type, value) {
+    const code = text(value)
+    if (!code) return ''
+    return dictLabel(type, code) || code
+}
+
+/** 关联设备的业务引用(规格 §5):name + code,有 code 才能定位。 */
+function equipmentReference(a) {
+    const equipment = a.equipment
+    if (!equipment || typeof equipment !== 'object') return null
+    const code = text(equipment.code)
+    const name = text(equipment.name)
+    if (!code && !name) return null
+    return { label: name && code ? `${name}(${code})` : name || code, code }
+}
+
+/**
+ * 关联工单的引用(规格 §5):后端只下发 code —— `work_order` 表没有名称列,
+ * 编一个名称等于造假,所以显示的就是工单号本身。
+ */
+function workOrderReference(a) {
+    const order = a.workOrder
+    if (!order || typeof order !== 'object') return null
+    const code = text(order.code)
+    return code ? { label: code, code } : null
+}
+
 /**
  * 关联管网的业务引用(规格 §5):只认后端下发的 name + code。
  * 只有内部 id 时不渲染 id —— 字段表据此显示「未提供」。
@@ -635,6 +665,16 @@ function formatAssetDate(value) {
     return /^\d{4}-\d{2}-\d{2}/.test(raw) ? raw.slice(0, 10) : raw
 }
 
+/**
+ * 资产详情的时刻(维护者 2026-12-01 时间显示规则):粒度看值的实际内容。
+ * 落在 `00:00:00` 这个占位时刻上的一律只显示日期,不造一个假时刻;
+ * 其它仍然是 `yyyy-MM-dd HH:mm:ss`。
+ */
+function formatAssetTime(value) {
+    const full = formatEventTime(value)
+    return / 00:00:00$/.test(full) ? full.slice(0, 10) : full
+}
+
 /** 原始属性 → 展示值的唯一归一化层:摘要与明细共用;行内 format 只做单字段专门词表。 */
 function assetFieldValue(key, a) {
     if (key === 'equipmentIds' || key === 'equipmentId') {
@@ -644,7 +684,7 @@ function assetFieldValue(key, a) {
     if (['networkId', 'workOrderId', 'equipmentTypeId'].includes(key)) return '未提供'
     if (key === 'riskLevel') return riskLevelText(a[key])
     if (key === 'riskColor') return riskColorText(a[key])
-    if (ASSET_TIMESTAMP_KEYS.has(key)) return formatEventTime(a[key])
+    if (ASSET_TIMESTAMP_KEYS.has(key)) return formatAssetTime(a[key])
     if (ASSET_DATE_KEYS.has(key)) return formatAssetDate(a[key])
     return a[key]
 }
@@ -652,12 +692,26 @@ function assetFieldValue(key, a) {
 function assetFields(category, a) {
     const rows = category === 'PIPE_NETWORK' ? pipesFields(a) : ASSET_FIELD_ROWS[category] || []
     return rows.map((row) => {
+        // 码值字段:业务库字典是唯一权威,没取到就回原码(不回显 0/1/2 之外的编造词)。
+        if (row.dict) return field(row.label, dictOrCode(row.dict, a[row.key]), row.wide === true)
         // 关联管网:后端下发 name + code 时显示「名称(编码)」并给聚焦入口;否则如实「未提供」。
-        if (row.key === 'networkId' && category === 'PROTECTION_TARGET') {
+        if (row.key === 'network') {
             const ref = networkReference(a)
             if (!ref) return field(row.label, '未提供')
             return field(row.label, ref.label, false, { action: ref.code ? { kind: 'focus-network', code: ref.code } : null })
         }
+        // 关联设备:显示「名称(编码)」,有编码才能定位。
+        if (row.key === 'equipment') {
+            const ref = equipmentReference(a)
+            if (!ref) return field(row.label, '未提供')
+            return field(row.label, ref.label, false, { action: ref.code ? { kind: 'locate-equipment', code: ref.code } : null })
+        }
+        // 关联工单:显示工单号并可打开卡片。
+        if (row.key === 'workOrder') {
+            const ref = workOrderReference(a)
+            if (!ref) return field(row.label, '未提供')
+            return field(row.label, ref.label, false, { action: { kind: 'open-work-order', code: ref.code } })
+        }
         // 风险因素:能解析成键值就出网格;非法 JSON / 纯文本原样展示。
         if (row.pairs) {
             const pairs = riskFactorPairs(a[row.key])

+ 3 - 2
tests/entityDetailAssetFields.test.js

@@ -139,7 +139,8 @@ test('关联项按源表列存在:有列缺值显示「未提供」,无列
     assert.equal(businessFields(target).find((item) => item.label === '关联管网').value, '未提供')
 })
 
-test('危险源报告时间与应急资源安装时间按完整时间戳展示', () => {
+test('时间按值的实际粒度展示:真时刻给完整串,00:00:00 占位只显示日期', () => {
+    // 维护者 2026-12-01 时间显示规则:落在 00:00:00 这个占位时刻上的一律只显示日期。
     assert.equal(businessFields(hazardView()).find((item) => item.label === '报告时间').value, '2026-11-13 17:57:10')
-    assert.equal(businessFields(resourceView()).find((item) => item.label === '安装时间').value, '2026-10-26 00:00:00')
+    assert.equal(businessFields(resourceView()).find((item) => item.label === '安装时间').value, '2026-10-26')
 })

+ 123 - 0
tests/entityDetailHazard.test.js

@@ -0,0 +1,123 @@
+import assert from 'node:assert/strict'
+import { test } from 'node:test'
+
+import { normalizeEntityDetail, entityDetailView } from '../src/modules/cockpit/domain/entityDetail.js'
+import { DICT_TYPES, resetDictLabelsForTest, setDictLabels } from '../src/modules/cockpit/domain/dictLabels.js'
+
+/** 真实字典(线上 /dict/*,2026-12-01)。 */
+const DICTS = {
+    [DICT_TYPES.hazardType]: [['0', '腐蚀'], ['1', '第三方破坏'], ['2', '占压'], ['3', '泄漏']],
+    [DICT_TYPES.hazardLevel]: [['1', '一级隐患'], ['2', '二级隐患'], ['3', '三级隐患'], ['4', '四级隐患']],
+    [DICT_TYPES.hazardSource]: [['0', '巡检'], ['1', '政府检查'], ['2', '企业上报'], ['3', '模型辨识']],
+}
+
+function useDictionaries() {
+    resetDictLabelsForTest()
+    for (const [type, rows] of Object.entries(DICTS)) {
+        setDictLabels(type, rows.map(([dictValue, dictLabel]) => ({ dictValue, dictLabel })))
+    }
+}
+
+/** 线上真实响应原文(YH-20261201134850,2026-12-01 实测)。 */
+const REAL_PAYLOAD = {
+    requestId: 'ba80165ff557475baadeeed1671bf381',
+    apiVersion: 'v1',
+    readOnly: true,
+    category: 'HAZARD',
+    id: '156cdc681e9fa53932ba4c1efe277b9c',
+    code: 'YH-20261201134850',
+    name: 'test',
+    status: '待核查',
+    location: null,
+    district: 1,
+    districtName: '城北',
+    coordinates: { longitude: 110.361206, latitude: 28.45557, endLongitude: null, endLatitude: null },
+    attributes: {
+        hazardType: '3',
+        level: '2',
+        source: '0',
+        description: 'test',
+        equipment: { code: '2607230190000022', name: '可燃气体-022' },
+        workOrder: { code: 'WO202612011354251210' },
+        reportTime: '2026-12-01T00:00:00',
+        rectifyPlan: '',
+        rectifyDeadline: '2026-12-04',
+        rectifyPerson: '',
+        images: '/hazard/2026/12/01/bbf71b8ebf6645b0ba3666cf13a37e83.png',
+    },
+    updatedAt: '2026-12-01T13:51:52+08:00',
+}
+
+function hazardView(attributes = {}, source = {}) {
+    useDictionaries()
+    return entityDetailView(normalizeEntityDetail(
+        { kind: 'emergency', id: REAL_PAYLOAD.id, category: 'HAZARD' },
+        { ...REAL_PAYLOAD, ...source, attributes: { ...REAL_PAYLOAD.attributes, ...attributes } },
+    ))
+}
+
+const businessRows = (view) => view.sections.find((group) => group.title === '业务详情').fields
+const rowOf = (view, label) => businessRows(view).find((row) => row.label === label)
+
+test('隐患类型/等级/来源按业务库字典显示中文,不出现裸码', () => {
+    const view = hazardView()
+    assert.equal(rowOf(view, '隐患类型').value, '泄漏')
+    assert.equal(rowOf(view, '隐患等级').value, '二级隐患')
+    assert.equal(rowOf(view, '来源').value, '巡检')
+    for (const label of ['隐患类型', '隐患等级', '来源']) {
+        assert.ok(!/^[0-9]+$/.test(rowOf(view, label).value), label + ' 仍是裸码')
+    }
+})
+
+test('字典没取到时回原码,不编「未知」', () => {
+    resetDictLabelsForTest()
+    const view = entityDetailView(normalizeEntityDetail(
+        { kind: 'emergency', id: REAL_PAYLOAD.id, category: 'HAZARD' },
+        REAL_PAYLOAD,
+    ))
+    assert.equal(rowOf(view, '隐患类型').value, '3')
+    assert.equal(rowOf(view, '隐患等级').value, '2')
+})
+
+test('关联设备显示「名称(编码)」并给定位入口', () => {
+    const row = rowOf(hazardView(), '关联设备')
+    assert.equal(row.value, '可燃气体-022(2607230190000022)')
+    assert.deepEqual(row.action, { kind: 'locate-equipment', code: '2607230190000022' })
+})
+
+test('关联工单显示工单号并可打开(后端只给 code,没有名称列)', () => {
+    const row = rowOf(hazardView(), '关联工单')
+    assert.equal(row.value, 'WO202612011354251210')
+    assert.deepEqual(row.action, { kind: 'open-work-order', code: 'WO202612011354251210' })
+})
+
+test('没有关联管网时显示「未提供」,且不出现内部 id', () => {
+    const view = hazardView()
+    const row = rowOf(view, '关联管网')
+    assert.equal(row.value, '未提供')
+    assert.equal(row.action, undefined)
+    assert.ok(!JSON.stringify(view.sections).includes('156cdc681e9fa539'))
+})
+
+test('隐患图片不再作为明细行,改为附件数据(缩略图由共享组件渲染)', () => {
+    const view = hazardView()
+    assert.equal(businessRows(view).some((row) => row.label === '隐患图片'), false)
+    assert.equal(view.attachments.length, 1)
+    assert.match(view.attachments[0].url, /bbf71b8ebf6645b0ba3666cf13a37e83\.png$/)
+})
+
+test('时间按粒度显示:00:00:00 占位只显示日期,整改期限同样只到日', () => {
+    const view = hazardView()
+    assert.equal(rowOf(view, '报告时间').value, '2026-12-01')
+    assert.equal(rowOf(view, '整改期限').value, '2026-12-04')
+    assert.ok(!businessRows(view).some((row) => String(row.value).includes('00:00:00')))
+})
+
+test('后端已发布的中文状态原样透传;有业务编码列时展现编码', () => {
+    const view = hazardView()
+    assert.equal(view.status, '待核查')
+    assert.match(view.subtitle, /YH-20261201134850/)
+    const basic = view.sections.find((group) => group.title === '基本信息').fields
+    // 应急对象的编码行叫「对象编码」(规格 §7);危险源有业务编码列,所以这行存在。
+    assert.ok(basic.some((row) => row.label === '对象编码' && row.value === 'YH-20261201134850'))
+})