2026-03-11 16:48:44 +08:00
|
|
|
<template>
|
|
|
|
|
<div class="file-list-container">
|
|
|
|
|
<!-- 空数据提示 -->
|
|
|
|
|
<div v-if="fileList.length === 0 && !loading" class="empty-tip">
|
|
|
|
|
<el-empty description="暂无文件数据"></el-empty>
|
|
|
|
|
</div>
|
2026-03-31 11:16:48 +08:00
|
|
|
<!-- 自定义文件列表 -->
|
|
|
|
|
<div v-else class="file-list" v-loading="loading">
|
|
|
|
|
<div
|
|
|
|
|
v-for="file in fileList"
|
|
|
|
|
:key="file.ossId"
|
|
|
|
|
class="file-item"
|
|
|
|
|
>
|
|
|
|
|
<div class="file-info">
|
|
|
|
|
<i class="el-icon-document"></i>
|
|
|
|
|
<span class="file-name">{{ file.originalName }}</span>
|
|
|
|
|
</div>
|
2026-04-06 13:16:45 +08:00
|
|
|
<div class="file-actions">
|
|
|
|
|
<el-button
|
|
|
|
|
type="text"
|
|
|
|
|
icon="el-icon-view"
|
|
|
|
|
@click="handlePreview(file)"
|
|
|
|
|
size="small"
|
|
|
|
|
class="preview-btn"
|
|
|
|
|
>
|
|
|
|
|
预览
|
|
|
|
|
</el-button>
|
|
|
|
|
<el-button
|
|
|
|
|
type="text"
|
|
|
|
|
icon="el-icon-download"
|
|
|
|
|
@click="downloadFile(file)"
|
|
|
|
|
size="small"
|
|
|
|
|
class="download-btn"
|
|
|
|
|
>
|
|
|
|
|
下载
|
|
|
|
|
</el-button>
|
|
|
|
|
</div>
|
2026-03-31 11:16:48 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-04-06 13:16:45 +08:00
|
|
|
|
|
|
|
|
<!-- 文件预览组件 -->
|
|
|
|
|
<file-preview
|
|
|
|
|
:visible.sync="previewVisible"
|
|
|
|
|
:file-url="previewFileUrl"
|
|
|
|
|
:file-name="previewFileName"
|
|
|
|
|
/>
|
2026-03-11 16:48:44 +08:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import { listByIds } from "@/api/system/oss";
|
2026-04-06 13:16:45 +08:00
|
|
|
import FilePreview from "../FilePreview";
|
2026-03-11 16:48:44 +08:00
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: "FileList",
|
2026-04-06 13:16:45 +08:00
|
|
|
components: {
|
|
|
|
|
FilePreview
|
|
|
|
|
},
|
2026-03-11 16:48:44 +08:00
|
|
|
props: {
|
|
|
|
|
ossIds: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: '',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
fileList: [],
|
2026-04-06 13:16:45 +08:00
|
|
|
loading: false, // 加载状态
|
|
|
|
|
// 预览相关
|
|
|
|
|
previewVisible: false,
|
|
|
|
|
previewFileUrl: '',
|
|
|
|
|
previewFileName: ''
|
2026-03-11 16:48:44 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
watch: {
|
|
|
|
|
ossIds: {
|
|
|
|
|
handler(val) {
|
|
|
|
|
if (val) {
|
|
|
|
|
this.getFileList();
|
|
|
|
|
} else {
|
|
|
|
|
this.fileList = []; // 清空文件列表
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
immediate: true,
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
async getFileList() {
|
|
|
|
|
if (!this.ossIds) return;
|
|
|
|
|
|
|
|
|
|
this.loading = true;
|
|
|
|
|
try {
|
|
|
|
|
let res = await listByIds(this.ossIds);
|
|
|
|
|
this.fileList = res.data || [];
|
|
|
|
|
} catch (error) {
|
|
|
|
|
this.$message.error('获取文件列表失败:' + (error.message || '未知错误'));
|
|
|
|
|
this.fileList = [];
|
|
|
|
|
} finally {
|
|
|
|
|
this.loading = false;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 文件下载方法
|
|
|
|
|
downloadFile(file) {
|
|
|
|
|
if (!file || !file.ossId) {
|
|
|
|
|
this.$message.warning('文件下载地址不存在');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.$download.oss(file.ossId);
|
2026-04-06 13:16:45 +08:00
|
|
|
},
|
|
|
|
|
// 预览文件
|
|
|
|
|
handlePreview(file) {
|
|
|
|
|
this.previewFileUrl = file.url;
|
|
|
|
|
this.previewFileName = file.originalName;
|
|
|
|
|
this.previewVisible = true;
|
2026-03-11 16:48:44 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
.file-list-container {
|
|
|
|
|
width: 100%;
|
|
|
|
|
min-height: 100px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.empty-tip {
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
align-items: center;
|
|
|
|
|
height: 200px;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-31 11:16:48 +08:00
|
|
|
.file-list {
|
|
|
|
|
width: 100%;
|
|
|
|
|
border: 1px solid #ebeef5;
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.file-item {
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
align-items: center;
|
|
|
|
|
padding: 12px 16px;
|
|
|
|
|
border-bottom: 1px solid #ebeef5;
|
|
|
|
|
transition: background-color 0.3s;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-06 13:16:45 +08:00
|
|
|
.file-actions {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: 16px;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-31 11:16:48 +08:00
|
|
|
.file-item:last-child {
|
|
|
|
|
border-bottom: none;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.file-item:hover {
|
|
|
|
|
background-color: #f5f7fa;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.file-info {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
flex: 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.file-info .el-icon-document {
|
|
|
|
|
margin-right: 8px;
|
|
|
|
|
color: #409eff;
|
|
|
|
|
font-size: 16px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.file-name {
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
color: #606266;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
flex: 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.download-btn {
|
|
|
|
|
margin: 0;
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
color: #409eff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.download-btn:hover {
|
|
|
|
|
color: #66b1ff;
|
2026-03-11 16:48:44 +08:00
|
|
|
}
|
|
|
|
|
</style>
|