Sfoglia il codice sorgente

feat(cockpit): 抽出通用图片展示组件,三处图片统一缩略图与放大

- 新增 domain/imageGallery.js:地址串、{url,name} 对象、单值三种入参归一到同一形状;只有名字没有地址的项保留(与改造前附件一致),地址解析交给注入的解析器。
- 新增 components/ImageGallery.vue:多图按序平铺、点击走现有 ImagePreview、加载失败占位可重试、无图空态;两档尺寸 thumb / large。
- 替换三处:实体详情附件、设备详情设备图片、工单时间线维修图;工单维修前、后附件一并迁移。
- 地址一律走 resolveDeviceImageUrl,组件不拼前缀,也不拿原始串给解析失败的项兜底;设备图片被解析器拒绝时落失败占位,不再误说「后端未提供」。
ChenJZ 9 ore fa
parent
commit
2153429cbb

+ 3 - 28
src/modules/cockpit/components/EntityDetailSections.vue

@@ -54,16 +54,7 @@
         </section>
         <section v-if="showAttachments" class="entity-sections__group">
             <h3><span class="entity-sections__icon" aria-hidden="true" v-html="sectionIcon('附件')"></span>附件</h3>
-            <p v-if="!view.attachments.length" class="entity-sections__empty">暂无附件</p>
-            <ul v-else class="entity-sections__attachments">
-                <li v-for="(item, index) in view.attachments" :key="index">
-                    <button v-if="item.url" type="button" class="entity-sections__attachment" :aria-label="'查看附件 ' + (item.name || (index + 1))" @click="openPreview(attachmentUrl(item.url), item.name)">
-                        <img :src="attachmentUrl(item.url)" :alt="item.name || ('附件' + (index + 1))" loading="lazy" />
-                        <span>{{ item.name }}</span>
-                    </button>
-                    <span v-else>{{ item.name }}</span>
-                </li>
-            </ul>
+            <ImageGallery :items="view.attachments" empty-text="暂无附件" size="large" />
         </section>
         <section v-if="showRelated" class="entity-sections__group">
             <h3><span class="entity-sections__icon" aria-hidden="true" v-html="sectionIcon('关联信息')"></span>关联信息</h3>
@@ -79,26 +70,17 @@
             <h3><span class="entity-sections__icon" aria-hidden="true" v-html="sectionIcon('处置轨迹')"></span>处置轨迹</h3>
             <WorkOrderTimeline :track="view.track" />
         </section>
-        <ImagePreview :open="preview.open" :src="preview.src" :alt="preview.alt" @close="preview.open = false" />
     </div>
 </template>
 <script setup>
 import { computed, ref, watch } from 'vue'
 import { entityDetailView } from '../domain/entityDetail.js'
 import WorkOrderTimeline from './WorkOrderTimeline.vue'
-import ImagePreview from './ImagePreview.vue'
-import { resolveDeviceImageUrl } from '../services/deviceImage.js'
+import ImageGallery from './ImageGallery.vue'
 const props = defineProps({ detail: { type: Object, default: null }, presentation: { type: String, default: 'entity' } })
 const emit = defineEmits(['locate-device'])
 const view = computed(() => entityDetailView(props.detail))
