完善导检单显示

This commit is contained in:
xianyi
2026-01-08 16:53:42 +08:00
parent 9309037f19
commit 2dbba9e708
2 changed files with 78 additions and 8 deletions

View File

@@ -87,10 +87,36 @@ export const ExamPrintPanel = ({ client }: { client: ExamClient }) => {
}
};
// 组件加载时检查localStorage如果有则直接展示
// 组件加载时自动获取导检单(未签名版本也可以查看)
useEffect(() => {
const examId = Number(client.id);
if (!examId) return;
// 自动加载未签名的导检单用于查看
const fetchPdf = async () => {
setFetchLoading(true);
setError(null);
try {
const res = await getDaojiandanPdfApi({ exam_id: examId });
if (res.Status === 200 && res.Data?.pdf_url) {
const pdfUrlValue = res.Data.pdf_url;
console.log('获取到导检单PDF URL:', pdfUrlValue);
setPdfUrl(pdfUrlValue);
setShowPreview(true);
} else {
console.error('获取导检单失败,响应:', res);
setError(res.Message || '获取导检单失败');
}
} catch (err) {
console.error('获取导检单失败', err);
setError('获取导检单失败,请稍后重试');
} finally {
setFetchLoading(false);
}
};
fetchPdf();
}, [client.id]);
// 获取导检单PDF优先使用localStorage没有则调用接口
@@ -389,10 +415,6 @@ export const ExamPrintPanel = ({ client }: { client: ExamClient }) => {
<div className='flex items-center justify-center py-12 text-gray-500'>
<div>...</div>
</div>
) : loading ? (
<div className='flex items-center justify-center py-12 text-gray-500'>
<div>PDF...</div>
</div>
) : error ? (
<div className='flex flex-col items-center justify-center py-12 text-gray-500'>
<div className='mb-2'>{error}</div>
@@ -421,6 +443,10 @@ export const ExamPrintPanel = ({ client }: { client: ExamClient }) => {
</Button>
)}
</div>
) : loading ? (
<div className='flex items-center justify-center py-12 text-gray-500'>
<div>PDF...</div>
</div>
) : pdfUrl ? (
<div className='w-full'>
<div ref={printRef} className='print-content'>
@@ -429,6 +455,10 @@ export const ExamPrintPanel = ({ client }: { client: ExamClient }) => {
</div>
</div>
</div>
) : showPreview ? (
<div className='flex items-center justify-center py-12 text-gray-500'>
<div>...</div>
</div>
) : null}
</div>
</div>