前后端导出数据功能调试

This commit is contained in:
zhangtao
2024-12-12 19:43:03 +08:00
parent dd7f2b0a46
commit fda2b07b54
12 changed files with 228 additions and 129 deletions
+43 -24
View File
@@ -464,33 +464,52 @@ const handleModalSumbit = () => {
}
}
/** 导出按钮操作 */
const handleExport = () => {
// 构建查询参数
const params = {
...queryState,
page_no: 1,
page_size: pagination.total // 导出所有数据
};
// 调用 exportLog 接口
exportRole(params).then(response => {
const blob = new Blob([response.data], { type: 'application/vnd.ms-excel' });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `role_${new Date().getTime()}.xlsx`; // 设置下载文件名
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
message.success('导出成功');
}).catch(error => {
console.error('导出失败:', error);
message.error('导出失败');
// 导出按钮操作
const handleExport = () => {
Modal.confirm({
title: '警告',
content: '是否确认导出所有角色数据?',
onOk() {
const body = {
...queryState,
page_no: 1,
page_size: pagination.total
};
message.loading('正在导出数据,请稍候...', 0);
return exportRole(body).then(response => {
const blob = new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
console.log("blob", blob);
// 从响应头获取文件名
const contentDisposition = response.headers['content-disposition'];
let fileName = '角色.xlsx';
if (contentDisposition) {
const fileNameMatch = contentDisposition.match(/filename=(.*?)(;|$)/);
if (fileNameMatch) {
fileName = decodeURIComponent(fileNameMatch[1]);
}
}
console.log(fileName);
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = fileName;
document.body.appendChild(link);
link.click();
message.destroy();
message.success('导出成功');
}).catch((error) => {
message.destroy();
console.error('导出错误:', error);
message.error('文件处理失败');
});
},
onCancel() {
message.info('已取消导出');
}
});
};
// 授权弹窗事件
const handlePermissionDrawerEvent = () => loadingData();
</script>