完善导检单显示
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user