Explorar el Código

feat(cockpit): 工单详情接入真实处理流程与维修图片

- 工单卡按 orderId 打开详情,并行请求 detail + timeline
- 时间线步骤渲染过程处置图片,流程页签补维修前/后图片
- 图片统一走 ImageGallery,附件页签保留完整清单
- 兼容仍无 orderId 的旧接口:退回列表 prefill
- 新增 3 项工单详情/身份/接口合并测试
ChenJZ hace 4 horas
padre
commit
b6b13eb2e0

+ 12 - 2
src/modules/cockpit/components/EntityDetailSections.vue

@@ -66,9 +66,15 @@
             <p v-if="!view.relatedAlarms.length" class="entity-sections__empty">暂无关联报警</p>
             <ul v-else><li v-for="(item, index) in view.relatedAlarms" :key="item.code || index"><b>{{ item.name }}</b><span>{{ item.code }} · {{ item.status }}</span></li></ul>
         </section>
-        <section v-if="showFlow && view.track" class="entity-sections__group">
+        <section v-if="showFlow && (view.track || view.maintenanceImages.length)" class="entity-sections__group">
             <h3><span class="entity-sections__icon" aria-hidden="true" v-html="sectionIcon('处置轨迹')"></span>处置轨迹</h3>
-            <WorkOrderTimeline :track="view.track" />
+            <WorkOrderTimeline v-if="view.track" :track="view.track" />
+            <div v-if="view.maintenanceImages.length" class="entity-sections__maintenance" data-wo-maintenance-images>
+                <div v-for="group in view.maintenanceImages" :key="group.key" class="entity-sections__maintenance-group">
+                    <h4>{{ group.label }}</h4>
+                    <ImageGallery :items="group.images" />
+                </div>
+            </div>
         </section>
     </div>
 </template>
