Files
prop-ai-hr/mobile-uni/src/services/personal-assistant-ocr.ts
T

21 lines
1.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { PersonalOcrProgress } from '@/types/api';
export const ocrProgressPercent = (ocr?: PersonalOcrProgress) => {
if (!ocr?.required || ocr.totalPages <= 0) return 0;
return Math.min(100, Math.max(0, Math.round((ocr.processedPages / ocr.totalPages) * 100)));
};
export const ocrProgressText = (ocr?: PersonalOcrProgress) => {
if (!ocr?.required) return '';
if (ocr.processedPages < ocr.totalPages && ['PENDING', 'RUNNING', 'RETRY'].includes(ocr.status)) {
return `正在识别扫描 PDF:${ocr.processedPages}/${ocr.totalPages} 页`;
}
if (ocr.failedPages > 0 && ocr.successPages > 0) return `已收录,${ocr.failedPages} 页识别失败`;
if (ocr.failedPages > 0) return `${ocr.failedPages} 页识别失败`;
if (ocr.totalPages > 0) return `扫描 PDF 已识别:${ocr.successPages}/${ocr.totalPages} 页`;
return '正在准备扫描 PDF 识别';
};
export const isOcrActive = (ocr?: PersonalOcrProgress) =>
Boolean(ocr?.required && ['PENDING', 'RUNNING', 'RETRY'].includes(ocr.status));