fix quarterlyresults

This commit is contained in:
张 元山 2025-05-26 14:11:56 +08:00
parent e052d59c2b
commit ce58c9886e
4 changed files with 110 additions and 120 deletions

View File

@ -25,13 +25,17 @@
class="result-item"
>
<div class="content">
<a :href="item.url" class="result-title subtitle">{{ item.title }}</a>
<p class="result-title subtitle">{{ item.title }}</p>
<p class="result-description content-text">{{ item.description }}</p>
</div>
<div class="pdf-icon">
<a :href="item.url" target="_blank">
<img src="@/assets/image/pdf.png" alt="PDF" />
</a>
<div
class="pdf-icon"
@click="downloadPdf(item.url)"
style="color: #2979ff; cursor: pointer"
>
<img src="@/assets/image/pdf.png" alt="PDF" />
{{ t("financialinformation.quarterlyresults.download") }}
</div>
</div>
</div>
@ -341,6 +345,31 @@ const handleSearch = () => {
//
console.log("搜索:", searchQuery.value);
};
const downloadPdf = async (pdfResource, filename = "") => {
try {
// PDF
const response = await fetch(pdfResource);
const blob = await response.blob();
// Blob URL
const blobUrl = URL.createObjectURL(blob);
//
const a = document.createElement("a");
a.href = blobUrl;
a.download = filename || pdfResource.split("/").pop() || "download.pdf";
//
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
// Blob URL
URL.revokeObjectURL(blobUrl);
} catch (error) {
console.error("下载PDF文件失败:", error);
}
};
</script>
<style scoped lang="scss">
.title {
@ -387,7 +416,7 @@ const handleSearch = () => {
.result-item {
display: flex;
justify-content: space-between;
align-items: flex-start;
align-items: center;
padding: 15px 0;
border-bottom: 1px solid #eee;
}
@ -401,10 +430,6 @@ const handleSearch = () => {
text-decoration: none;
display: block;
margin-bottom: 5px;
&:hover {
text-decoration: underline;
}
}
.result-description {

View File

@ -25,13 +25,16 @@
class="result-item"
>
<div class="content">
<a :href="item.url" class="result-title subtitle">{{ item.title }}</a>
<p class="result-title subtitle">{{ item.title }}</p>
<p class="result-description content-text">{{ item.description }}</p>
</div>
<div class="pdf-icon">
<a :href="item.url" target="_blank">
<img src="@/assets/image/pdf.png" alt="PDF" />
</a>
<div
class="pdf-icon"
@click="downloadPdf(item.url)"
style="color: #2979ff; cursor: pointer"
>
<img src="@/assets/image/pdf.png" alt="PDF" />
{{ t("financialinformation.quarterlyresults.download") }}
</div>
</div>
</div>
@ -341,6 +344,32 @@ const handleSearch = () => {
//
console.log("搜索:", searchQuery.value);
};
const downloadPdf = async (pdfResource, filename = "") => {
try {
// PDF
const response = await fetch(pdfResource);
const blob = await response.blob();
// Blob URL
const blobUrl = URL.createObjectURL(blob);
//
const a = document.createElement("a");
a.href = blobUrl;
a.download = filename || pdfResource.split("/").pop() || "download.pdf";
//
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
// Blob URL
URL.revokeObjectURL(blobUrl);
} catch (error) {
console.error("下载PDF文件失败:", error);
}
};
</script>
<style scoped lang="scss">
.title {
@ -387,7 +416,7 @@ const handleSearch = () => {
.result-item {
display: flex;
justify-content: space-between;
align-items: flex-start;
align-items: center;
padding: 15px 0;
border-bottom: 1px solid #eee;
}
@ -401,10 +430,6 @@ const handleSearch = () => {
text-decoration: none;
display: block;
margin-bottom: 5px;
&:hover {
text-decoration: underline;
}
}
.result-description {

View File

@ -36,7 +36,7 @@
<img
src="@/assets/image/download.svg"
style="width: 20px; height: 20px"
@click="handleDownload(item.url)"
@click="downloadPdf(item.url)"
/>
</div>
</div>
@ -345,55 +345,29 @@ const handleSearch = () => {
console.log("搜索:", searchQuery.value);
};
const handleDownload = (url) => {
//
console.log("下载:", url);
const downloadPdf = async (pdfResource, filename = "") => {
try {
// PDF
const response = await fetch(pdfResource);
const blob = await response.blob();
// 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();
//
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);
// Blob URL
URL.revokeObjectURL(blobUrl);
} catch (error) {
console.error("下载PDF文件失败:", error);
}
};
</script>
@ -475,10 +449,6 @@ const handleDownload = (url) => {
margin-bottom: 8px;
font-size: 92px;
font-weight: 600;
&:hover {
text-decoration: underline;
}
}
.result-description {

View File

@ -36,7 +36,7 @@
<img
src="@/assets/image/download.svg"
style="width: 20px; height: 20px"
@click="handleDownload(item.url)"
@click="downloadPdf(item.url)"
/>
</div>
</div>
@ -345,55 +345,29 @@ const handleSearch = () => {
console.log("搜索:", searchQuery.value);
};
const handleDownload = (url) => {
//
console.log("下载:", url);
const downloadPdf = async (pdfResource, filename = "") => {
try {
// PDF
const response = await fetch(pdfResource);
const blob = await response.blob();
// 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();
//
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);
// Blob URL
URL.revokeObjectURL(blobUrl);
} catch (error) {
console.error("下载PDF文件失败:", error);
}
};
</script>
@ -475,10 +449,6 @@ const handleDownload = (url) => {
margin-bottom: 8px;
font-size: 50px;
font-weight: 600;
&:hover {
text-decoration: underline;
}
}
.result-description {