fix quarterlyresults

This commit is contained in:
张 元山 2025-05-26 15:30:58 +08:00
parent b184eba64d
commit 22e9b74173
2 changed files with 84 additions and 38 deletions

View File

@ -345,29 +345,52 @@ const handleSearch = () => {
console.log("搜索:", searchQuery.value);
};
const downloadPdf = async (pdfResource, filename = "") => {
try {
// PDF
const response = await fetch(pdfResource);
const blob = await response.blob();
const downloadPdf = (url) => {
// a
const link = document.createElement("a");
link.href = url;
// Blob URL
const blobUrl = URL.createObjectURL(blob);
//
let fileName = url.split("/").pop();
//
if (fileName.includes("?") || fileName.includes("_t=")) {
fileName = fileName.split(/[?_]/)[0];
}
link.download = fileName;
link.target = "_blank";
//
const a = document.createElement("a");
a.href = blobUrl;
a.download = filename || pdfResource.split("/").pop() || "download.pdf";
//
const isMobile =
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
navigator.userAgent
);
//
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
if (isMobile) {
// 使fetchblob
fetch(url)
.then((response) => response.blob())
.then((blob) => {
const objectUrl = URL.createObjectURL(blob);
link.href = objectUrl;
document.body.appendChild(link);
link.click();
// Blob URL
URL.revokeObjectURL(blobUrl);
} catch (error) {
console.error("下载PDF文件失败:", error);
//
setTimeout(() => {
document.body.removeChild(link);
URL.revokeObjectURL(objectUrl);
}, 100);
})
.catch((error) => {
console.error("下载文件时出错:", error);
// fetch退window.open
window.open(url, "_blank");
});
} else {
//
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
};
</script>

View File

@ -345,29 +345,52 @@ const handleSearch = () => {
console.log("搜索:", searchQuery.value);
};
const downloadPdf = async (pdfResource, filename = "") => {
try {
// PDF
const response = await fetch(pdfResource);
const blob = await response.blob();
const downloadPdf = (url) => {
// a
const link = document.createElement("a");
link.href = url;
// Blob URL
const blobUrl = URL.createObjectURL(blob);
//
let fileName = url.split("/").pop();
//
if (fileName.includes("?") || fileName.includes("_t=")) {
fileName = fileName.split(/[?_]/)[0];
}
link.download = fileName;
link.target = "_blank";
//
const a = document.createElement("a");
a.href = blobUrl;
a.download = filename || pdfResource.split("/").pop() || "download.pdf";
//
const isMobile =
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
navigator.userAgent
);
//
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
if (isMobile) {
// 使fetchblob
fetch(url)
.then((response) => response.blob())
.then((blob) => {
const objectUrl = URL.createObjectURL(blob);
link.href = objectUrl;
document.body.appendChild(link);
link.click();
// Blob URL
URL.revokeObjectURL(blobUrl);
} catch (error) {
console.error("下载PDF文件失败:", error);
//
setTimeout(() => {
document.body.removeChild(link);
URL.revokeObjectURL(objectUrl);
}, 100);
})
.catch((error) => {
console.error("下载文件时出错:", error);
// fetch退window.open
window.open(url, "_blank");
});
} else {
//
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
};
</script>