diff --git a/src/views/modules/base/smartImport.vue b/src/views/modules/base/smartImport.vue index 6d4ffa360..cfd6e8822 100644 --- a/src/views/modules/base/smartImport.vue +++ b/src/views/modules/base/smartImport.vue @@ -285,27 +285,36 @@ export default { data: params, }) .then((res) => { - // this.download(res.data, title + '.xls') - if (res.headers["content-disposition"]) { - let fileName = window.decodeURI( - res.headers["content-disposition"] - .split(";")[1] - .split("=")[1] - ); - console.log("filename", fileName); - let blob = new Blob([res.data], { - type: "application/vnd.ms-excel", - }); - var url = window.URL.createObjectURL(blob); - var aLink = document.createElement("a"); - aLink.style.display = "none"; - aLink.href = url; - aLink.setAttribute("download", fileName); - document.body.appendChild(aLink); - aLink.click(); - document.body.removeChild(aLink); //下载完成移除元素 - window.URL.revokeObjectURL(url); //释放掉blob对象 - } else this.$message.error("下载失败"); + const url = window.URL.createObjectURL(new Blob([res.data])) + const aLink = document.createElement('a') + aLink.style.display = 'none' + aLink.href = url + aLink.setAttribute('download', '人员导入模板.zip') + document.body.appendChild(aLink) + aLink.click() + document.body.removeChild(aLink) + window.URL.revokeObjectURL(url) + // // this.download(res.data, title + '.xls') + // if (res.headers["content-disposition"]) { + // let fileName = window.decodeURI( + // res.headers["content-disposition"] + // .split(";")[1] + // .split("=")[1] + // ); + // console.log("filename", fileName); + // let blob = new Blob([res.data], { + // type: "application/vnd.ms-excel", + // }); + // var url = window.URL.createObjectURL(blob); + // var aLink = document.createElement("a"); + // aLink.style.display = "none"; + // aLink.href = url; + // aLink.setAttribute("download", fileName); + // document.body.appendChild(aLink); + // aLink.click(); + // document.body.removeChild(aLink); //下载完成移除元素 + // window.URL.revokeObjectURL(url); //释放掉blob对象 + // } else this.$message.error("下载失败"); }) .catch((err) => { console.log("err", err);