fix quarterlyresults
This commit is contained in:
parent
b184eba64d
commit
22e9b74173
@ -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) {
|
||||
// 在移动设备上,可能需要使用fetch下载文件并创建blob
|
||||
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>
|
||||
|
@ -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) {
|
||||
// 在移动设备上,可能需要使用fetch下载文件并创建blob
|
||||
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>
|
||||
|
Loading…
Reference in New Issue
Block a user