Files
jinshen-website/app/components/DocumentList.vue
R2m1liA 359aaec8a9 style: 格式化项目代码
- 根据prettier配置格式化整个项目的代码
2025-09-17 15:50:29 +08:00

76 lines
1.7 KiB
Vue

<template>
<div class="document-list">
<el-card
v-for="(doc, index) in documents"
:key="index"
class="document-card"
>
<div class="document-info">
<h3>{{ doc.caption || doc.name }}</h3>
<div class="document-content">
<span v-if="doc.size" class="document-meta"
>大小: {{ formatFileSize(doc.size) }}
</span>
<span v-if="doc.ext" class="document-meta"
>格式: {{ formatFileExtension(doc.ext) }}</span
>
<el-button
class="download-button"
type="primary"
@click="handleDownload(doc.name, doc.url)"
>
下载
</el-button>
</div>
</div>
</el-card>
</div>
</template>
<script setup lang="ts">
defineProps({
documents: {
type: Array as () => Array<StrapiMedia>,
default: () => [],
},
});
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-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>