R73-A3 优化轻交互 OCR 前端处理

这个提交包含在:
2026-04-28 21:14:00 +08:00
父节点 b7c018922c
当前提交 03f384fdfe
共修改 8 个文件,包含 227 行新增和 12 行删除
+48
查看文件
@@ -0,0 +1,48 @@
const OCR_FIELD_LABELS: Record<string, string> = {
invoiceCode: "发票代码",
invoiceNumber: "发票号码",
invoiceDate: "开票日期",
totalAmount: "总金额",
sellerName: "销售方",
};
export function parseMissingInvoiceOcrFields(rawError: string | null | undefined) {
if (typeof rawError !== "string") {
return [];
}
const matched = rawError.match(/^missing_required_fields:(.+)$/);
if (!matched?.[1]) {
return [];
}
return matched[1]
.split(",")
.map((field) => field.trim())
.filter(Boolean);
}
export function formatInvoiceOcrFieldLabels(fields: string[]) {
return fields.map((field) => OCR_FIELD_LABELS[field] ?? field);
}
export function formatInvoiceOcrErrorMessage(rawError: string | null | undefined) {
const missingFields = parseMissingInvoiceOcrFields(rawError);
if (missingFields.length) {
return `OCR 缺少关键字段:${formatInvoiceOcrFieldLabels(missingFields).join("、")}。`;
}
if (rawError === "duplicate_invoice_code_number") {
return "OCR 识别到的发票代码/号码与已使用票据重复,请核对后再处理。";
}
if (rawError === "mock_ocr_failed") {
return "OCR 识别失败,请重试或人工补齐关键信息。";
}
if (!rawError) {
return "OCR 识别失败,请稍后重试。";
}
return rawError;
}
+7
查看文件
@@ -41,6 +41,13 @@ export const TEST_IDS = {
erpExport: "reimbursement-erp-export",
overview: "reimbursement-overview",
workflowProgress: "reimbursement-workflow-progress",
invoices: "reimbursement-invoices",
invoiceAdd: "reimbursement-invoice-add",
invoiceDialog: "reimbursement-invoice-dialog",
invoiceUploadFile: "reimbursement-invoice-upload-file",
invoiceUploadSubmit: "reimbursement-invoice-upload-submit",
invoicePendingHint: "reimbursement-invoice-pending-hint",
invoiceActionError: "reimbursement-invoice-action-error",
},
weeklyReport: {
save: "weekly-report-save",