This commit is contained in:
zlwu committed 2025-09-07 20:54:52 +08:00
1 parent 3e3a503fff
commit a3d3fccd33
2 files changed
+44 -2

No files matched your search

+34 -1
View File
@@ -99,6 +99,7 @@
<template #header>
<div class="card-header">
<span>明细数据</span>
<el-button type="success" icon="Download" @click="handleExport" :loading="exportLoading">导出Excel</el-button>
</div>
</template>
<el-table :data="statisticsData.detailData" style="width: 100%" border>
@@ -286,9 +287,41 @@ const resetQuery = () => {
/** 导出按钮操作 */
const handleExport = async () => {
if (!statisticsData.value) {
ElMessage.warning('暂无数据可导出');
return;
}
exportLoading.value = true;
try {
await exportStatistics(queryParams);
const response = await exportStatistics(queryParams);
let blobData: Blob;
if (response instanceof Blob) {
blobData = response;
} else if (response.data instanceof Blob) {
blobData = response.data;
} else {
throw new Error('无效的响应数据格式');
}
// 创建下载链接
const url = window.URL.createObjectURL(blobData);
const link = document.createElement('a');
link.href = url;
// 生成文件名
const now = new Date();
const dateStr = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}`;
const timeStr = `${String(now.getHours()).padStart(2, '0')}_${String(now.getMinutes()).padStart(2, '0')}_${String(now.getSeconds()).padStart(2, '0')}`;
link.download = `学生统计数据_${dateStr}_${timeStr}.xlsx`;
link.style.display = 'none';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
ElMessage.success('导出成功');
} catch (error) {
console.error('导出失败:', error);