From 79ca3613ae35a62a5099b69b48bfa02b9c096940 Mon Sep 17 00:00:00 2001 From: chenjw28 <792430652@qq.com> Date: Fri, 8 May 2026 16:21:37 +0800 Subject: [PATCH] x --- static/vue-app.js | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/static/vue-app.js b/static/vue-app.js index 5aedf35..8d26aa6 100644 --- a/static/vue-app.js +++ b/static/vue-app.js @@ -1511,12 +1511,7 @@ const ResultView = { if (result.status === 'success' && result.data.files) { for (const file of result.data.files) { const downloadUrl = `/api/export-download/${file.filepath.replace(/\\/g, '/').split('/').slice(-2).join('/')}`; - const link = document.createElement('a'); - link.href = downloadUrl; - link.download = file.filename; - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); + await downloadWithAuth(downloadUrl, file.filename); } addNotification(`已导出 ${result.data.files.length} 个 ${format.toUpperCase()} 文件`, 'success'); } else if (result.data.errors && result.data.errors.length > 0) { @@ -1527,6 +1522,26 @@ const ResultView = { } }; + async function downloadWithAuth(url, filename) { + const headers = {}; + if (appState.token) { + headers['Authorization'] = `Bearer ${appState.token}`; + } + const response = await fetch(url, { headers }); + if (!response.ok) { + throw new Error(`下载失败 (${response.status}): 无法下载,需要授权`); + } + const blob = await response.blob(); + const blobUrl = URL.createObjectURL(blob); + const link = document.createElement('a'); + link.href = blobUrl; + link.download = filename; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + URL.revokeObjectURL(blobUrl); + } + const generateCamPlan = async () => { try { state.camLoading = true;