From 9f72e21463d735233528c932ab621e4221b6ff94 Mon Sep 17 00:00:00 2001 From: tt <1301725380@qq.com> Date: Tue, 22 Oct 2024 11:35:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:fetch=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/src/views/proManagement/contract.vue | 40 +++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/admin/src/views/proManagement/contract.vue b/admin/src/views/proManagement/contract.vue index 858cd169..16a6cdda 100644 --- a/admin/src/views/proManagement/contract.vue +++ b/admin/src/views/proManagement/contract.vue @@ -101,14 +101,52 @@ export default { if (res.error === 0) { let blob_url = type === 1 ? res.data.domestic : res.data.abroad; const extension = blob_url.substring(blob_url.lastIndexOf(".")); + console.log(blob_url, "blob_url"); let txt = (type === 1 ? "境内合同" : "境外合同") + extension; - const url = window.URL.createObjectURL(new Blob([blob_url])); + const url = URL.createObjectURL(new Blob([blob_url])); const link = document.createElement("a"); link.style.display = "none"; link.href = url; link.setAttribute("download", txt); document.body.appendChild(link); link.click(); + document.body.removeChild(link); + URL.revokeObjectURL(objectUrl); + } + console.log(res, "下载合同"); + }, + async downloadWord(type) { + const res = await postDownloadContractApi(); + if (res.error === 0) { + let fileUrl = type === 1 ? res.data.domestic : res.data.abroad; + if (fileUrl) { + fetch(fileUrl) + .then((response) => response.blob()) + .then((blob) => { + const link = document.createElement("a"); + const objectUrl = URL.createObjectURL(blob); + link.href = objectUrl; + link.download = url.split("/").pop(); // Extract filename from URL + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + URL.revokeObjectURL(objectUrl); + }) + .catch((error) => { + this.$message({ + showClose: true, + message: "下载失败", + type: "error", + }); + console.error("Download error:", error); + }); + } else { + this.$message({ + showClose: true, + message: "暂无下载链接", + type: "warning", + }); + } } console.log(res, "下载合同"); },