setExportLoading(true);
axios({
method: ‘post’,
url: ‘/approval/v1/nomination/export’, // 请求地址
data: params2, // 参数
responseType: ‘blob’, // 表明返回服务器返回的数据类型
}).then(res => {
if (res.data.type.includes(‘application/json’)) {
let reader = new FileReader();
reader.onload = (event) => {
let content = JSON.parse(reader.result);
message.error(content.msg);
}
reader.readAsText(res.data);
setExportLoading(false);
return true;
} else {
let fileName = ‘’;
if (type === ‘conformList’) {
fileName = ‘符合条件名单’ + moment().format(‘YYYYMMDDHHmmss’) + ‘.xlsx’;
} else {
fileName = ‘不符合条件名单’ + moment().format(‘YYYYMMDDHHmmss’) + ‘.xlsx’;
}
if (‘msSaveOrOpenBlob’ in navigator) {//兼容ie浏览器下载报传递给系统调用的数据区域太小.
let data = res.data;
const blob = new Blob([data], { type: ‘application/vnd.ms-excel’ });
window.navigator.msSaveOrOpenBlob(blob, fileName);
return;
} else {
const blob = res.data;
const reader = new FileReader();
reader.readAsDataURL(blob);
reader.onload = (e) => {
const a = document.createElement(‘a’);
a.download = fileName;
a.style.display = ‘none’;
a.href = e.target.result;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
}
setExportLoading(false);
}
})
上传下载0117
![](https://img-home.csdnimg.cn/images/20240711042549.png)