x
This commit is contained in:
+21
-6
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user