R73-A3 优化轻交互 OCR 前端处理
这个提交包含在:
@@ -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;
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户