From 4e2fc08e8ca3b5e584feddc908ae5ca9a49516f8 Mon Sep 17 00:00:00 2001 From: NiSen Date: Wed, 28 Jun 2023 18:56:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E7=9A=84=E4=BB=8E=E6=96=B0?= =?UTF-8?q?=E5=B0=81=E8=A3=85=E4=B8=80=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useDownload.js | 12 ++++++------ src/views/case/CaseRecommended.vue | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/hooks/useDownload.js b/src/hooks/useDownload.js index cef1c4d5..f0056a12 100644 --- a/src/hooks/useDownload.js +++ b/src/hooks/useDownload.js @@ -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); diff --git a/src/views/case/CaseRecommended.vue b/src/views/case/CaseRecommended.vue index f9cf9964..ab184b4f 100644 --- a/src/views/case/CaseRecommended.vue +++ b/src/views/case/CaseRecommended.vue @@ -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("信息下载失败");