修复打印和exam_id问题
This commit is contained in:
@@ -67,6 +67,7 @@ export interface PackagItemInfo {
|
||||
package_code: string;
|
||||
package_name: string;
|
||||
registration_time: string;
|
||||
physical_exam_id: number;
|
||||
}
|
||||
|
||||
// 套餐详情
|
||||
|
||||
@@ -34,6 +34,7 @@ const UI6: React.FC = () => {
|
||||
const res = await getPackagItemDetail(id_no as string);
|
||||
if (res.Status === 200) {
|
||||
localStorage.setItem("package_code", res.Data.packagItemInfo.package_code || "");
|
||||
localStorage.setItem("selectedExamId", res.Data.packagItemInfo.physical_exam_id.toString() || "0");
|
||||
// 处理数据:将 project_id 和 project_name 字符串分离为数组
|
||||
const processedData = res.Data.listPackDetail.map((item: any) => {
|
||||
// 将 project_id 字符串按中文顿号分割为数组
|
||||
|
||||
@@ -291,49 +291,73 @@ const UI8: React.FC = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
const primaryPdf = pdfFiles[0] || originPdfUrls[0];
|
||||
if (!primaryPdf) {
|
||||
if (printers.length > 0 && !selectedPrinter) {
|
||||
alert("请先选择打印机");
|
||||
return;
|
||||
}
|
||||
|
||||
if (pdfFiles.length === 0 && originPdfUrls.length === 0) {
|
||||
const errorMsg = "PDF 尚未加载完成,请稍候";
|
||||
window.electronAPI?.log("warn", errorMsg);
|
||||
alert(errorMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
if (printers.length > 0 && !selectedPrinter) {
|
||||
alert("请先选择打印机");
|
||||
return;
|
||||
}
|
||||
|
||||
setIsPrinting(true);
|
||||
try {
|
||||
const printData =
|
||||
primaryPdf.startsWith("data:") && pdfFiles[0]
|
||||
? primaryPdf
|
||||
: originPdfUrls[0];
|
||||
const dataType = printData.startsWith("data:") ? "base64数据" : "远程文件路径";
|
||||
window.electronAPI.log("info", `开始打印PDF (${dataType}): ${printData.substring(0, 100)}...`);
|
||||
// 优先使用已加载的 base64 数据,确保数据完整
|
||||
let printData: string;
|
||||
let dataType: string;
|
||||
|
||||
if (pdfFiles[0] && pdfFiles[0].startsWith("data:application/pdf;base64,")) {
|
||||
printData = pdfFiles[0];
|
||||
dataType = "base64数据";
|
||||
|
||||
// 验证 base64 数据长度(至少应该有几KB)
|
||||
const base64Part = printData.replace("data:application/pdf;base64,", "");
|
||||
const estimatedSize = (base64Part.length * 3) / 4;
|
||||
window.electronAPI.log("info", `使用base64数据打印,估算大小: ${Math.round(estimatedSize)} bytes`);
|
||||
|
||||
if (estimatedSize < 1024) {
|
||||
window.electronAPI.log("warn", "base64数据可能不完整,尝试使用原始URL");
|
||||
// 如果base64数据太小,回退到URL
|
||||
if (originPdfUrls[0]) {
|
||||
printData = originPdfUrls[0];
|
||||
dataType = "远程文件路径";
|
||||
}
|
||||
}
|
||||
} else if (originPdfUrls[0]) {
|
||||
printData = originPdfUrls[0];
|
||||
dataType = "远程文件路径";
|
||||
} else {
|
||||
throw new Error("没有可用的PDF数据");
|
||||
}
|
||||
|
||||
window.electronAPI.log("info", `开始打印PDF (${dataType}): ${dataType === "base64数据" ? `base64长度${printData.length}` : printData.substring(0, 100)}...`);
|
||||
|
||||
const printResult = await window.electronAPI.printPdf(
|
||||
printData,
|
||||
selectedPrinter ? { printerName: selectedPrinter } : undefined
|
||||
);
|
||||
|
||||
if (!printResult.success) {
|
||||
const errorMsg = `打印失败: ${printResult.error || "未知错误"}`;
|
||||
window.electronAPI.log("error", errorMsg);
|
||||
alert(errorMsg);
|
||||
} else {
|
||||
window.electronAPI.log("info", "PDF打印请求已发送");
|
||||
return;
|
||||
}
|
||||
|
||||
window.electronAPI.log("info", "PDF打印请求已发送成功");
|
||||
navigate("/UI81");
|
||||
} catch (error) {
|
||||
const errorMsg = `Print error: ${error}`;
|
||||
const errorMsg = `打印错误: ${(error as Error).message || error}`;
|
||||
console.error(errorMsg);
|
||||
window.electronAPI.log("error", errorMsg);
|
||||
alert("打印失败,请重试");
|
||||
} finally {
|
||||
setIsPrinting(false);
|
||||
navigate("/UI81");
|
||||
}
|
||||
}, [originPdfUrls, pdfFiles, printers.length, selectedPrinter]);
|
||||
}, [originPdfUrls, pdfFiles, printers.length, selectedPrinter, navigate]);
|
||||
|
||||
const handlePageCountUpdate = useCallback((index: number, numPages: number) => {
|
||||
window.electronAPI?.log("info", `[UI8] PDF渲染成功 (index=${index}),共 ${numPages} 页`);
|
||||
|
||||
Reference in New Issue
Block a user