diff --git a/src/components/exam/ExamModal.tsx b/src/components/exam/ExamModal.tsx
index c237ed3..ba70ed6 100644
--- a/src/components/exam/ExamModal.tsx
+++ b/src/components/exam/ExamModal.tsx
@@ -6,6 +6,7 @@ import { getCustomerDetail, getPhysicalExamProgressDetail, getTongyishuPdf, sign
import { Button, Input, SignaturePad, type SignaturePadHandle } from '../ui';
import { ExamDetailPanel } from './ExamDetailPanel';
import { ExamAddonPanel } from './ExamAddonPanel';
+import { ExamPrintPanel } from './ExamPrintPanel';
interface ExamModalProps {
client: ExamClient;
@@ -164,7 +165,7 @@ export const ExamModal = ({ client, tab, onTabChange, onClose }: ExamModalProps)
{tab === 'sign' && }
{tab === 'addon' && }
{tab === 'print' && }
- {tab === 'delivery' && }
+ {/* {tab === 'delivery' && } */}
@@ -559,201 +560,4 @@ const ExamSignPanel = ({ examId }: { examId?: number }) => {
);
};
-const ExamDeliveryPanel = ({ client }: { client: ExamClient }) => (
-
-
-
报告寄送
-
-
-
-
- 当前客户:{client.name}(体检号:{client.id})
-
-
-
-
-
-);
-
-const ExamPrintPanel = ({ client }: { client: ExamClient }) => {
- const [pdfUrl, setPdfUrl] = useState(null);
- const [loading, setLoading] = useState(true);
- const [error, setError] = useState(null);
- const [pdfReady, setPdfReady] = useState(false);
- const [pdfBlobUrl, setPdfBlobUrl] = useState(null);
- const printRef = useRef(null);
- const iframeRef = useRef(null);
-
- // 获取 PDF
- useEffect(() => {
- const physical_exam_id = Number(client.id);
- if (!physical_exam_id) {
- setError('无效的体检ID');
- setLoading(false);
- return;
- }
-
- setPdfReady(false);
- getTongyishuPdf({ exam_id: physical_exam_id })
- .then((res) => {
- if (res.Status === 200 && res.Data?.list_pdf_url && res.Data.list_pdf_url.length > 0) {
- // 取第一个PDF URL
- setPdfUrl(res.Data.list_pdf_url[0].pdf_url);
- setPdfReady(false);
- } else {
- setError(res.Message || '未获取到PDF文件');
- }
- })
- .catch((err) => {
- console.error('获取PDF失败', err);
- setError('获取PDF失败,请稍后重试');
- })
- .finally(() => {
- setLoading(false);
- });
- }, [client.id]);
-
- // 将 PDF 拉取为同源 blob,避免跨域打印限制
- useEffect(() => {
- if (!pdfUrl) return;
-
- let objectUrl: string | null = null;
- setPdfReady(false);
- setLoading(true);
-
- fetch(pdfUrl)
- .then((resp) => {
- if (!resp.ok) throw new Error('获取PDF文件失败');
- return resp.blob();
- })
- .then((blob) => {
- objectUrl = URL.createObjectURL(blob);
- setPdfBlobUrl(objectUrl);
- })
- .catch((err) => {
- console.error('PDF 拉取失败', err);
- setError('PDF 加载失败,请稍后重试');
- })
- .finally(() => {
- setLoading(false);
- });
-
- return () => {
- if (objectUrl) {
- URL.revokeObjectURL(objectUrl);
- }
- };
- }, [pdfUrl]);
-
- const handlePrint = () => {
- if (!pdfBlobUrl || !pdfReady) return;
-
- // 打开新窗口打印(同源 blob),避免跨域和空白页问题
- const printWindow = window.open(pdfBlobUrl, '_blank');
- if (printWindow) {
- printWindow.onload = () => {
- printWindow.focus();
- printWindow.print();
- };
- }
- };
-
- return (
-
-
-
-
-
圆和医疗体检中心 · 导检单预览
-
此为预览页面,实际打印效果以院内打印机为准。
-
-
-
-
体检号:{client.id}
-
日期:{new Date().toLocaleDateString('zh-CN')}
-
-
-
-
-
- {loading ? (
-
- ) : error ? (
-
-
{error}
-
-
- ) : pdfUrl ? (
-
- ) : null}
-
-
- );
-};
-
diff --git a/src/components/exam/ExamPrintPanel.tsx b/src/components/exam/ExamPrintPanel.tsx
new file mode 100644
index 0000000..3ee1ed0
--- /dev/null
+++ b/src/components/exam/ExamPrintPanel.tsx
@@ -0,0 +1,163 @@
+import { useEffect, useRef, useState } from 'react';
+
+import { getTongyishuPdf } from '../../api';
+import type { ExamClient } from '../../data/mockData';
+import { Button } from '../ui';
+
+export const ExamPrintPanel = ({ client }: { client: ExamClient }) => {
+ const [pdfUrl, setPdfUrl] = useState(null);
+ const [loading, setLoading] = useState(true);
+ const [error, setError] = useState(null);
+ const [pdfReady, setPdfReady] = useState(false);
+ const [pdfBlobUrl, setPdfBlobUrl] = useState(null);
+ const printRef = useRef(null);
+ const iframeRef = useRef(null);
+
+ useEffect(() => {
+ const physical_exam_id = Number(client.id);
+ if (!physical_exam_id) {
+ setError('无效的体检ID');
+ setLoading(false);
+ return;
+ }
+
+ setPdfReady(false);
+ getTongyishuPdf({ exam_id: physical_exam_id })
+ .then((res) => {
+ if (res.Status === 200 && res.Data?.list_pdf_url && res.Data.list_pdf_url.length > 0) {
+ setPdfUrl(res.Data.list_pdf_url[0].pdf_url);
+ setPdfReady(false);
+ } else {
+ setError(res.Message || '未获取到PDF文件');
+ }
+ })
+ .catch((err) => {
+ console.error('获取PDF失败', err);
+ setError('获取PDF失败,请稍后重试');
+ })
+ .finally(() => {
+ setLoading(false);
+ });
+ }, [client.id]);
+
+ useEffect(() => {
+ if (!pdfUrl) return;
+
+ let objectUrl: string | null = null;
+ setPdfReady(false);
+ setLoading(true);
+
+ fetch(pdfUrl)
+ .then((resp) => {
+ if (!resp.ok) throw new Error('获取PDF文件失败');
+ return resp.blob();
+ })
+ .then((blob) => {
+ objectUrl = URL.createObjectURL(blob);
+ setPdfBlobUrl(objectUrl);
+ })
+ .catch((err) => {
+ console.error('PDF 拉取失败', err);
+ setError('PDF 加载失败,请稍后重试');
+ })
+ .finally(() => {
+ setLoading(false);
+ });
+
+ return () => {
+ if (objectUrl) {
+ URL.revokeObjectURL(objectUrl);
+ }
+ };
+ }, [pdfUrl]);
+
+ const handlePrint = () => {
+ if (!pdfBlobUrl || !pdfReady) return;
+ const printWindow = window.open(pdfBlobUrl, '_blank');
+ if (printWindow) {
+ printWindow.onload = () => {
+ printWindow.focus();
+ printWindow.print();
+ };
+ }
+ };
+
+ return (
+
+
+
+
+
圆和医疗体检中心 · 导检单预览
+
此为预览页面,实际打印效果以院内打印机为准。
+
+
+
+
体检号:{client.id}
+
日期:{new Date().toLocaleDateString('zh-CN')}
+
+
+
+
+
+ {loading ? (
+
+ ) : error ? (
+
+
{error}
+
+
+ ) : pdfUrl ? (
+
+ ) : null}
+
+
+ );
+};
+
+