预览pdf(未完成)
This commit is contained in:
parent
68936a6ab3
commit
0b1af5bc78
@ -141,31 +141,36 @@ async function handleDiagnosticInfo(status) {
|
|||||||
.formreturnCancel {
|
.formreturnCancel {
|
||||||
width: 80px;
|
width: 80px;
|
||||||
height: 40px;
|
height: 40px;
|
||||||
background: #313131;
|
background-color: #597194;
|
||||||
border: 1px solid rgb(148, 148, 148);
|
border: 1px solid #597194;
|
||||||
font-family: 'Noto Sans SC';
|
font-family: 'Noto Sans SC';
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
color: rgb(148, 148, 148);
|
color: rgba(255, 255, 255, 0.6);
|
||||||
}
|
}
|
||||||
|
|
||||||
.formreturnCancel:hover {
|
.formreturnCancel:hover {
|
||||||
background: #1e2c49;
|
background-color: #14aaff;
|
||||||
color: #266fff;
|
color: #fff;
|
||||||
border: 1px solid #266fff;
|
border: 1px solid #14aaff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.formsaveCancel {
|
.formsaveCancel {
|
||||||
width: 80px;
|
width: 80px;
|
||||||
height: 40px;
|
height: 40px;
|
||||||
background: #266fff;
|
background:#0b94d5;
|
||||||
|
border:1px solid #0b94d5;
|
||||||
font-family: 'Noto Sans SC';
|
font-family: 'Noto Sans SC';
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
color: #FFFFFF;
|
color: #FFFFFF;
|
||||||
}
|
}
|
||||||
|
.formsaveCancel:hover{
|
||||||
|
background:#14aaff;
|
||||||
|
border:1px solid #14aaff;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
<style>
|
<style>
|
||||||
.DiagnosticMessage-container .el-form-item__label{
|
.DiagnosticMessage-container .el-form-item__label{
|
||||||
|
|||||||
@ -210,7 +210,7 @@
|
|||||||
:selectedPatient="selectedPatient"
|
:selectedPatient="selectedPatient"
|
||||||
:detectionInfo="detectionInfo"
|
:detectionInfo="detectionInfo"
|
||||||
:selectId="rawData.id"
|
:selectId="rawData.id"
|
||||||
@closePopUpReport="closePopUpReport"
|
@closePopUpOnlyReport="closePopUpOnlyReport"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -344,7 +344,15 @@ function closeSelectData(is,val){
|
|||||||
}
|
}
|
||||||
function closePopUpReport() {
|
function closePopUpReport() {
|
||||||
isPopUpReport.value = false
|
isPopUpReport.value = false
|
||||||
|
emit("closeGenerateReport",true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function closePopUpOnlyReport() {
|
||||||
|
isPopUpOnlyReport.value = false
|
||||||
|
emit("closeGenerateReport",true)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
@ -303,7 +303,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- <ViewPDF /> -->
|
<ViewPDF v-if="isViewPDF" :pdfUrl="pdfUrl" @closeViewPDF="closeViewPDF"/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -341,6 +341,8 @@ const props = defineProps({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
const isTip = ref(false) // 退出提示
|
const isTip = ref(false) // 退出提示
|
||||||
|
const isViewPDF = ref(false) // 是否查看PDF
|
||||||
|
const pdfUrl = ref('') // PDF地址
|
||||||
const tipValue = ref('')
|
const tipValue = ref('')
|
||||||
const delType = ref('')
|
const delType = ref('')
|
||||||
const detectionId = ref('') // 列表检测ID
|
const detectionId = ref('') // 列表检测ID
|
||||||
@ -380,6 +382,9 @@ function getNo(order) {
|
|||||||
return order
|
return order
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function closeViewPDF(){
|
||||||
|
isViewPDF.value = false
|
||||||
|
}
|
||||||
function clickImg(item,index){
|
function clickImg(item,index){
|
||||||
debugger
|
debugger
|
||||||
selectIndex.value = index
|
selectIndex.value = index
|
||||||
@ -562,10 +567,13 @@ function deleteClick(row){
|
|||||||
isTip.value = true
|
isTip.value = true
|
||||||
}
|
}
|
||||||
function fileClick(row){
|
function fileClick(row){
|
||||||
ElMessage.success({
|
pdfUrl.value = BACKEND_URL + '/' + row.detection_report
|
||||||
message: '预览文件',
|
debugger
|
||||||
duration: 3000
|
isViewPDF.value = true
|
||||||
});
|
// ElMessage.success({
|
||||||
|
// message: '预览文件',
|
||||||
|
// duration: 3000
|
||||||
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectedChange(val){
|
function selectedChange(val){
|
||||||
@ -695,7 +703,10 @@ function generateReport(row,index){ // 打开生成报告页面
|
|||||||
detectionId.value = row.id
|
detectionId.value = row.id
|
||||||
isGenerateReport.value = true
|
isGenerateReport.value = true
|
||||||
}
|
}
|
||||||
function closeGenerateReport(){ // 关闭生成报告页面
|
function closeGenerateReport(e){ // 关闭生成报告页面
|
||||||
|
if(e == true){
|
||||||
|
sessionsInit()
|
||||||
|
}
|
||||||
isGenerateReport.value = false
|
isGenerateReport.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="PopUpOnlyReport-container">
|
<div class="PopUpOnlyReport-container" id="popup-report-root">
|
||||||
<div class="PopUpOnlyReport-container-body" id="pdf-content">
|
<div class="PopUpOnlyReport-container-body" id="pdf-content">
|
||||||
<div style="height: 100%; padding:0 90px; box-sizing: border-box;">
|
<div style="height: 100%; padding:0 90px; box-sizing: border-box;">
|
||||||
<div class="PopUpOnlyReport-container-bodytitle">体态测量报告单</div>
|
<div class="PopUpOnlyReport-container-bodytitle">体态测量报告单</div>
|
||||||
@ -131,8 +131,8 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted, onUnmounted } from 'vue'
|
import { ref, onMounted, onUnmounted } from 'vue'
|
||||||
import { getBackendUrl } from '@/services/api.js'
|
import { getBackendUrl } from '@/services/api.js'
|
||||||
import html2canvas from 'html2canvas';
|
// import html2canvas from 'html2canvas';
|
||||||
import jsPDF from 'jspdf';
|
// import jsPDF from 'jspdf';
|
||||||
const emit = defineEmits([ 'closePopUpOnlyReport' ]);
|
const emit = defineEmits([ 'closePopUpOnlyReport' ]);
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
selectedPatient: {
|
selectedPatient: {
|
||||||
@ -187,6 +187,7 @@ onMounted(() => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
generatePDF()
|
generatePDF()
|
||||||
}, 500);
|
}, 500);
|
||||||
@ -206,66 +207,127 @@ function getFormattedTime() {
|
|||||||
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
||||||
}
|
}
|
||||||
const generatePDF = async () => {
|
const generatePDF = async () => {
|
||||||
const element = document.getElementById('pdf-content');
|
try {
|
||||||
|
const root = document.getElementById('popup-report-root')
|
||||||
// PDF尺寸配置
|
if (!root) {
|
||||||
const pdf = new jsPDF('p', 'mm', 'a4');
|
ElMessage.error('报告容器未找到')
|
||||||
const pageWidth = pdf.internal.pageSize.getWidth();
|
return
|
||||||
const pageHeight = pdf.internal.pageSize.getHeight();
|
|
||||||
|
|
||||||
// 计算缩放比例
|
|
||||||
const scale = 2; // 提高清晰度
|
|
||||||
const elementWidth = element.offsetWidth;
|
|
||||||
const elementHeight = element.scrollHeight;
|
|
||||||
const widthRatio = pageWidth / (elementWidth / scale);
|
|
||||||
|
|
||||||
// 智能分页算法
|
|
||||||
const pageContentHeight = (pageHeight / widthRatio) * scale;
|
|
||||||
let position = 0;
|
|
||||||
let currentPage = 1;
|
|
||||||
|
|
||||||
while (position < elementHeight) {
|
|
||||||
// 添加新页面(首页除外)
|
|
||||||
if (currentPage > 1) {
|
|
||||||
pdf.addPage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 分块渲染
|
if (!window.electronAPI) {
|
||||||
const canvas = await html2canvas(element, {
|
console.error('electronAPI 未定义')
|
||||||
scale,
|
return
|
||||||
useCORS: true,
|
|
||||||
windowHeight: pageContentHeight,
|
|
||||||
height: pageContentHeight,
|
|
||||||
y: position,
|
|
||||||
x: 0,
|
|
||||||
scrollY: -window.scrollY // 锁定滚动位置
|
|
||||||
});
|
|
||||||
|
|
||||||
// 计算当前块尺寸
|
|
||||||
const imgData = canvas.toDataURL('image/jpeg', 1.0);
|
|
||||||
const imgWidth = pageWidth;
|
|
||||||
const imgHeight = (canvas.height * imgWidth) / canvas.width;
|
|
||||||
|
|
||||||
// 添加图片到PDF
|
|
||||||
pdf.addImage(imgData, 'JPEG', 0, 0, imgWidth, imgHeight);
|
|
||||||
|
|
||||||
// 更新位置
|
|
||||||
position += pageContentHeight;
|
|
||||||
currentPage++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成并下载PDF
|
const pdfBuffer = await window.electronAPI.generateReportPdf({
|
||||||
const pdfBlob = pdf.output('blob');
|
selector: '#popup-report-root',
|
||||||
const url = URL.createObjectURL(pdfBlob);
|
pageSize: 'A4',
|
||||||
const a = document.createElement('a');
|
landscape: true, // 横向
|
||||||
a.href = url;
|
printBackground: true
|
||||||
a.download = '体态测量报告单.pdf';
|
})
|
||||||
document.body.appendChild(a);
|
|
||||||
a.click();
|
const blob = new Blob([pdfBuffer], { type: 'application/pdf' })
|
||||||
document.body.removeChild(a);
|
const form = new FormData()
|
||||||
URL.revokeObjectURL(url);
|
// 使用检测ID作为文件名
|
||||||
emit("closePopUpOnlyReport",false)
|
const filename = `${props.detectionInfo.id || 'report'}.pdf`
|
||||||
|
form.append('file', blob, filename)
|
||||||
|
|
||||||
|
// 如果有detectionInfo.id,则上传到后端
|
||||||
|
if (props.detectionInfo.id) {
|
||||||
|
const res = await fetch(`${BACKEND_URL}/api/reports/${props.detectionInfo.id}/upload`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: form
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error(`HTTP ${res.status}: ${res.statusText}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const json = await res.json()
|
||||||
|
if (json.success) {
|
||||||
|
ElMessage.success('报告生成并上传成功')
|
||||||
|
emit('closePopUpOnlyReport', true)
|
||||||
|
} else {
|
||||||
|
throw new Error(json.error || '上传失败')
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 仅供预览或下载
|
||||||
|
const url = URL.createObjectURL(blob)
|
||||||
|
const a = document.createElement('a')
|
||||||
|
a.href = url
|
||||||
|
a.download = filename
|
||||||
|
document.body.appendChild(a)
|
||||||
|
a.click()
|
||||||
|
document.body.removeChild(a)
|
||||||
|
URL.revokeObjectURL(url)
|
||||||
|
emit('closePopUpOnlyReport', true)
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('报告生成异常:', e)
|
||||||
|
ElMessage.error(`报告生成失败:${e.message}`)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
// const generatePDF = async () => {
|
||||||
|
// const element = document.getElementById('pdf-content');
|
||||||
|
|
||||||
|
// // PDF尺寸配置
|
||||||
|
// const pdf = new jsPDF('p', 'mm', 'a4');
|
||||||
|
// const pageWidth = pdf.internal.pageSize.getWidth();
|
||||||
|
// const pageHeight = pdf.internal.pageSize.getHeight();
|
||||||
|
|
||||||
|
// // 计算缩放比例
|
||||||
|
// const scale = 2; // 提高清晰度
|
||||||
|
// const elementWidth = element.offsetWidth;
|
||||||
|
// const elementHeight = element.scrollHeight;
|
||||||
|
// const widthRatio = pageWidth / (elementWidth / scale);
|
||||||
|
|
||||||
|
// // 智能分页算法
|
||||||
|
// const pageContentHeight = (pageHeight / widthRatio) * scale;
|
||||||
|
// let position = 0;
|
||||||
|
// let currentPage = 1;
|
||||||
|
|
||||||
|
// while (position < elementHeight) {
|
||||||
|
// // 添加新页面(首页除外)
|
||||||
|
// if (currentPage > 1) {
|
||||||
|
// pdf.addPage();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // 分块渲染
|
||||||
|
// const canvas = await html2canvas(element, {
|
||||||
|
// scale,
|
||||||
|
// useCORS: true,
|
||||||
|
// windowHeight: pageContentHeight,
|
||||||
|
// height: pageContentHeight,
|
||||||
|
// y: position,
|
||||||
|
// x: 0,
|
||||||
|
// scrollY: -window.scrollY // 锁定滚动位置
|
||||||
|
// });
|
||||||
|
|
||||||
|
// // 计算当前块尺寸
|
||||||
|
// const imgData = canvas.toDataURL('image/jpeg', 1.0);
|
||||||
|
// const imgWidth = pageWidth;
|
||||||
|
// const imgHeight = (canvas.height * imgWidth) / canvas.width;
|
||||||
|
|
||||||
|
// // 添加图片到PDF
|
||||||
|
// pdf.addImage(imgData, 'JPEG', 0, 0, imgWidth, imgHeight);
|
||||||
|
|
||||||
|
// // 更新位置
|
||||||
|
// position += pageContentHeight;
|
||||||
|
// currentPage++;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // 生成并下载PDF
|
||||||
|
// const pdfBlob = pdf.output('blob');
|
||||||
|
// const url = URL.createObjectURL(pdfBlob);
|
||||||
|
// const a = document.createElement('a');
|
||||||
|
// a.href = url;
|
||||||
|
// a.download = '体态测量报告单.pdf';
|
||||||
|
// document.body.appendChild(a);
|
||||||
|
// a.click();
|
||||||
|
// document.body.removeChild(a);
|
||||||
|
// URL.revokeObjectURL(url);
|
||||||
|
// emit("closePopUpOnlyReport",false)
|
||||||
|
// };
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
@ -184,6 +184,11 @@
|
|||||||
<div class="PopUpReport-border2">{{ detectionInfo.treatment_info }}</div>
|
<div class="PopUpReport-border2">{{ detectionInfo.treatment_info }}</div>
|
||||||
<div class="PopUpReport-title2">备注</div>
|
<div class="PopUpReport-title2">备注</div>
|
||||||
<div class="PopUpReport-border3">{{ detectionInfo.suggestion_info }}</div>
|
<div class="PopUpReport-border3">{{ detectionInfo.suggestion_info }}</div>
|
||||||
|
<div class="PopUpReport-footer">
|
||||||
|
<div style="margin-right: 80px;">检测时间:{{ detectionInfo.created_at }}</div>
|
||||||
|
<div style="margin-right: 80px;">报告时间:{{ getFormattedTime() }}</div>
|
||||||
|
<div>检测医生:{{ detectionInfo.creator_name }}</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
@ -678,4 +683,15 @@ function getFormattedTime() {
|
|||||||
display: none !important;
|
display: none !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.PopUpOnlyReport-footer{
|
||||||
|
margin-top: 40px;
|
||||||
|
padding-top: 40px;
|
||||||
|
border-top: 1px solid #333;
|
||||||
|
display: flex;
|
||||||
|
font-weight: 700;
|
||||||
|
font-style: normal;
|
||||||
|
color: rgb(40, 40, 40);
|
||||||
|
font-size: 18px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@ -1,8 +1,17 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="viewPDF-container">
|
<div class="viewPDF-container">
|
||||||
<div class="pdf-viewer">
|
<div class="viewPDF-header">
|
||||||
<div class="pdf-container" ref="pdfContainer"></div>
|
<div style="display: flex; align-items: center;">
|
||||||
</div>
|
</div>
|
||||||
|
<img src="@/assets/archive/close.png" alt="" style="cursor: pointer;" @click="handleCancel">
|
||||||
|
</div>
|
||||||
|
<div style="padding: 0 20px;height: calc(100vh - 80px);">
|
||||||
|
<iframe :src="pdfUrl" width="100%" height="100%" frameborder="0"></iframe>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- <div class="pdf-viewer">
|
||||||
|
<div class="pdf-container" ref="pdfContainer"></div>
|
||||||
|
</div> -->
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
@ -12,12 +21,23 @@ import { patientAPI, detectionAPI,historyAPI,getBackendUrl } from '@/services/ap
|
|||||||
|
|
||||||
import { ref, onMounted } from 'vue'
|
import { ref, onMounted } from 'vue'
|
||||||
import * as pdfjsLib from 'pdfjs-dist'
|
import * as pdfjsLib from 'pdfjs-dist'
|
||||||
|
const emit = defineEmits([ 'closeViewPDF' ]);
|
||||||
|
const props = defineProps({
|
||||||
|
pdfUrl: {
|
||||||
|
required: false,
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const pdfUrl = ref(props.pdfUrl)
|
||||||
const pdfContainer = ref(null) // 容器用于挂载多个 canvas
|
const pdfContainer = ref(null) // 容器用于挂载多个 canvas
|
||||||
// 设置 worker 路径(重要)
|
// 设置 worker 路径(重要)
|
||||||
pdfjsLib.GlobalWorkerOptions.workerSrc = '/pdf.worker.min.js'
|
pdfjsLib.GlobalWorkerOptions.workerSrc = '/pdf.worker.min.js'
|
||||||
const BACKEND_URL = getBackendUrl()
|
const BACKEND_URL = getBackendUrl()
|
||||||
const pdfCanvas = ref(null)
|
const pdfCanvas = ref(null)
|
||||||
|
function handleCancel(){
|
||||||
|
emit('closeViewPDF',false)
|
||||||
|
}
|
||||||
// const renderPDF = async (url) => {
|
// const renderPDF = async (url) => {
|
||||||
// try {
|
// try {
|
||||||
// // 加载 PDF 文档
|
// // 加载 PDF 文档
|
||||||
@ -106,7 +126,7 @@ const renderPage = async (pdf, pageNum, scale) => {
|
|||||||
}
|
}
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
// 替换为你的 PDF 文件路径或 URL
|
// 替换为你的 PDF 文件路径或 URL
|
||||||
renderPDF(`${BACKEND_URL}/202512070001/20251209141628/report_142802459.pdf`) // 可以是本地文件或远程链接
|
// renderPDF(`${BACKEND_URL}/202512070001/20251209141628/report_142802459.pdf`) // 可以是本地文件或远程链接
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -139,4 +159,12 @@ canvas {
|
|||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.viewPDF-header{
|
||||||
|
height: 60px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
align-items: center;
|
||||||
|
padding-right: 20px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
Loading…
Reference in New Issue
Block a user