Compare commits

..

No commits in common. "b06317e5819a258a19ceb5d212d6d34917343987" and "97fc7d966bd98ae37c89253da3d8356957bd53d5" have entirely different histories.

2 changed files with 10 additions and 24 deletions

View File

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

View File

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