From 119e45ba2b56e94716fcf24aab10972e4da6658b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E5=85=89LG?= Date: Wed, 20 Aug 2025 22:10:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E5=8F=AA=E8=B7=B3=E8=BD=AC=E4=B8=8D=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/paper/question/CdesignForm.vue | 40 ++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/views/paper/question/CdesignForm.vue b/src/views/paper/question/CdesignForm.vue index 87be48c..e80c641 100644 --- a/src/views/paper/question/CdesignForm.vue +++ b/src/views/paper/question/CdesignForm.vue @@ -729,9 +729,45 @@ const downloadFile = async (url: string) => { return } try { - window.open(url, '_blank') + // 获取文件信息 + const fileItem = formData.value.fileUploads.find((i) => i.url === url) + const fileName = fileItem?.fileName || '下载文件' + + // 使用 fetch 获取文件 + const response = await fetch(url) + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`) + } + + // 获取文件内容 + const blob = await response.blob() + + // 创建对象URL + const objectUrl = URL.createObjectURL(blob) + + // 创建下载链接 + const link = document.createElement('a') + link.href = objectUrl + link.download = fileName + link.style.display = 'none' + + // 触发下载 + document.body.appendChild(link) + link.click() + + // 清理 + document.body.removeChild(link) + URL.revokeObjectURL(objectUrl) + + message.success('文件下载成功') } catch (err: any) { - message.error(`下载失败:${err.message}`) + console.error('Download error:', err) + // 如果 fetch 下载失败,回退到直接打开链接 + try { + window.open(url, '_blank') + } catch (openError) { + message.error(`下载失败:${err.message}`) + } } }