fix:fetch下载
This commit is contained in:
parent
d4d973aa12
commit
9f72e21463
|
@ -101,14 +101,52 @@ export default {
|
||||||
if (res.error === 0) {
|
if (res.error === 0) {
|
||||||
let blob_url = type === 1 ? res.data.domestic : res.data.abroad;
|
let blob_url = type === 1 ? res.data.domestic : res.data.abroad;
|
||||||
const extension = blob_url.substring(blob_url.lastIndexOf("."));
|
const extension = blob_url.substring(blob_url.lastIndexOf("."));
|
||||||
|
console.log(blob_url, "blob_url");
|
||||||
let txt = (type === 1 ? "境内合同" : "境外合同") + extension;
|
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");
|
const link = document.createElement("a");
|
||||||
link.style.display = "none";
|
link.style.display = "none";
|
||||||
link.href = url;
|
link.href = url;
|
||||||
link.setAttribute("download", txt);
|
link.setAttribute("download", txt);
|
||||||
document.body.appendChild(link);
|
document.body.appendChild(link);
|
||||||
link.click();
|
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, "下载合同");
|
console.log(res, "下载合同");
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue