This commit is contained in:
zlwu committed 2026-09-24 09:59:26 +08:00
1 parent 8248e5ef15
commit b9b4cc2673
57 files changed
+42800 -30473

No files matched your search

@@ -0,0 +1,196 @@
<!-- 评论附件缩略图:文字区分「引用 / 上传」;预览/下载/移除为图标 -->
<template>
<div class="oa-cmt-files">
<div v-for="(f, idx) in files" :key="`${f.url}-${idx}`" class="oa-cmt-files__item">
<div class="oa-cmt-files__thumb" :title="f.fileName || '附件'">
<img v-if="isImage(f)" :src="fullUrl(f.url)" :alt="f.fileName || '附件'" />
<el-icon v-else-if="isVideo(f)" :size="16"><VideoPlay /></el-icon>
<el-icon v-else :size="16"><Document /></el-icon>
<span class="oa-cmt-files__badge">{{ sourceLabel(f) }}</span>
<span class="oa-cmt-files__actions">
<button type="button" title="预览" aria-label="预览" @click.stop="preview(f)">
<el-icon :size="14"><ZoomIn /></el-icon>
</button>
<button type="button" title="下载" aria-label="下载" @click.stop="download(f)">
<el-icon :size="14"><Download /></el-icon>
</button>
<button
v-if="removable"
type="button"
title="移除"
aria-label="移除"
@click.stop="emit('remove', idx)"
>
<el-icon :size="14"><Delete /></el-icon>
</button>
</span>
</div>
<div class="oa-cmt-files__name" :title="f.fileName || '附件'">{{ f.fileName || '附件' }}</div>
</div>
</div>
<el-dialog
v-model="previewOpen"
title="预览"
width="720px"
append-to-body
align-center
modal-class="protocol-dialog-mask"
>
<img v-if="previewImage" class="oa-cmt-files__preview" :src="previewImage" alt="" />
</el-dialog>
</template>
<script setup lang="ts">
import { Delete, Document, Download, VideoPlay, ZoomIn } from '@element-plus/icons-vue'
import type { OaCommentAttachmentRef } from '@/api/oaApproval'
import { attachmentFullUrl } from '@/composables/useAttachmentActions'
import { downloadAttachmentFile } from '@/utils/download-attachment'
import { isOaUploadImageFile, isOaUploadVideoFile } from '@/utils/oa-upload-file-type'
defineOptions({ name: 'OaCommentFileCards' })
defineProps<{
files: OaCommentAttachmentRef[]
removable?: boolean
}>()
const emit = defineEmits<{ remove: [index: number] }>()
const previewOpen = ref(false)
const previewImage = ref('')
function asFile(f: OaCommentAttachmentRef) {
return { name: f.fileName, url: f.url }
}
function isImage(f: OaCommentAttachmentRef) {
return isOaUploadImageFile(asFile(f))
}
function isVideo(f: OaCommentAttachmentRef) {
return isOaUploadVideoFile(asFile(f))
}
function fullUrl(url: string) {
return attachmentFullUrl(url) || url
}
function sourceLabel(f: OaCommentAttachmentRef) {
return f.source === 'upload' ? '上传' : '引用'
}
function preview(f: OaCommentAttachmentRef) {
const url = fullUrl(f.url)
if (!url) return
if (isImage(f)) {
previewImage.value = url
previewOpen.value = true
return
}
window.open(url, '_blank')
}
function download(f: OaCommentAttachmentRef) {
void downloadAttachmentFile(
{ fileUrl: f.url, fileName: f.fileName },
{ fullFileUrl: (u) => attachmentFullUrl(u) }
)
}
</script>
<style scoped lang="scss">
.oa-cmt-files {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 8px;
}
.oa-cmt-files__item {
width: 88px;
}
.oa-cmt-files__thumb {
position: relative;
display: flex;
align-items: center;
justify-content: center;
width: 88px;
height: 64px;
overflow: hidden;
color: #64748b;
background: #f8fafc;
border: 1px solid #e2e8f0;
border-radius: 8px;
img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
}
&:hover .oa-cmt-files__actions {
opacity: 1;
}
}
.oa-cmt-files__badge {
position: absolute;
top: 2px;
left: 2px;
z-index: 1;
padding: 0 4px;
color: #334155;
font-size: 10px;
line-height: 16px;
background: rgb(255 255 255 / 92%);
border-radius: 4px;
}
.oa-cmt-files__actions {
position: absolute;
inset: 0;
z-index: 2;
display: flex;
align-items: center;
justify-content: center;
gap: 4px;
background: rgb(15 23 42 / 45%);
opacity: 0;
transition: opacity 0.15s;
button {
display: inline-flex;
align-items: center;
justify-content: center;
width: 26px;
height: 26px;
padding: 0;
color: #fff;
cursor: pointer;
background: rgb(255 255 255 / 18%);
border: none;
border-radius: 6px;
&:hover {
background: var(--primary, #10b981);
}
}
}
.oa-cmt-files__name {
margin-top: 4px;
color: var(--mint-text, #334155);
font-size: 12px;
line-height: 1.35;
word-break: break-all;
overflow-wrap: anywhere;
white-space: normal;
}
.oa-cmt-files__preview {
display: block;
width: 100%;
}
</style>