@@ -197,6 +203,10 @@ function locateDevice(code) {
 .entity-sections__group li small,
 .entity-sections__group time { display: block; color: var(--muted); font-size: calc(10.5 * var(--u, 1px)); overflow-wrap: anywhere; }
 
+/* 处理流程页签:维修前/后图片与时间线同区展示;图片查看复用 ImageGallery。 */
+.entity-sections__maintenance { display: grid; gap: 10px; margin-top: 12px; padding-top: 10px; border-top: 1px solid rgba(1, 171, 234, .18); }
+.entity-sections__maintenance-group h4 { margin: 0 0 5px; color: var(--text-2); font-size: calc(10.5 * var(--u, 1px)); font-weight: 600; letter-spacing: .04em; }
+
 /* 处置记录:竖向时间线。 */
 .entity-sections__records { position: relative; display: grid; gap: 12px; margin: 0; padding: 0 0 0 16px; list-style: none; }
 .entity-sections__records:before { content: ''; position: absolute; left: 5px; top: 4px; bottom: 4px; width: 1px; background: linear-gradient(180deg, rgba(1, 171, 234, .55), rgba(1, 171, 234, .08)); }

+ 2 - 1
src/modules/cockpit/components/WarningResponsePane.vue

@@ -103,7 +103,8 @@ function onListPage(payload) {
 /** 历史事件与工单按显式身份分流,禁止把事件卡误开成工单。 */
 function onCardAction(action) {
     const row = (action && action.row) || {}
-    const id = (action && action.code) || ''
+    // 工单卡的路由身份是后端 orderId(票 129);事件仍用业务编码。
+    const id = (row.identityCode || action.identityCode || action.code) || ''
     if (!id) return false
     const prefill = row.identityPayload || row
     if (action.kind === 'event') {

+ 11 - 1
src/modules/cockpit/domain/entityDetail.js

@@ -115,6 +115,7 @@ export function entityDetailView(detail) {
         devices: Array.isArray(current.devices) ? current.devices : [],
         sectionMap: current.sectionMap && typeof current.sectionMap === 'object' ? current.sectionMap : {},
         attachments: Array.isArray(current.attachments) ? current.attachments : [],
+        maintenanceImages: Array.isArray(current.maintenanceImages) ? current.maintenanceImages : [],
         records: Array.isArray(current.records) ? current.records : [],
         track: current.track || null,
     }
@@ -755,7 +756,16 @@ function normalizeWorkOrder(identity, source) {
         stage: workOrderStage(order.stateCode),
         people: peopleItems([['处置人', order.receiveUserName], ['核验人', order.verifyUserName]]),
         devices: order.deviceCode || order.deviceName ? [{ name: order.deviceName || order.deviceCode, code: order.deviceCode, type: order.deviceTypeName, location: order.deviceLocation }] : [],
-        attachments: attachmentItems([raw.maintenanceBeforeImg, raw.maintenanceAfterImg, ...timelineAttachments(timelineRaw)]),
+        // 附件页签保留完整清单;处理流程页签另外按维修前/后分组展示。
+        attachments: attachmentItems([
+            ...order.maintenanceBeforeImages,
+            ...order.maintenanceAfterImages,
+            ...timelineAttachments(timelineRaw),
+        ]),
+        maintenanceImages: [
+            { key: 'before', label: '维修前', images: order.maintenanceBeforeImages },
+            { key: 'after', label: '维修后', images: order.maintenanceAfterImages },
+        ].filter((group) => group.images.length),
         records: recordItems(timelineRaw),
         sections: compactSections([
             section('工单摘要', [field('工单号', order.code || '未提供'), field('类型', order.orderTypeName), field('优先级', orderLevelText(order.orderLevel)), field('状态', stateText)]),

+ 5 - 3
src/modules/cockpit/domain/workOrder.js

@@ -62,6 +62,8 @@ export function toWorkOrder(raw) {
     const source = fieldReader(mobile, 'workOrder')
     const code = source.raw.stateCode !== undefined ? source.num('stateCode') : source.num('orderStatus')
     const association = mobile && mobile.eventAssociation
+    const beforeImages = imageList(source, 'maintenanceBeforeImages')
+    const afterImages = imageList(source, 'maintenanceAfterImages')
 
     return {
         id: source.raw.orderId === undefined || source.raw.orderId === null ? '' : String(source.raw.orderId),
@@ -87,9 +89,9 @@ export function toWorkOrder(raw) {
         faultTime: source.optionalStr('faultTime'),
         // 优先级中文名:后端按等级字典下发;缺失时前端只显示码,不自造词表。
         orderLevelName: source.optionalStr('orderLevelName'),
-        // 维修前/后附件:后端解析成数组,缺失为空数组(不是「无附件」的断言)。
-        maintenanceBeforeImages: imageList(source, 'maintenanceBeforeImages'),
-        maintenanceAfterImages: imageList(source, 'maintenanceAfterImages'),
+        // 维修前/后附件:列表回数组,详情回单图字段,两种形状都认;缺失为空数组。
+        maintenanceBeforeImages: beforeImages.length ? beforeImages : imageList(source, 'maintenanceBeforeImg'),
+        maintenanceAfterImages: afterImages.length ? afterImages : imageList(source, 'maintenanceAfterImg'),
         // 延期申请:无申请时后端给 null,界面显示「没有延期信息」。
         delayApply: delayApplyView(source),
         associatedWithCurrentEvent: typeof source.raw.associatedWithCurrentEvent === 'boolean'

+ 54 - 6
src/modules/cockpit/services/entityDetailApi.js

@@ -12,6 +12,11 @@ export const ENTITY_DETAIL_PATHS = Object.freeze({
     [ENTITY_DETAIL_KIND.WORK_ORDER]: (id) => `/work-orders/${encodeURIComponent(id)}/detail`,
 })
 
+/** 工单处理流程:后端按 orderId 返回 workOrder + timelineEntries(票 129)。 */
+export function workOrderTimelinePath(orderId) {
+    return orderId ? `/work-orders/${encodeURIComponent(orderId)}/timeline` : ''
+}
+
 export function entityDetailPath(identityInput) {
     const identity = entityIdentity(identityInput)
     const build = ENTITY_DETAIL_PATHS[identity.kind]
@@ -22,14 +27,57 @@ export async function fetchEntityDetail(identityInput, options = {}) {
     const identity = entityIdentity(identityInput)
     const path = options.path || entityDetailPath(identity)
     if (!identity.valid || !path) return { ok: false, identity, reason: 'invalid-identity', mode: '', data: null }
-    // 工单:live 后端 /work-orders/{id}/detail 只认内部主键,而 /work-orders 列表不返回该主键
-    // (仅 workOrderCode)。用列表 prefill 直接构造详情,避免点开工单卡片报“详情暂未取到”。
-    // 工单时间线只读接口缺失,另见后端票。
+    // 工单:列表已下发 orderId(票 129),详情 + 处理流程都按主键取。
+    // 旧调用方没有 orderId 时仍退回列表 prefill,避免刚升级后端前整卡不可用。
     if (identity.kind === ENTITY_DETAIL_KIND.WORK_ORDER) {
-        const detail = normalizeEntityDetail(identity, {}, options.prefill)
+        const prefill = options.prefill && typeof options.prefill === 'object' ? options.prefill : {}
+        const orderId = String(prefill.orderId || prefill.identityPayload?.orderId || identity.id || '').trim()
+        if (!orderId || !/^\d+$/.test(orderId)) {
+            const detail = normalizeEntityDetail(identity, {}, prefill)
+            return detail
+                ? { ok: true, identity, mode: prefill ? 'prefill' : 'unavailable', path: '', data: detail }
+                : { ok: false, identity, mode: '', reason: 'bad-payload', data: null }
+        }
+        const detailPath = `/work-orders/${encodeURIComponent(orderId)}/detail`
+        const timelinePath = workOrderTimelinePath(orderId)
+        const [detailResult, timelineResult] = await Promise.all([
+            requestCockpitJson(detailPath, { config: options.config, fetchImpl: options.fetchImpl }),
+            requestCockpitJson(timelinePath, { config: options.config, fetchImpl: options.fetchImpl }),
+        ])
+        if (!detailResult.ok && !timelineResult.ok) {
+            const fallback = normalizeEntityDetail(identity, {}, prefill)
+            return fallback
+                ? { ok: true, identity, mode: prefill ? 'prefill' : 'unavailable', path: '', data: fallback }
+                : { ok: false, identity, mode: '', reason: detailResult.reason || timelineResult.reason || 'unavailable', data: null }
+        }
+        const detailData = detailResult.ok && detailResult.data ? detailResult.data : {}
+        const timelineData = timelineResult.ok && timelineResult.data ? timelineResult.data : {}
+        const order = {
+            ...prefill,
+            ...(timelineData.workOrder && typeof timelineData.workOrder === 'object' ? timelineData.workOrder : {}),
+            ...(detailData.order && typeof detailData.order === 'object' ? detailData.order : {}),
+        }
+        const source = {
+            ...prefill,
+            ...detailData,
+            ...timelineData,
+            order,
+        }
+        // 时间线端点成功时以它为准;只有它失败才保留 detail 自带的 logs 兜底。
+        if (timelineResult.ok) {
+            source.timelineEntries = Array.isArray(timelineData.timelineEntries) ? timelineData.timelineEntries : []
+            delete source.logs
+        }
+        const detail = normalizeEntityDetail(identity, source, prefill)
         return detail
-            ? { ok: true, identity, mode: options.prefill ? 'prefill' : 'unavailable', path: '', data: detail }
-            : { ok: false, identity, mode: '', reason: 'bad-payload', data: null }
+            ? {
+                ok: true,
+                identity,
+                mode: detailResult.mode || timelineResult.mode || '',
+                path: detailResult.path || detailPath,
+                data: detail,
+            }
+            : { ok: false, identity, mode: '', path: detailPath, reason: 'bad-payload', data: null }
     }
     const result = await requestCockpitJson(path, { config: options.config, fetchImpl: options.fetchImpl })
     if (!result.ok) return { ...result, identity, data: null }

+ 94 - 0
tests/entityDetailWorkOrder.test.js

@@ -0,0 +1,94 @@
+/**
+ * 工单详情处理流程:时间线条目图片 + 维修前/后图片必须进入详情视图;
+ * 工单卡身份使用后端 orderId(票 129)。
+ */
+import assert from 'node:assert/strict'
+import { test } from 'node:test'
+
+import { normalizeEntityDetail, entityDetailView } from '../src/modules/cockpit/domain/entityDetail.js'
+import { toWorkOrder } from '../src/modules/cockpit/domain/workOrder.js'
+import { workOrderCardRows } from '../src/modules/cockpit/domain/warningResponsePanels.js'
+import { fetchEntityDetail } from '../src/modules/cockpit/services/entityDetailApi.js'
+
+test('工单详情保留时间线过程图片与维修前后图片', () => {
+    const detail = normalizeEntityDetail({ kind: 'work-order', id: '279' }, {
+        order: {
+            orderNo: 'WO-2026120100001',
+            orderStatus: 3,
+            maintenanceBeforeImg: '/upload/before.png',
+            maintenanceAfterImg: '/upload/after.png',
+        },
+        timelineEntries: [
+            {
+                stateCode: 3,
+                stateName: '处理中',
+                operationName: '现场处置',
+                operationDesc: '更换探头',
+                operatorName: '张工',
+                operatedAt: '2026-12-01 09:30:00',
+                attachImages: ['/upload/process-1.png', '/upload/process-2.png'],
+            },
+        ],
+    })
+    const view = entityDetailView(detail)
+
+    assert.equal(view.track.steps.length, 1)
+    assert.deepEqual(view.track.steps[0].attachImages, ['/upload/process-1.png', '/upload/process-2.png'])
+    assert.deepEqual(view.maintenanceImages.map((group) => ({ label: group.label, images: group.images })), [
+        { label: '维修前', images: ['/upload/before.png'] },
+        { label: '维修后', images: ['/upload/after.png'] },
+    ])
+    assert.deepEqual(view.attachments.map((item) => item.url).sort(), [
+        '/upload/after.png',
+        '/upload/before.png',
+        '/upload/process-1.png',
+        '/upload/process-2.png',
+    ].sort())
+})
+
+test('工单卡身份使用 orderId,而不是 workOrderCode', () => {
+    const order = toWorkOrder({ orderId: 279, orderNo: 'WO-2026120100001', orderStatus: 0 })
+    const [row] = workOrderCardRows([order])
+    assert.equal(row.identityCode, '279')
+    assert.equal(row.code, 'WO-2026120100001')
+})
+
+test('工单详情按 orderId 同时请求详情与时间线,并合并处理流程', async () => {
+    const calls = []
+    const config = { dataSource: 'real', api: { baseUrl: 'http://backend.test/api/cockpit/v1' } }
+    const fetchImpl = async (url) => {
+        calls.push(url)
+        const timeline = url.endsWith('/timeline')
+        return {
+            ok: true,
+            status: 200,
+            json: async () => ({
+                code: 200,
+                data: timeline
+                    ? {
+                        workOrder: { orderId: 279, workOrderCode: 'WO-2026120100001', stateCode: 3, stateName: '处理中' },
+                        timelineEntries: [{
+                            stateCode: 3, stateName: '处理中', operationName: '现场处置',
+                            operatedAt: '2026-12-01 09:30:00', attachImages: ['/upload/process.png'],
+                        }],
+                    }
+                    : {
+                        order: { orderId: 279, orderNo: 'WO-2026120100001', orderStatus: 3, maintenanceBeforeImg: '/upload/before.png' },
+                        logs: [],
+                    },
+            }),
+        }
+    }
+    const result = await fetchEntityDetail({ kind: 'work-order', id: '279' }, {
+        config,
+        fetchImpl,
+        prefill: { orderId: '279', workOrderCode: 'WO-2026120100001' },
+    })
+
+    assert.equal(result.ok, true)
+    assert.ok(calls.some((url) => url.endsWith('/work-orders/279/detail')))
+    assert.ok(calls.some((url) => url.endsWith('/work-orders/279/timeline')))
+    assert.equal(result.data.track.steps.length, 1)
+    assert.deepEqual(result.data.track.steps[0].attachImages, ['/upload/process.png'])
+    assert.deepEqual(result.data.maintenanceImages[0].images, ['/upload/before.png'])
+})