From 6ef3204589f66daa467a18ee69ffd7b0368c2b71 Mon Sep 17 00:00:00 2001 From: lichuanyang <1176537920@qq.com> Date: Thu, 19 Dec 2024 15:05:58 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=B3=E6=80=A7=E7=BB=9F=E8=AE=A1=E3=80=81?= =?UTF-8?q?=E5=8D=B1=E6=80=A5=E5=80=BC=E9=A1=B5=E9=9D=A2=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=20ecg=E4=BF=9D=E5=AD=98=E7=94=9F=E6=88=90pdf=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/htmlPdf.js | 83 ++++++------- src/views/ECG/ECGForm.vue | 110 +++++++++++------- src/views/ECG/ECGPositiveStatistics/index.vue | 41 +------ .../ECG/warningStatisticsReport/index.vue | 33 +++++- .../reportPrintStatistics/ReportInfoECG.vue | 40 +++++-- 5 files changed, 171 insertions(+), 136 deletions(-) diff --git a/src/utils/htmlPdf.js b/src/utils/htmlPdf.js index 65f2567f..6bcd1c3b 100644 --- a/src/utils/htmlPdf.js +++ b/src/utils/htmlPdf.js @@ -147,8 +147,10 @@ const htmlToPdf = { // 使用html2canvas捕捉div内容 html2Canvas(divElement, { + width: divElement.offsetWidth + 4, + height: divElement.offsetHeight + 6, dpi: 300, // 设置300DPI - scale: 3.125, // 保持原始比例 + scale: 2.4, // 保持原始比例 useCORS: true, // 如果内容包含跨域图片,需要设置为true allowTaint: false // 是否允许跨域图片导致画布被污染 }) @@ -162,10 +164,10 @@ const htmlToPdf = { orientation: 'l', unit: 'px', format: [canvas.width, canvas.height] - }); + }) // 将canvas转换为图片数据URL - const imgData = canvas.toDataURL('image/jpeg', 1) // 1.0表示最高质量 - // pdf.addImage(imgData, 'JPEG', 0, 0, canvas.width, canvas.height); + const imgData = canvas.toDataURL('image/jpeg', 1) // 1.0表示最高质量 + // pdf.addImage(imgData, 'JPEG', 0, 0, canvas.width, canvas.height); // // 设置 PDF 页面尺寸 // // pdf.addImage(imgData, 'JPEG', 10, 10, 1920, 820) // const link = document.createElement('a'); @@ -174,7 +176,7 @@ const htmlToPdf = { // link.click(); // pdf.save('111.pdf') // 解决Promise并返回图片的base64字符串 - // pdf.save(`${divId}-content.pdf`); + // pdf.save(`${divId}-content.pdf`); resolve(imgData) }) .catch((error) => { @@ -185,52 +187,51 @@ const htmlToPdf = { }, createPdfFromBase64(base64Image) { return new Promise((resolve, reject) => { - // 使用html2canvas捕捉div内容(这里不需要,但保留以备后续使用) - // html2Canvas(divElement, { ... }).then(canvas => { - // 将base64字符串转换为Blob对象 - const blob = base64ToBlob(base64Image); + // 使用html2canvas捕捉div内容(这里不需要,但保留以备后续使用) + // html2Canvas(divElement, { ... }).then(canvas => { + // 将base64字符串转换为Blob对象 + const blob = base64ToBlob(base64Image) - // 创建一个URL对象 - const url = URL.createObjectURL(blob); + // 创建一个URL对象 + const url = URL.createObjectURL(blob) - // 创建一个新的Image对象 - const img = new Image(); - img.onload = () => { - // 创建PDF对象 - const pdf = new jsPDF({ - orientation: 'l', - unit: 'px', - format: [img.width, img.height] - }); + // 创建一个新的Image对象 + const img = new Image() + img.onload = () => { + // 创建PDF对象 + const pdf = new jsPDF({ + orientation: 'l', + unit: 'px', + format: [img.width, img.height] + }) - // 将图片添加到PDF - pdf.addImage(img, 'JPEG', 0, 0, img.width, img.height); + // 将图片添加到PDF + pdf.addImage(img, 'JPEG', 0, 0, img.width, img.height) - // 获取PDF的base64字符串 - const pdfBase64 = pdf.output('datauristring'); + // 获取PDF的base64字符串 + const pdfBase64 = pdf.output('datauristring') - // 解决Promise并返回PDF的base64字符串 - resolve(pdfBase64); - - // 清理URL对象 - URL.revokeObjectURL(url); - }; - img.onerror = (error) => { - console.error('图片加载失败:', error); - reject(error); - }; - img.src = url; - }); -} + // 解决Promise并返回PDF的base64字符串 + resolve(pdfBase64) + // 清理URL对象 + URL.revokeObjectURL(url) + } + img.onerror = (error) => { + console.error('图片加载失败:', error) + reject(error) + } + img.src = url + }) + } } // 辅助函数:将base64字符串转换为Blob对象 function base64ToBlob(base64) { - const binary = atob(base64.split(',')[1]); - const array = []; + const binary = atob(base64.split(',')[1]) + const array = [] for (let i = 0; i < binary.length; i++) { - array.push(binary.charCodeAt(i)); + array.push(binary.charCodeAt(i)) } - return new Blob([new Uint8Array(array)], { type: 'image/jpeg' }); + return new Blob([new Uint8Array(array)], { type: 'image/jpeg' }) } export default htmlToPdf diff --git a/src/views/ECG/ECGForm.vue b/src/views/ECG/ECGForm.vue index 1d0cb36f..dd6e1d63 100644 --- a/src/views/ECG/ECGForm.vue +++ b/src/views/ECG/ECGForm.vue @@ -532,22 +532,25 @@
- + +
+ +
@@ -627,7 +630,7 @@ const open = async (row: any) => { orgid.value = row.orgId rowinfo.value = row // console.log( rowinfo.value) - const data = await EcganalysisparasApi.getexamIDdata('MZCF0191729074962197_44',orgid.value) + const data = await EcganalysisparasApi.getexamIDdata('MZCF0191729074962197_44', orgid.value) queryParams.value = data snapshotTime.value = formattedDate(queryParams.value.snapshotTime) await getlogininfo() @@ -718,42 +721,51 @@ async function save() { const ret = await EcganalysisparasApi.SaveEcganalysisparas(saveFormVO.value) if (ret) { //进行生成pdf - const data = await EcganalysisparasApi.getexamIDdata('MZCF0191729074962197_44',orgid.value) + const data = await EcganalysisparasApi.getexamIDdata('MZCF0191729074962197_44', orgid.value) queryParams.value = data message.alertSuccess('保存成功') - isprintimage.value = true - nextTick(async () => { - setTimeout(async () => { - try { - //生成PDF - htmlToPdf - .createPdfFromBase64(imagebase64.value) - .then((pdfBase64) => { - //生成PDF - PatientexamlistApi.ftppdf({ - id: Primarykey.value, - imagebase: pdfBase64, - model: '0', - folderPath: 'C:\\work\\pacs' + '\\' + Primarykey.value - }) - }) - .catch((error) => { - console.log(error) - }) - } finally { - isprintimage.value = false - imagebase64.value = '' - } - }, 1000) - }) + //ElMessage.info('开始保存pdf') + setTimeout(() => { + isprintimage.value = true + }, 900) } } + //展示图片 function updateimagebase(newValue) { imagebase64.value = newValue } +const updateimagebase_new = async () => { + try { + const image_base64 = await htmlToPdf.getDivContentAsBase64('#ecg_pdf') + try { + //生成PDF + htmlToPdf + .createPdfFromBase64(image_base64) + .then((pdfBase64) => { + PatientexamlistApi.ftppdf({ + id: Primarykey.value, + imagebase: pdfBase64, + model: '0', + folderPath: 'C:\\work\\pacs' + '\\' + Primarykey.value + }) + ElMessage.info('pdf保存成功') + }) + .catch((error) => { + console.log(error) + }) + } finally { + } + } catch { + } finally { + nextTick(() => { + isprintimage.value = false + }) + } +} + //重置数据 function resetForm() { Isgrid.value = 1 //是否显示网格 1显示 0不显示 @@ -794,7 +806,7 @@ function openreprotdiag() { } //对比弹窗 function opencomparediag() { - ECGCompare.value.opencomparediag(rowinfo.value,queryParams.value.snapshotTime) + ECGCompare.value.opencomparediag(rowinfo.value, queryParams.value.snapshotTime) } //纠错 function iscorrect() { @@ -996,11 +1008,19 @@ defineExpose({ open }) // 提供 open 方法,用于打开弹窗 .page-item-ecg { padding: 1mm 0.8mm 1mm 0.6mm; max-width: 1184px; - margin: 6vh auto 0 auto; + margin: 3vh auto 0 auto; border: 2px solid #ccc; border-radius: 8px; } +.page-pdf-ecg { + border-width: 0; + padding: 0 0.8mm 0 0.8mm; + width: 294mm; + height: 206mm; + page-break-after: always; +} + @media print { .ignore-print { display: none; diff --git a/src/views/ECG/ECGPositiveStatistics/index.vue b/src/views/ECG/ECGPositiveStatistics/index.vue index 73e93b4b..1f21e906 100644 --- a/src/views/ECG/ECGPositiveStatistics/index.vue +++ b/src/views/ECG/ECGPositiveStatistics/index.vue @@ -130,44 +130,11 @@ /> - - - - +