fix file down

This commit is contained in:
张 元山 2025-05-26 16:03:51 +08:00
parent 22e9b74173
commit 44d3555e06
2 changed files with 24 additions and 10 deletions

View File

@ -357,7 +357,6 @@ const downloadPdf = (url) => {
fileName = fileName.split(/[?_]/)[0];
}
link.download = fileName;
link.target = "_blank";
//
const isMobile =
@ -366,12 +365,15 @@ const downloadPdf = (url) => {
);
if (isMobile) {
// 使fetchblob
// 使fetch使blob URL
fetch(url)
.then((response) => response.blob())
.then((blob) => {
const objectUrl = URL.createObjectURL(blob);
link.href = objectUrl;
// downloadtarget="_blank"
link.download = fileName;
link.target = "_self"; //
document.body.appendChild(link);
link.click();
@ -383,11 +385,16 @@ const downloadPdf = (url) => {
})
.catch((error) => {
console.error("下载文件时出错:", error);
// fetch退window.open
window.open(url, "_blank");
// fetch
link.href = url;
link.download = fileName;
link.target = "_self";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
});
} else {
//
//
document.body.appendChild(link);
link.click();
document.body.removeChild(link);

View File

@ -357,7 +357,6 @@ const downloadPdf = (url) => {
fileName = fileName.split(/[?_]/)[0];
}
link.download = fileName;
link.target = "_blank";
//
const isMobile =
@ -366,12 +365,15 @@ const downloadPdf = (url) => {
);
if (isMobile) {
// 使fetchblob
// 使fetch使blob URL
fetch(url)
.then((response) => response.blob())
.then((blob) => {
const objectUrl = URL.createObjectURL(blob);
link.href = objectUrl;
// downloadtarget="_blank"
link.download = fileName;
link.target = "_self"; //
document.body.appendChild(link);
link.click();
@ -383,11 +385,16 @@ const downloadPdf = (url) => {
})
.catch((error) => {
console.error("下载文件时出错:", error);
// fetch退window.open
window.open(url, "_blank");
// fetch
link.href = url;
link.download = fileName;
link.target = "_self";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
});
} else {
//
//
document.body.appendChild(link);
link.click();
document.body.removeChild(link);