refactor(annotation): 简化注释数据导出下载逻辑

- 移除前端手动创建 a 标签下载文件的方式
- 将文件名参数传递给后端 API 函数
- 利用 download 函数内置的下载处理机制
- 简化 ExportAnnotationDialog 组件中的导出流程
- 更新 annotation.api.ts 中的 downloadAnnotationsUsingGet 函数签名
- 直接通过 API 调用完成文件下载和命名
This commit is contained in:
2026-01-30 17:33:14 +08:00
parent 6dfed934a5
commit a4cdaecf8a
2 changed files with 11 additions and 18 deletions

View File

@@ -106,13 +106,6 @@ export default function ExportAnnotationDialog({
const values = await form.validateFields();
setExporting(true);
const blob = await downloadAnnotationsUsingGet(
projectId,
values.format,
values.onlyAnnotated,
values.includeData
);
// 获取文件名
const formatExt: Record<ExportFormat, string> = {
json: "json",
@@ -124,15 +117,14 @@ export default function ExportAnnotationDialog({
const ext = formatExt[values.format as ExportFormat] || "json";
const filename = `${projectName}_annotations.${ext}`;
// 下载文件
const url = window.URL.createObjectURL(blob as Blob);
const a = document.createElement("a");
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
// 下载文件(download函数内部已处理下载逻辑)
await downloadAnnotationsUsingGet(
projectId,
values.format,
values.onlyAnnotated,
values.includeData,
filename
);
message.success("导出成功");
onClose();

View File

@@ -109,12 +109,13 @@ export function downloadAnnotationsUsingGet(
projectId: string,
format: ExportFormat = "json",
onlyAnnotated: boolean = true,
includeData: boolean = false
includeData: boolean = false,
filename?: string
) {
const params = new URLSearchParams({
format,
only_annotated: String(onlyAnnotated),
include_data: String(includeData),
});
return download(`/api/annotation/export/projects/${projectId}/download?${params.toString()}`);
return download(`/api/annotation/export/projects/${projectId}/download?${params.toString()}`, null, filename);
}