| 对比新文件 |
| | |
| | | <script setup> |
| | | const props = defineProps({ |
| | | fileList: { |
| | | type: Array, |
| | | default: () => [], |
| | | }, |
| | | thumbSize: { |
| | | type: Number, |
| | | default: 72, |
| | | }, |
| | | gap: { |
| | | type: Number, |
| | | default: 10, |
| | | }, |
| | | }) |
| | | |
| | | const normalizedList = computed(() => { |
| | | return (props.fileList || []) |
| | | .filter((item) => item && item.previewURL) |
| | | .map((item, index) => ({ |
| | | id: item.id ?? index, |
| | | name: item.originalFilename || `image-${index + 1}`, |
| | | url: item.previewURL, |
| | | })) |
| | | }) |
| | | const previewUrls = computed(() => normalizedList.value.map((item) => item.url)) |
| | | </script> |
| | | |
| | | <template> |
| | | <div class="attachment-image-preview"> |
| | | <div v-if="!normalizedList.length" class="empty">鏆傛棤鍥剧墖</div> |
| | | |
| | | <div v-else class="thumbs" :style="{ gap: `${gap}px` }"> |
| | | <el-image |
| | | v-for="(item, index) in normalizedList" |
| | | :key="item.id" |
| | | class="thumb" |
| | | :style="{ width: `${thumbSize}px`, height: `${thumbSize}px` }" |
| | | :src="item.url" |
| | | :preview-src-list="previewUrls" |
| | | :initial-index="index" |
| | | fit="cover" |
| | | preview-teleported |
| | | /> |
| | | </div> |
| | | </div> |
| | | </template> |
| | | |
| | | <style scoped lang="scss"> |
| | | .attachment-image-preview { |
| | | width: 100%; |
| | | } |
| | | |
| | | .empty { |
| | | height: 120px; |
| | | display: flex; |
| | | align-items: center; |
| | | justify-content: center; |
| | | color: var(--el-text-color-secondary); |
| | | border: 1px dashed var(--el-border-color); |
| | | border-radius: 8px; |
| | | } |
| | | |
| | | .thumbs { |
| | | display: flex; |
| | | flex-wrap: wrap; |
| | | } |
| | | |
| | | .thumb { |
| | | border: 1px solid var(--el-border-color); |
| | | border-radius: 6px; |
| | | overflow: hidden; |
| | | cursor: pointer; |
| | | background: #fff; |
| | | } |
| | | </style> |