Sfoglia il codice sorgente

refactor(cockpit): 图片组件按审查意见收口角标高度、可访问名与盒子模型

- 主图加载完成前给带角标的按钮一个占位高度,否则角标被 overflow:hidden 裁掉、figure 会从 0 高跳变。
- 维修前、后附件补 alt 标出组别与序号,两组的第一张不再都念成「第 1 张图片」。
- 失败占位的状态文本与重试按钮分开:live region 里不再夹一个可点控件。
- 组件自带 box-sizing:scoped 的 * 规则进不了子组件,缩略图曾比原来的 44u 宽 2px。
- 删掉恒被覆盖的 height、永远到不了的 empty-text、无主 JSDoc、时间线里失效的 flex 规则。
- 域层去掉恒等解析兜底:忘传解析器要立刻报错,而不是静默绕过唯一解析器;size 加取值校验。
ChenJZ 3 ore fa
parent
commit
71dc40067e

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

@@ -86,7 +86,6 @@ 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))
-// 附件展示与放大统一交 ImageGallery:地址解析走组件内的唯一解析器,这里不再拼前缀。
 
 // 分区图标:静态内联 SVG(不引第三方图标库),统一当前色 14px。
 const SECTION_ICONS = {

+ 9 - 7
src/modules/cockpit/components/EquipmentDetailSections.vue

@@ -332,7 +332,7 @@
                                 :data-work-order-images="group.key"
                             >
                                 <span class="equipment-section__wo-label">{{ group.label }}附件</span>
-                                <ImageGallery :items="proofItems(order, group)" empty-text="暂无附件" />
+                                <ImageGallery :items="proofItems(order, group)" />
                             </div>
                         </template>
 
@@ -502,10 +502,14 @@ function setWoTab(order, key) {
     woTabs.value = { ...woTabs.value, [order.code]: key }
 }
 
-/** 工单维修前/后附件:每张带同一句 caption(工单 · 前后),不让组件猜。 */
+/** 工单维修前/后附件:alt 标出组别与序号,caption 带工单号(读屏与悬浮都能分清是哪一组)。 */
 function proofItems(order, group) {
     const title = order?.title || '工单'
-    return (group.images || []).map((path) => ({ url: path, caption: `${title} · ${group.label}附件` }))
+    return (group.images || []).map((path, index) => ({
+        url: path,
+        alt: `${group.label}附件${index + 1}`,
+        caption: `${title} · ${group.label}附件`,
+    }))
 }
 
 // ---- 票 46 返工第 1 条:标签页切换(弃用六块竖排的长滚动)----
@@ -758,19 +762,17 @@ function image(panel) {
  * 误说成「后端未提供」,还会与下面的「拍摄于 …」自相矛盾。
  */
 function deviceImageItems(panel) {
-    const view = imageView(panel.section.data)
+    const view = image(panel)
     return view.hasImage ? [{ url: view.url, alt: `${props.deviceCode} 设备图片` }] : []
 }
 
 /** 换设备/换图时重建组件(连带复位预览与加载状态);用后端原始地址做键。 */
 function deviceImageKey(panel) {
-    return imageView(panel.section.data).url
+    return image(panel).url
 }
 watch([() => props.deviceCode, activeTab], () => {
     closeAudioPlayer()
 })
-/** 图片查看交互已收口到通用 ImageGallery(内部弹 ImagePreview,背景点击 / Esc 关闭)。 */
-
 function emptyList(label) {
     return emptyListText(label)
 }

+ 10 - 5
src/modules/cockpit/components/ImageGallery.vue

@@ -13,13 +13,13 @@
         <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)">
+                    <button v-if="isShown(item)" type="button" class="image-gallery__button" :class="{ 'has-hint': hint }" :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">
-                        图片加载失败
+                    <span v-else-if="stateOf(item) === 'failed'" class="image-gallery__failed">
+                        <span role="status">图片加载失败</span>
                         <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>
@@ -42,7 +42,7 @@ const props = defineProps({
     /** 没有图时说的话(措辞由各分区给,组件不编业务文案)。 */
     emptyText: { type: String, default: '暂无图片' },
     /** `thumb` 小方块 / `large` 整宽主图。 */
-    size: { type: String, default: 'thumb' },
+    size: { type: String, default: 'thumb', validator: (value) => ['thumb', 'large'].includes(value) },
     /** 主图上的提示文字(设备图片用「点击放大」;列表附图不传)。 */
     hint: { type: String, default: '' },
 })
@@ -90,6 +90,10 @@ function open(item) {
 </script>
 
 <style scoped>
+/* scoped 的 * 规则进不了子组件内部,这里自带一份,缩略图才是精确的 44u(含边框)。 */
+.image-gallery,
+.image-gallery * { box-sizing: border-box; }
+
 .image-gallery { min-width: 0; }
 
 .image-gallery__empty {
@@ -135,9 +139,10 @@ function open(item) {
 .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__button img { display: block; width: 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__list.is-large .image-gallery__button.has-hint { min-height: calc(96 * var(--u, 1px)); }
 
 .image-gallery__hint {
     position: absolute;

+ 2 - 5
src/modules/cockpit/components/WorkOrderTimeline.vue

@@ -104,7 +104,7 @@ function shotItems(step) {
     return (step.attachImages || []).map((path, shot) => ({
         url: path,
         alt: `${step.operationName || '处置'}第${shot + 1}张图片`,
-        caption: `${step.operatedAt || ''} · ${step.operationName || '处置'}第${shot + 1}张图片`,
+        caption: [step.operatedAt, `${step.operationName || '处置'}第${shot + 1}张图片`].filter(Boolean).join(' · '),
     }))
 }
 
@@ -233,11 +233,8 @@ function nodeTone(node) {
     align-items: baseline;
 }
 
-/* 维修过程图片(维护者 2026-11-23):缩略图铺成一行,点开看大图。 */
+/* 维修过程图片(维护者 2026-11-23):独占一行;换行与间距由共享图片组件自己管。 */
 .wo-timeline__shots {
-    display: flex;
-    flex-wrap: wrap;
-    gap: calc(4 * var(--u, 1px));
     flex-basis: 100%;
     margin-top: calc(2 * var(--u, 1px));
 }

+ 1 - 2
src/modules/cockpit/domain/imageGallery.js

@@ -49,9 +49,8 @@ export function galleryItems(value) {
  * 解析不出的项标记 `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) || '' : ''
+        const src = item.url ? resolve(item.url) || '' : ''
         return { ...item, src, available: !!src }
     })
 }