|
@@ -13,13 +13,13 @@
|
|
|
<template v-else>
|
|
<template v-else>
|
|
|
<ul class="image-gallery__list" :class="`is-${size}`" data-image-gallery>
|
|
<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)">
|
|
<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)" />
|
|
<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>
|
|
<span v-if="hint" class="image-gallery__hint">{{ stateOf(item) === 'ready' ? hint : '图片加载中…' }}</span>
|
|
|
</button>
|
|
</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>
|
|
<button v-if="canRetry(item)" type="button" class="image-gallery__retry" @click="retry(item)">重试</button>
|
|
|
</span>
|
|
</span>
|
|
|
<span v-if="item.name" class="image-gallery__name">{{ item.name }}</span>
|
|
<span v-if="item.name" class="image-gallery__name">{{ item.name }}</span>
|
|
@@ -42,7 +42,7 @@ const props = defineProps({
|
|
|
/** 没有图时说的话(措辞由各分区给,组件不编业务文案)。 */
|
|
/** 没有图时说的话(措辞由各分区给,组件不编业务文案)。 */
|
|
|
emptyText: { type: String, default: '暂无图片' },
|
|
emptyText: { type: String, default: '暂无图片' },
|
|
|
/** `thumb` 小方块 / `large` 整宽主图。 */
|
|
/** `thumb` 小方块 / `large` 整宽主图。 */
|
|
|
- size: { type: String, default: 'thumb' },
|
|
|
|
|
|
|
+ size: { type: String, default: 'thumb', validator: (value) => ['thumb', 'large'].includes(value) },
|
|
|
/** 主图上的提示文字(设备图片用「点击放大」;列表附图不传)。 */
|
|
/** 主图上的提示文字(设备图片用「点击放大」;列表附图不传)。 */
|
|
|
hint: { type: String, default: '' },
|
|
hint: { type: String, default: '' },
|
|
|
})
|
|
})
|
|
@@ -90,6 +90,10 @@ function open(item) {
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
<style scoped>
|
|
|
|
|
+/* scoped 的 * 规则进不了子组件内部,这里自带一份,缩略图才是精确的 44u(含边框)。 */
|
|
|
|
|
+.image-gallery,
|
|
|
|
|
+.image-gallery * { box-sizing: border-box; }
|
|
|
|
|
+
|
|
|
.image-gallery { min-width: 0; }
|
|
.image-gallery { min-width: 0; }
|
|
|
|
|
|
|
|
.image-gallery__empty {
|
|
.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:hover,
|
|
|
.image-gallery__list.is-large .image-gallery__button:focus-visible { border-color: rgba(53, 216, 255, .7); }
|
|
.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-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 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 {
|
|
.image-gallery__hint {
|
|
|
position: absolute;
|
|
position: absolute;
|