下载的从新封装一下

This commit is contained in:
NiSen
2023-06-28 18:56:09 +08:00
parent 3d07b37679
commit 4e2fc08e8c
2 changed files with 7 additions and 7 deletions

View File

@@ -2,15 +2,15 @@
/**
*
* @param {*} data 文件流Blob对象
* @param {*} mimeType 类型
* @param {*} fileName 名字
* @param {String} fileType [导出文件类型] 默认值 xls
* @param {String} fileName [导出文件名称] 默认值 导出文件
*/
const useDownload = (data, fileName, mimeType = 'application/vnd.ms-excel;charset=UTF-8') => {
const useDownload = (data, fileName = '导出文件', fileType = 'xls') => {
const link = document.createElement('a');// 创建a标签
let blob = new Blob([data], { type: mimeType }); // 设置文件类型
// let blob = new Blob([data], { type: mimeType }); // 设置文件类型
link.style.display = "none";
link.href = URL.createObjectURL(blob); // 创建URL
link.setAttribute("download", fileName);
link.href = URL.createObjectURL(data); // 创建URL
link.setAttribute("download", `${fileName}.${fileType}`);
document.body.appendChild(link);
link.click();
URL.revokeObjectURL(link.href);

View File

@@ -248,7 +248,7 @@ function handleOper(record, type) {
const downloadInfo = (record) => {
caseInfoDownload({ casesRecommendId: record.id })
.then((res) => {
useDownload(res.data, '案例信息.xls')
useDownload(res.data, '案例信息')
})
.catch(() => {
message.info("信息下载失败");