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