From b2ebd3e12d9e5dd99cbebce6e911068b62f48764 Mon Sep 17 00:00:00 2001 From: tl <1655185665@qq.com> Date: Wed, 8 Apr 2026 20:45:02 +0800 Subject: [PATCH] tl --- frontend/src/db/backend-api.ts | 35 +++++++++++++++++++++++++++++ frontend/src/pages/TemplateFill.tsx | 1 + 2 files changed, 36 insertions(+) diff --git a/frontend/src/db/backend-api.ts b/frontend/src/db/backend-api.ts index 94ac852..998fe62 100644 --- a/frontend/src/db/backend-api.ts +++ b/frontend/src/db/backend-api.ts @@ -103,7 +103,9 @@ export interface FillResult { field: string; value: any; source: string; + confidence?: number; }>; + source_doc_count?: number; error?: string; } @@ -621,6 +623,39 @@ export const backendApi = { } }, + /** + * 从已上传的模板提取字段定义 + */ + async extractTemplateFields( + templateId: string, + fileType: string = 'xlsx' + ): Promise<{ + success: boolean; + fields: TemplateField[]; + }> { + const url = `${BACKEND_BASE_URL}/templates/fields`; + + try { + const response = await fetch(url, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + template_id: templateId, + file_type: fileType, + }), + }); + + if (!response.ok) { + const error = await response.json(); + throw new Error(error.detail || '提取字段失败'); + } + return await response.json(); + } catch (error) { + console.error('提取字段失败:', error); + throw error; + } + }, + /** * 执行表格填写 */ diff --git a/frontend/src/pages/TemplateFill.tsx b/frontend/src/pages/TemplateFill.tsx index f9a4a39..573d3f7 100644 --- a/frontend/src/pages/TemplateFill.tsx +++ b/frontend/src/pages/TemplateFill.tsx @@ -46,6 +46,7 @@ type TemplateField = { name: string; field_type: string; required: boolean; + hint?: string; }; const TemplateFill: React.FC = () => {