-// 附件与设备图片共用同一对象基址(相对路径统一拼前缀)。
-function attachmentUrl(url) { return resolveDeviceImageUrl(url) || url }
-// 通用图片放大:不新开页面,交共用 ImagePreview 处理。
-const preview = ref({ open: false, src: '', alt: '' })
-function openPreview(url, alt) {
-    if (!url) return
-    preview.value = { open: true, src: url, alt: alt || '附件图片' }
-}
+// 附件展示与放大统一交 ImageGallery:地址解析走组件内的唯一解析器,这里不再拼前缀。
 
 // 分区图标:静态内联 SVG(不引第三方图标库),统一当前色 14px。
 const SECTION_ICONS = {
@@ -226,13 +208,6 @@ function locateDevice(code) {
 .entity-sections__record-meta { display: block; color: var(--cyan-hi); font-size: calc(10 * var(--u, 1px)); opacity: .92; }
 .entity-sections__record p { margin: 3px 0 0; color: var(--text-2); font-size: calc(11.5 * var(--u, 1px)); line-height: 1.5; }
 
-/* 附件:缩略图 → 通用放大查看(不新开页面)。 */
-.entity-sections__attachments { display: grid; grid-template-columns: 1fr; gap: 10px; margin: 0; padding: 0; list-style: none; }
-.entity-sections__attachment { display: flex; flex-direction: column; gap: 4px; width: 100%; padding: 0; border: 0; background: none; color: var(--cyan-hi); font: inherit; font-size: calc(10.5 * var(--u, 1px)); text-align: left; cursor: zoom-in; }
-.entity-sections__attachment img { display: block; width: 100%; height: auto; max-height: 320px; object-fit: cover; border: 1px solid rgba(1, 171, 234, .25); border-radius: 6px; background: rgba(0, 20, 72, .4); transition: border-color .15s ease; }
-.entity-sections__attachment:hover img,
-.entity-sections__attachment:focus-visible img { border-color: rgba(53, 216, 255, .7); }
-.entity-sections__attachment span { overflow-wrap: anywhere; }
 .entity-sections__empty { margin: 0; color: var(--muted); font-size: calc(10.5 * var(--u, 1px)); }
 
 .entity-sections__locate { margin-top: 4px; padding: 0 8px; border: 1px solid rgba(1, 171, 234, .45); border-radius: 9px; background: rgba(0, 20, 72, .5); color: var(--cyan-hi, #35d8ff); font: inherit; font-size: calc(10 * var(--u, 1px)); cursor: pointer; }

+ 35 - 116
src/modules/cockpit/components/EquipmentDetailSections.vue

@@ -332,18 +332,7 @@
                                 :data-work-order-images="group.key"
                             >
                                 <span class="equipment-section__wo-label">{{ group.label }}附件</span>
-                                <span class="equipment-section__thumbs">
-                                    <button
-                                        v-for="(path, index) in group.images"
-                                        :key="`${group.key}-${index}`"
-                                        type="button"
-                                        class="equipment-section__thumb"
-                                        :aria-label="`查看${group.label}附件${index + 1}`"
-                                        @click="openProof(order, group, path)"
-                                    >
-                                        <img :src="resolveDeviceImageUrl(path)" :alt="`${group.label}附件${index + 1}`" loading="lazy" @error="markProofFailed($event)" />
-                                    </button>
-                                </span>
+                                <ImageGallery :items="proofItems(order, group)" empty-text="暂无附件" />
                             </div>
                         </template>
 
@@ -360,7 +349,6 @@
                                 v-if="trackOfOrder(order)"
                                 :track="trackOfOrder(order)"
                                 :path-only="!timeline.hasContent"
-                                @preview="openStepProof"
                             />
                             <p v-else-if="timeline.hasContent" class="equipment-section__hint" data-wo-timeline-missing>
                                 这张工单没有动作记录
@@ -387,15 +375,15 @@
 
                 <!-- 设备图片:只画后端指定的那一张(前端不索引、不挑选) -->
                 <figure v-else-if="panel.kind === 'image'" class="equipment-section__figure" data-latest-image>
-                    <template v-if="image(panel).hasImage">
-                        <button v-if="!imageFailed" type="button" class="equipment-section__image-button" aria-label="放大查看设备图片" @click="imagePreviewOpen = true">
-                            <img class="equipment-section__img" :src="image(panel).url" :alt="`${deviceCode} 设备图片`" @load="imageLoading = false" @error="imageFailed = true; imageLoading = false" />
-                            <span>{{ imageLoading ? '图片加载中…' : '点击放大' }}</span>
-                        </button>
-                        <p v-else class="equipment-section__hint" role="status">图片加载失败,请检查图片服务地址或文件是否可访问。<button type="button" @click="imageFailed = false; imageLoading = true">重试</button></p>
-                        <figcaption class="equipment-section__meta">拍摄于 {{ image(panel).capturedAt }}</figcaption>
-                    </template>
-                    <p v-else class="equipment-section__hint" data-latest-image-empty>后端未提供该设备的图片</p>
+                    <ImageGallery
+                        :key="deviceImageKey(panel)"
+                        :items="deviceImageItems(panel)"
+                        size="large"
+                        hint="点击放大"
+                        empty-text="后端未提供该设备的图片"
+                        :style="{ '--image-gallery-max-height': 'calc(140 * var(--u, 1px))' }"
+                    />
+                    <figcaption v-if="image(panel).hasImage" class="equipment-section__meta">拍摄于 {{ image(panel).capturedAt }}</figcaption>
                 </figure>
             </template>
 
@@ -414,9 +402,6 @@
             </p>
         </section>
         </div>
-        <!-- 设备图片 / 维修附件共用通用图片查看器(背景虚化压暗、右上角 × 关闭、不画背景板)。 -->
-        <ImagePreview :open="imagePreviewOpen" :src="currentImageUrl" :alt="`${deviceCode} 设备图片`" @close="imagePreviewOpen = false" />
-        <ImagePreview :open="proofPreviewOpen" :src="proofUrl" :alt="proofImage.caption" :caption="proofImage.caption" @close="proofPreviewOpen = false" />
         <!--
             音频播放条:贴在播放键上方渐入的小浮层(Teleport 到 body,避免被滚动容器裁剪)。
             不再用居中大弹窗/背景虚化;点击外部、滚动或 Esc 都会收起。
@@ -474,7 +459,7 @@ import SectionStateTag from './SectionStateTag.vue'
 import WorkOrderTimeline from './WorkOrderTimeline.vue'
 import PagerNav from './PagerNav.vue'
 import MetricStateHint from './MetricStateHint.vue'
-import ImagePreview from './ImagePreview.vue'
+import ImageGallery from './ImageGallery.vue'
 
 const props = defineProps({
     /** `stores/detailStore.js` 的 `sections.equipmentAggregate`。 */
@@ -517,29 +502,10 @@ function setWoTab(order, key) {
     woTabs.value = { ...woTabs.value, [order.code]: key }
 }
 
-/**
- * 附件/流水图片的查看弹窗:缩略图与流水截图共用同一个 <dialog>。
- * 路径走 `resolveDeviceImageUrl`(维修附件与设备图片同一对象基址);解析不出就不弹空窗。
- */
-const proofPreviewOpen = ref(false)
-const proofImage = ref({ url: '', caption: '' })
-const proofUrl = computed(() => proofImage.value.url)
-function showProof(path, caption) {
-    const url = resolveDeviceImageUrl(path)
-    if (!url) return
-    proofImage.value = { url, caption }
-    proofPreviewOpen.value = true
-}
-function openProof(order, group, path) {
-    showProof(path, `${order?.title || '工单'} · ${group.label}附件`)
-}
-function openStepProof(detail) {
-    showProof(detail?.path, detail?.caption || '维修过程附件')
-}
-/** 缩略图取不到就压暗并明确标出来,不画破图。 */
-function markProofFailed(event) {
-    const img = event?.target
-    if (img && typeof img.setAttribute === 'function') img.setAttribute('data-broken', 'true')
+/** 工单维修前/后附件:每张带同一句 caption(工单 · 前后),不让组件猜。 */
+function proofItems(order, group) {
+    const title = order?.title || '工单'
+    return (group.images || []).map((path) => ({ url: path, caption: `${title} · ${group.label}附件` }))
 }
 
 // ---- 票 46 返工第 1 条:标签页切换(弃用六块竖排的长滚动)----
@@ -780,28 +746,30 @@ function trackOfOrder(order) {
     return full || pathOnlyTrack(order)
 }
 
+/** 设备图片视图:有没有后端点名的那一张、拍摄于何时(地址解析交给展示组件)。 */
 function image(panel) {
+    return imageView(panel.section.data)
+}
+/**
+ * 设备图片只有后端点名的那一张;没有就给空列表,由组件说「后端未提供」。
+ *
+ * 这里传**原始地址**,解析交给组件的唯一解析器:如果把已解析结果塞回去,
+ * 解析器拒绝(带凭据 / 非法协议)时会变成空地址,界面就会把「地址不可用」
+ * 误说成「后端未提供」,还会与下面的「拍摄于 …」自相矛盾。
+ */
+function deviceImageItems(panel) {
     const view = imageView(panel.section.data)
-    return { ...view, url: resolveDeviceImageUrl(view.url) }
-}
-const imagePreviewOpen = ref(false)
-const imageFailed = ref(false)
-const imageLoading = ref(true)
-const currentImageUrl = computed(() => {
-    const panel = panels.value.find((item) => item.kind === 'image')
-    return panel ? image(panel).url : ''
-})
-watch([() => props.deviceCode, currentImageUrl], () => {
-    imagePreviewOpen.value = false
-    proofPreviewOpen.value = false
-    proofImage.value = { url: '', caption: '' }
-    imageFailed.value = false
-    imageLoading.value = true
-})
+    return view.hasImage ? [{ url: view.url, alt: `${props.deviceCode} 设备图片` }] : []
+}
+
+/** 换设备/换图时重建组件(连带复位预览与加载状态);用后端原始地址做键。 */
+function deviceImageKey(panel) {
+    return imageView(panel.section.data).url
+}
 watch([() => props.deviceCode, activeTab], () => {
     closeAudioPlayer()
 })
-/** 图片查看交互已收口到通用 ImagePreview(背景点击 / Esc 关闭)。 */
+/** 图片查看交互已收口到通用 ImageGallery(内部弹 ImagePreview,背景点击 / Esc 关闭)。 */
 
 function emptyList(label) {
     return emptyListText(label)
@@ -1300,24 +1268,6 @@ function isPlaceholder(text) {
     gap: calc(8 * var(--u, 1px));
     margin-top: calc(4 * var(--u, 1px));
 }
-.equipment-section__thumbs {
-    display: flex;
-    flex-wrap: wrap;
-    gap: calc(4 * var(--u, 1px));
-    min-width: 0;
-}
-.equipment-section__thumb {
-    width: calc(44 * var(--u, 1px));
-    height: calc(44 * var(--u, 1px));
-    padding: 0;
-    overflow: hidden;
-    border: 1px solid rgba(1, 171, 234, .3);
-    border-radius: calc(3 * var(--u, 1px));
-    background: rgba(1, 12, 32, .5);
-    cursor: zoom-in;
-}
-.equipment-section__thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
-.equipment-section__thumb img[data-broken='true'] { opacity: .3; }
 
 /* 工单详情:面板较窄,两列键值改为竖向一行一项,字号与正文一致。 */
 .equipment-section__wo-detail { gap: calc(6 * var(--u, 1px)); }
@@ -1435,15 +1385,6 @@ function isPlaceholder(text) {
     margin: 0;
 }
 
-.equipment-section__img {
-    display: block;
-    width: 100%;
-    max-height: calc(140 * var(--u, 1px));
-    object-fit: cover;
-    border: 1px solid rgba(1, 171, 234, 0.35);
-    border-radius: calc(8 * var(--u, 1px));
-}
-
 .equipment-section__hint,
 .equipment-section__missing,
 .is-muted {
@@ -1461,29 +1402,7 @@ function isPlaceholder(text) {
     font-family: var(--num, monospace);
     letter-spacing: 0.04em;
 }
-.equipment-section__image-button {
-    display: grid;
-    gap: 6px;
-    width: 100%;
-    padding: 0;
-    border: 0;
-    background: transparent;
-    color: var(--cyan-hi);
-    font: inherit;
-    cursor: zoom-in;
-}
-.equipment-image-viewer {
-    width: min(90vw, 1200px);
-    max-height: 90vh;
-    padding: 16px;
-    border: 1px solid var(--cyan);
-    border-radius: calc(8 * var(--u, 1px));
-    background: var(--bg-0);
-    color: var(--text);
-}
-.equipment-image-viewer::backdrop { background: rgba(1, 5, 20, .8); backdrop-filter: blur(6px); }
-.equipment-image-viewer img { display: block; width: 100%; height: auto; max-height: 78vh; object-fit: contain; }
-.equipment-image-viewer__close { display: block; margin-left: auto; margin-bottom: 8px; cursor: pointer; }
+
 /* 音频播放条:贴播放键上方渐入的小浮层,不遮罩、不虚化整屏 UI。 */
 .collection-audio-player {
     position: fixed;

+ 189 - 0
src/modules/cockpit/components/ImageGallery.vue

@@ -0,0 +1,189 @@
+<!--
+  通用图片展示(票 03):缩略图平铺 / 点击放大 / 加载失败占位 / 无图空态。
+
+  实体详情附件、设备详情设备图片、工单时间线的维修图共用这一份,各自不再写 <img>。
+  地址一律交 `resolveDeviceImageUrl`(唯一解析器):组件不拼前缀,也不拿原始串
+  给解析失败的项兜底 —— 解析器返回空就是「这一张不许展示」(见 domain/imageGallery.js)。
+
+  只有两档尺寸:`thumb` 列表里的小方块、`large` 详情里的整宽主图。
+-->
+<template>
+    <div class="image-gallery">
+        <p v-if="!entries.length" class="image-gallery__empty" data-image-gallery-empty>{{ emptyText }}</p>
+        <template v-else>
+            <ul class="image-gallery__list" :class="`is-${size}`" data-image-gallery>
+                <li v-for="item in entries" :key="item.key" class="image-gallery__item" :data-image-state="stateOf(item)">
+                    <button v-if="isShown(item)" type="button" class="image-gallery__button" :aria-label="`查看${item.alt || item.name || `第 ${item.index + 1} 张图片`}`" @click="open(item)">
+                        <img :key="attempts[item.key] || 0" :src="item.src" :alt="item.alt || `图片 ${item.index + 1}`" loading="lazy" @load="settle(item.key, false)" @error="settle(item.key, true)" />
+                        <span v-if="hint" class="image-gallery__hint">{{ stateOf(item) === 'ready' ? hint : '图片加载中…' }}</span>
+                    </button>
+                    <!-- 解析不出或加载出错:如实说取不到,不画破图;只有加载出错才给重试(解析拒绝重试也没用)。 -->
+                    <span v-else-if="stateOf(item) === 'failed'" class="image-gallery__failed" role="status">
+                        图片加载失败
+                        <button v-if="canRetry(item)" type="button" class="image-gallery__retry" @click="retry(item)">重试</button>
+                    </span>
+                    <span v-if="item.name" class="image-gallery__name">{{ item.name }}</span>
+                </li>
+            </ul>
+            <ImagePreview :open="preview.open" :src="preview.src" :alt="preview.alt" :caption="preview.caption" @close="preview.open = false" />
+        </template>
+    </div>
+</template>
+
+<script setup>
+import { computed, ref } from 'vue'
+import { galleryItems, resolveGalleryItems } from '../domain/imageGallery.js'
+import { resolveDeviceImageUrl } from '../services/deviceImage.js'
+import ImagePreview from './ImagePreview.vue'
+
+const props = defineProps({
+    /** 图片列表:地址字符串,或 `{ url, name, caption, alt }`。 */
+    items: { type: Array, default: () => [] },
+    /** 没有图时说的话(措辞由各分区给,组件不编业务文案)。 */
+    emptyText: { type: String, default: '暂无图片' },
+    /** `thumb` 小方块 / `large` 整宽主图。 */
+    size: { type: String, default: 'thumb' },
+    /** 主图上的提示文字(设备图片用「点击放大」;列表附图不传)。 */
+    hint: { type: String, default: '' },
+})
+
+const entries = computed(() => resolveGalleryItems(galleryItems(props.items), resolveDeviceImageUrl))
+
+/**
+ * 每一项的显示状态:
+ *   missing — 只有名字没有地址(改造前的附件就是这样:没图只写名字)
+ *   failed  — 有地址,但解析器拒绝或图片加载出错
+ *   loading — 还在加载
+ *   ready   — 可以点开看大图
+ */
+const states = ref({})
+const attempts = ref({})
+function stateOf(item) {
+    if (!item.url) return 'missing'
+    if (!item.available) return 'failed'
+    return states.value[item.key] || 'loading'
+}
+function isShown(item) {
+    const state = stateOf(item)
+    return state === 'loading' || state === 'ready'
+}
+function settle(key, failed) {
+    const next = failed ? 'failed' : 'ready'
+    if (states.value[key] === next) return
+    states.value = { ...states.value, [key]: next }
+}
+
+/** 地址解析成功但图片加载出错:可以重试(换 key 让浏览器重新请求)。 */
+function canRetry(item) {
+    return item.available && states.value[item.key] === 'failed'
+}
+function retry(item) {
+    states.value = { ...states.value, [item.key]: 'loading' }
+    attempts.value = { ...attempts.value, [item.key]: (attempts.value[item.key] || 0) + 1 }
+}
+
+const preview = ref({ open: false, src: '', alt: '', caption: '' })
+function open(item) {
+    if (!item.src) return
+    preview.value = { open: true, src: item.src, alt: item.alt || item.name || '图片', caption: item.caption }
+}
+</script>
+
+<style scoped>
+.image-gallery { min-width: 0; }
+
+.image-gallery__empty {
+    margin: 0;
+    color: var(--muted, #5680b0);
+    font-size: calc(10.5 * var(--u, 1px));
+}
+
+.image-gallery__list {
+    display: flex;
+    flex-wrap: wrap;
+    gap: calc(4 * var(--u, 1px));
+    margin: 0;
+    padding: 0;
+    list-style: none;
+}
+
+/* 整宽主图:一列铺开,多张时按序往下排。 */
+.image-gallery__list.is-large { display: grid; grid-template-columns: 1fr; gap: 10px; }
+
+.image-gallery__item { display: grid; gap: 3px; min-width: 0; }
+.image-gallery__list.is-thumb .image-gallery__item { width: calc(44 * var(--u, 1px)); }
+
+.image-gallery__button {
+    position: relative;
+    display: block;
+    width: 100%;
+    padding: 0;
+    overflow: hidden;
+    border: 1px solid rgba(1, 171, 234, .3);
+    border-radius: calc(3 * var(--u, 1px));
+    background: rgba(1, 12, 32, .5);
+    cursor: zoom-in;
+}
+
+.image-gallery__list.is-large .image-gallery__button {
+    border-color: rgba(1, 171, 234, .25);
+    border-radius: 6px;
+    background: rgba(0, 20, 72, .4);
+    transition: border-color .15s ease;
+}
+
+.image-gallery__list.is-large .image-gallery__button:hover,
+.image-gallery__list.is-large .image-gallery__button:focus-visible { border-color: rgba(53, 216, 255, .7); }
+
+.image-gallery__button img { display: block; width: 100%; height: 100%; object-fit: cover; }
+.image-gallery__list.is-thumb .image-gallery__button img { height: calc(44 * var(--u, 1px)); }
+.image-gallery__list.is-large .image-gallery__button img { height: auto; max-height: var(--image-gallery-max-height, 320px); }
+
+.image-gallery__hint {
+    position: absolute;
+    right: calc(4 * var(--u, 1px));
+    bottom: calc(4 * var(--u, 1px));
+    padding: 1px calc(5 * var(--u, 1px));
+    border-radius: calc(3 * var(--u, 1px));
+    background: rgba(0, 12, 32, .72);
+    color: var(--text-2, #88b7e8);
+    font-size: calc(10 * var(--u, 1px));
+    pointer-events: none;
+}
+
+/* 失败占位:与缩略图同尺寸,虚线红框 + 一句话,不留空洞。 */
+.image-gallery__failed {
+    display: grid;
+    place-items: center;
+    width: 100%;
+    height: calc(44 * var(--u, 1px));
+    padding: calc(2 * var(--u, 1px));
+    border: 1px dashed rgba(255, 59, 82, .5);
+    border-radius: calc(3 * var(--u, 1px));
+    background: rgba(60, 12, 20, .32);
+    color: var(--lv1, #ff3b52);
+    font-size: calc(9.5 * var(--u, 1px));
+    line-height: 1.3;
+    text-align: center;
+}
+
+.image-gallery__list.is-large .image-gallery__failed { height: calc(120 * var(--u, 1px)); font-size: calc(11 * var(--u, 1px)); }
+
+.image-gallery__retry {
+    justify-self: center;
+    margin-top: calc(3 * var(--u, 1px));
+    padding: calc(1 * var(--u, 1px)) calc(7 * var(--u, 1px));
+    border: 1px solid rgba(255, 59, 82, .55);
+    border-radius: calc(3 * var(--u, 1px));
+    background: transparent;
+    color: inherit;
+    font: inherit;
+    cursor: pointer;
+}
+
+.image-gallery__name {
+    color: var(--cyan-hi, #00b8ff);
+    font-size: calc(10.5 * var(--u, 1px));
+    overflow-wrap: anywhere;
+}
+</style>

+ 16 - 30
src/modules/cockpit/components/WorkOrderTimeline.vue

@@ -62,24 +62,16 @@
                         {{ step.actionLabel }} · 自{{ step.fromStateName }}
                     </em>
                 </span>
-                <span class="wo-timeline__step-body">
+                <!-- 流水正文用 div:里面要放图片网格(block 内容),span 装不下。 -->
+                <div class="wo-timeline__step-body">
                     <span class="wo-timeline__op">{{ step.operationName || placeholder }}</span>
                     <span v-if="step.operationDesc" class="wo-timeline__desc">{{ step.operationDesc }}</span>
                     <span v-if="step.operatorName" class="wo-timeline__who">{{ step.operatorName }}</span>
-                    <!-- 维修过程上传的图片(维护者 2026-11-23):缩略图,点开看大图。 -->
-                    <span v-if="step.attachImages && step.attachImages.length" class="wo-timeline__shots" data-wo-step-images>
-                        <button
-                            v-for="(path, shot) in step.attachImages"
-                            :key="path + shot"
-                            type="button"
-                            class="wo-timeline__shot"
-                            :aria-label="`查看${step.operationName || '处置'}第${shot + 1}张图片`"
-                            @click="emit('preview', { path, caption: `${step.operatedAt || ''} · ${step.operationName || '处置'}第${shot + 1}张图片` })"
-                        >
-                            <img :src="resolveDeviceImageUrl(path)" alt="" loading="lazy" />
-                        </button>
-                    </span>
-                </span>
+                    <!-- 维修过程上传的图片(维护者 2026-11-23):缩略图,点开看大图(交共享图片组件)。 -->
+                    <div v-if="step.attachImages && step.attachImages.length" class="wo-timeline__shots" data-wo-step-images>
+                        <ImageGallery :items="shotItems(step)" />
+                    </div>
+                </div>
             </li>
         </ol>
         <!--
@@ -95,7 +87,7 @@
 import { computed } from 'vue'
 import { DETAIL_PLACEHOLDER } from '../domain/detailFlow.js'
 import { pathView } from '../domain/workOrderTimeline.js'
-import { resolveDeviceImageUrl } from '../services/deviceImage.js'
+import ImageGallery from './ImageGallery.vue'
 
 const props = defineProps({
     /** `domain/equipmentDetailView.js` 的 `timelineSource().tracks[workOrderCode]`。 */
@@ -107,8 +99,14 @@ const props = defineProps({
     pathOnly: { type: Boolean, default: false },
 })
 
-/** 点缩略图 → 交给父组件弹查看器(组件自己不管弹窗,保持纯展示)。 */
-const emit = defineEmits(['preview'])
+/** 维修过程图片:每张带自己的 caption(时间 · 动作 · 序号),点开由共享组件弹大图。 */
+function shotItems(step) {
+    return (step.attachImages || []).map((path, shot) => ({
+        url: path,
+        alt: `${step.operationName || '处置'}第${shot + 1}张图片`,
+        caption: `${step.operatedAt || ''} · ${step.operationName || '处置'}第${shot + 1}张图片`,
+    }))
+}
 
 const placeholder = DETAIL_PLACEHOLDER
 const nodes = computed(() => pathView(props.track))
@@ -243,18 +241,6 @@ function nodeTone(node) {
     flex-basis: 100%;
     margin-top: calc(2 * var(--u, 1px));
 }
-.wo-timeline__shot {
-    width: calc(40 * var(--u, 1px));
-    height: calc(40 * var(--u, 1px));
-    padding: 0;
-    overflow: hidden;
-    border: 1px solid rgba(1, 171, 234, 0.3);
-    border-radius: calc(3 * var(--u, 1px));
-    background: rgba(1, 12, 32, 0.5);
-    cursor: zoom-in;
-}
-.wo-timeline__shot img { display: block; width: 100%; height: 100%; object-fit: cover; }
-
 .wo-timeline__time,
 .wo-timeline__who,
 .wo-timeline__desc {

+ 57 - 0
src/modules/cockpit/domain/imageGallery.js

@@ -0,0 +1,57 @@
+/**
+ * 图片展示的数据归一化(票 03)。
+ *
+ * 三处图片展示的入参形状各不相同:字符串数组(工单维修图)、`{ url, name }` 对象
+ * (实体详情附件)、单张地址(设备图片)。归一化收在这一处,组件只认识一种形状。
+ *
+ * 这里**不解析地址**:域层不读驾驶舱配置。「相对路径 → 可访问 URL」由
+ * `services/deviceImage.js` 的唯一解析器负责,由调用方注入(见 `resolveGalleryItems`)。
+ */
+
+/** 只收字符串;空白串等于没有。 */
+function text(value) {
+    return typeof value === 'string' ? value.trim() : ''
+}
+
+/**
+ * 把各种入参形状收成 `{ key, url, name, caption, alt, index }` 列表。
+ *
+ * 地址与名字都没有的项直接丢掉;**只有名字没有地址的项保留**(`url` 为空),
+ * 因为改造前实体详情附件就是这么显示的:有图看图,没图只写名字。
+ */
+export function galleryItems(value) {
+    const list = Array.isArray(value) ? value : value ? [value] : []
+    const items = []
+    for (const raw of list) {
+        const source = typeof raw === 'string' ? { url: raw } : raw && typeof raw === 'object' ? raw : null
+        if (!source) continue
+        const url = text(source.url)
+        const name = text(source.name)
+        if (!url && !name) continue
+        items.push({
+            // 同一地址可能出现两次(工单的维修前/后附图),序号保证 key 唯一。
+            key: `${url || name}#${items.length}`,
+            url,
+            name,
+            caption: text(source.caption) || name,
+            alt: text(source.alt) || name,
+            index: items.length,
+        })
+    }
+    return items
+}
+
+/**
+ * 解析每一项的地址,并标出这一张能不能展示。
+ *
+ * 解析器返回空串 = 「这一张不许展示」——空地址、非法协议、带凭据的地址都会走这条路。
+ * 所以这里**不拿原始串兜底**:兜底等于绕过解析器的拦截,把不该请求的地址塞回 `<img>`。
+ * 解析不出的项标记 `available: false`,由组件画失败占位。
+ */
+export function resolveGalleryItems(items, resolve) {
+    const run = typeof resolve === 'function' ? resolve : (url) => url
+    return (items || []).map((item) => {
+        const src = item.url ? run(item.url) || '' : ''
+        return { ...item, src, available: !!src }
+    })
+}

+ 58 - 0
tests/imageGallery.test.js

@@ -0,0 +1,58 @@
+import assert from 'node:assert/strict'
+import { test } from 'node:test'
+
+import { galleryItems, resolveGalleryItems } from '../src/modules/cockpit/domain/imageGallery.js'
+
+test('字符串数组按原序归一化,空白项被丢掉', () => {
+    const items = galleryItems(['a/1.jpg', '  ', 'b/2.png'])
+    assert.deepEqual(items.map((item) => item.url), ['a/1.jpg', 'b/2.png'])
+    assert.deepEqual(items.map((item) => item.index), [0, 1])
+})
+
+test('对象项保留 name 与 caption,caption 缺省回落到 name', () => {
+    const items = galleryItems([
+        { url: 'a.jpg', name: '隐患照片' },
+        { url: 'b.jpg', name: '现场', caption: '验收 · 第 1 张' },
+    ])
+    assert.equal(items[0].caption, '隐患照片')
+    assert.equal(items[0].alt, '隐患照片')
+    assert.equal(items[1].caption, '验收 · 第 1 张')
+})
+
+test('只有名字没有地址的项保留,地址留空(与改造前附件行为一致)', () => {
+    const items = galleryItems([{ name: '无图附件' }, { url: '' }])
+    assert.equal(items.length, 1)
+    assert.equal(items[0].url, '')
+    assert.equal(items[0].name, '无图附件')
+})
+
+test('同一地址出现两次也各有唯一 key', () => {
+    const items = galleryItems(['same.jpg', 'same.jpg'])
+    assert.equal(items.length, 2)
+    assert.notEqual(items[0].key, items[1].key)
+})
+
+test('非数组、空值输入得到空列表', () => {
+    assert.deepEqual(galleryItems(null), [])
+    assert.deepEqual(galleryItems(undefined), [])
+    assert.deepEqual(galleryItems({}), [])
+})
+
+test('解析器返回空串时标记为不可用,不拿原始串兜底', () => {
+    const items = resolveGalleryItems(galleryItems(['secret/with-credentials.jpg']), () => '')
+    assert.equal(items[0].available, false)
+    assert.equal(items[0].src, '')
+})
+
+test('解析成功的项带上 src 并标记可用', () => {
+    const items = resolveGalleryItems(galleryItems(['a/1.jpg']), (url) => 'http://img/' + url)
+    assert.equal(items[0].available, true)
+    assert.equal(items[0].src, 'http://img/a/1.jpg')
+})
+
+test('没有地址的项不做解析,直接不可用', () => {
+    let called = 0
+    const items = resolveGalleryItems(galleryItems([{ name: '无图附件' }]), () => { called += 1; return 'x' })
+    assert.equal(called, 0)
+    assert.equal(items[0].available, false)
+})