diff --git a/src/views/financialinformation/quarterlyresults/size375/index.vue b/src/views/financialinformation/quarterlyresults/size375/index.vue index dde03f0..cf06fa6 100644 --- a/src/views/financialinformation/quarterlyresults/size375/index.vue +++ b/src/views/financialinformation/quarterlyresults/size375/index.vue @@ -357,7 +357,6 @@ const downloadPdf = (url) => { fileName = fileName.split(/[?_]/)[0]; } link.download = fileName; - link.target = "_blank"; // 对于移动设备,我们需要特殊处理 const isMobile = @@ -366,12 +365,15 @@ const downloadPdf = (url) => { ); if (isMobile) { - // 在移动设备上,可能需要使用fetch下载文件并创建blob + // 在移动设备上,使用fetch下载文件并直接触发下载,不使用blob URL进行预览 fetch(url) .then((response) => response.blob()) .then((blob) => { const objectUrl = URL.createObjectURL(blob); link.href = objectUrl; + // 确保设置download属性并且不设置target="_blank"以避免预览 + link.download = fileName; + link.target = "_self"; // 避免在新窗口打开 document.body.appendChild(link); link.click(); @@ -383,11 +385,16 @@ const downloadPdf = (url) => { }) .catch((error) => { console.error("下载文件时出错:", error); - // 如果fetch失败,回退到window.open - window.open(url, "_blank"); + // 如果fetch失败,尝试直接下载 + link.href = url; + link.download = fileName; + link.target = "_self"; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); }); } else { - // 桌面设备上直接点击链接 + // 桌面设备上直接点击链接下载 document.body.appendChild(link); link.click(); document.body.removeChild(link); diff --git a/src/views/financialinformation/quarterlyresults/size768/index.vue b/src/views/financialinformation/quarterlyresults/size768/index.vue index 8a512fa..7e84601 100644 --- a/src/views/financialinformation/quarterlyresults/size768/index.vue +++ b/src/views/financialinformation/quarterlyresults/size768/index.vue @@ -357,7 +357,6 @@ const downloadPdf = (url) => { fileName = fileName.split(/[?_]/)[0]; } link.download = fileName; - link.target = "_blank"; // 对于移动设备,我们需要特殊处理 const isMobile = @@ -366,12 +365,15 @@ const downloadPdf = (url) => { ); if (isMobile) { - // 在移动设备上,可能需要使用fetch下载文件并创建blob + // 在移动设备上,使用fetch下载文件并直接触发下载,不使用blob URL进行预览 fetch(url) .then((response) => response.blob()) .then((blob) => { const objectUrl = URL.createObjectURL(blob); link.href = objectUrl; + // 确保设置download属性并且不设置target="_blank"以避免预览 + link.download = fileName; + link.target = "_self"; // 避免在新窗口打开 document.body.appendChild(link); link.click(); @@ -383,11 +385,16 @@ const downloadPdf = (url) => { }) .catch((error) => { console.error("下载文件时出错:", error); - // 如果fetch失败,回退到window.open - window.open(url, "_blank"); + // 如果fetch失败,尝试直接下载 + link.href = url; + link.download = fileName; + link.target = "_self"; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); }); } else { - // 桌面设备上直接点击链接 + // 桌面设备上直接点击链接下载 document.body.appendChild(link); link.click(); document.body.removeChild(link);