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); console.log("搜索:", searchQuery.value);
}; };
const downloadPdf = async (pdfResource, filename = "") => { const downloadPdf = (url) => {
try { // a
// PDF const link = document.createElement("a");
const response = await fetch(pdfResource); link.href = url;
const blob = await response.blob();
// 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"); const isMobile =
a.href = blobUrl; /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
a.download = filename || pdfResource.split("/").pop() || "download.pdf"; navigator.userAgent
);
// if (isMobile) {
document.body.appendChild(a); // 使fetchblob
a.click(); fetch(url)
document.body.removeChild(a); .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); setTimeout(() => {
} catch (error) { document.body.removeChild(link);
console.error("下载PDF文件失败:", error); 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> </script>

View File

@ -345,29 +345,52 @@ const handleSearch = () => {
console.log("搜索:", searchQuery.value); console.log("搜索:", searchQuery.value);
}; };
const downloadPdf = async (pdfResource, filename = "") => { const downloadPdf = (url) => {
try { // a
// PDF const link = document.createElement("a");
const response = await fetch(pdfResource); link.href = url;
const blob = await response.blob();
// 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"); const isMobile =
a.href = blobUrl; /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
a.download = filename || pdfResource.split("/").pop() || "download.pdf"; navigator.userAgent
);
// if (isMobile) {
document.body.appendChild(a); // 使fetchblob
a.click(); fetch(url)
document.body.removeChild(a); .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); setTimeout(() => {
} catch (error) { document.body.removeChild(link);
console.error("下载PDF文件失败:", error); 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> </script>