feat(document): 为文档添加下载与预览界面:
All checks were successful
deploy to server / build-and-deploy (push) Successful in 2m58s

- 添加路由: download路由用于下载文件, preview路由用于文件预览
- 添加组件: FilePreviewer封装了若干格式文件的预览功能(目前支持pdf,
  image, text, video等)
- 服务端API: 添加download和file分别用于处理文件下载请求与元数据获取请求
- 类型标注调整:
  将原先位于app/types内的类型标注文件移至shared/types内,让app与server共享类型标注
- 国际化文本添加: 为相关页面添加国际化文本
This commit is contained in:
2025-10-28 14:41:54 +08:00
21 changed files with 468 additions and 18 deletions

View File

@ -4,6 +4,7 @@
v-for="(doc, index) in documents"
:key="index"
class="document-card"
@click="handleClick(doc.fileId)"
>
<div class="document-info">
<h3>{{ doc.title }}</h3>
@ -15,13 +16,6 @@
>格式:
{{ formatFileExtension(getFileExtension(doc.filename)) }}</span
>
<el-button
class="download-button"
type="primary"
@click="handleDownload(doc.title, doc.url)"
>
下载
</el-button>
</div>
</div>
</el-card>
@ -36,18 +30,13 @@
},
});
const handleDownload = async (fileName: string, fileUrl: string) => {
const response = await fetch(fileUrl);
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const localePath = useLocalePath();
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);
const handleClick = (id: string) => {
// 获取路由参数
if (id) {
navigateTo(localePath(`/download/${id}`));
}
};
</script>
@ -59,6 +48,16 @@
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);