Files
jinshen-website/app/components/DocumentList.vue
R2m1liA ff143f980a
All checks were successful
deploy to server / build-and-deploy (push) Successful in 2m59s
feat: 添加preview路由用于文件预览
- preview路由预览文件
- FilePreviewer组件
- 删除Document卡片的下载按钮,使用单独的页面用于文件下载
- preview布局
2025-10-28 14:35:50 +08:00

90 lines
1.9 KiB
Vue

<template>
<div class="document-list">
<el-card
v-for="(doc, index) in documents"
:key="index"
class="document-card"
@click="handleClick(doc.fileId)"
>
<div class="document-info">
<h3>{{ doc.title }}</h3>
<div class="document-content">
<span v-if="doc.size" class="document-meta"
>大小: {{ formatFileSize(doc.size) }}
</span>
<span v-if="doc.filename" class="document-meta"
>格式:
{{ formatFileExtension(getFileExtension(doc.filename)) }}</span
>
</div>
</div>
</el-card>
</div>
</template>
<script setup lang="ts">
defineProps({
documents: {
type: Array as () => Array<ProductDocumentView>,
default: () => [],
},
});
const localePath = useLocalePath();
const handleClick = (id: string) => {
// 获取路由参数
if (id) {
navigateTo(localePath(`/download/${id}`));
}
};
const handleDownload = async (fileName: string, fileUrl: string) => {
const response = await fetch(fileUrl);
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = fileName;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
};
</script>
<style scoped>
.document-list {
display: flex;
flex-direction: column;
gap: 1rem;
width: 100%;
}
.document-card {
cursor: pointer;
transition: all 0.3s ease;
}
.document-card:hover {
transform: translateY(-1px);
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}
.document-meta {
font-size: 0.8rem;
color: var(--el-text-color-secondary);
}
.download-button {
margin-left: auto;
}
.document-content {
display: flex;
align-items: center;
gap: 1rem;
}
</style>