|
|
@@ -1,5 +1,5 @@
|
|
|
<template>
|
|
|
- <div :class="['report_page', { 'full_screen': isShowFullScreen }]" style="position: absolute;top: -9999999px;z-index: -10;">
|
|
|
+ <div :class="['report_page', { 'full_screen': isShowFullScreen }]">
|
|
|
<!-- 点击封面进入全屏 -->
|
|
|
<div class="joint_print_area">
|
|
|
<!-- 点击封面进入全屏预览模式 -->
|
|
|
@@ -63,6 +63,7 @@
|
|
|
<!-- 下载模版 -->
|
|
|
<!-- style="position: absolute;top: -9999999px;z-index: -10;" -->
|
|
|
<div class="magazine-viewport web_mode">
|
|
|
+ <el-button class="download_btn" size="small" type="primary" :loading="pdfLoading" @click="DownloadPdfNew">下载PDF</el-button>
|
|
|
<!-- 封面 -->
|
|
|
<BookCover class="web_cover web_area_page" :showButton="false" :bookBg="`${bookBg}_bg`" :title="coverTitle" :subtitle="subtitle"></BookCover>
|
|
|
<slot type="web_mode"></slot>
|
|
|
@@ -70,6 +71,19 @@
|
|
|
<BookCover class="web_cover web_area_page" :showButton="false" :isCover="true" :bookBg="`${bookBg}_cover_bg`"></BookCover>
|
|
|
</div>
|
|
|
</div>
|
|
|
+ <div class="page_dialog">
|
|
|
+ <el-dialog title="下载PDF" class="page_dialog" :visible.sync="showReportLoading" width="500px" top="15%" append-to-body>
|
|
|
+ <div class="report_loading">
|
|
|
+ <div class="report_loading_icon">
|
|
|
+ <img src="@/assets/report/report_loading.png">
|
|
|
+ </div>
|
|
|
+ <div class="report_loading_title">正在努力生成PDF中,请稍等...</div>
|
|
|
+ <div class="report_loading_progress">
|
|
|
+ <el-progress :text-inside="true" color="#2E64FA" text-color="#ffffff" :stroke-width="16" :percentage="targetProgress"></el-progress>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </el-dialog>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
@@ -124,7 +138,8 @@ export default {
|
|
|
totalPages: 0, // 总页数(由 turn.js 计算)
|
|
|
showReportLoading:false,
|
|
|
targetProgress:0,
|
|
|
- loading:false
|
|
|
+ loading:false,
|
|
|
+ pdfLoading:false,
|
|
|
};
|
|
|
},
|
|
|
computed: {
|
|
|
@@ -568,10 +583,12 @@ export default {
|
|
|
async DownloadPdfNew() {
|
|
|
//获取所有的area_page 元素
|
|
|
const elements = document.querySelectorAll(".web_mode .web_area_page");
|
|
|
- const elLens = elements.length - 1;
|
|
|
- this.loading = true;
|
|
|
- // this.targetProgress = 1;
|
|
|
- // this.showReportLoading = true;
|
|
|
+ const elLens = elements.length;
|
|
|
+ const elLensIndex = elLens - 1;
|
|
|
+ this.pdfLoading = true;
|
|
|
+ this.targetProgress = 0;
|
|
|
+ this.showReportLoading = true;
|
|
|
+ const itemProgress = elLens > 0 ? Math.ceil(100 / elLens) : 0;
|
|
|
const pdf = new jsPDF("p", "pt", "a4"); // 'p'表示纵向,'a4'表示A4纸张尺寸
|
|
|
const pdfWidth = pdf.internal.pageSize.getWidth(); //获取pdf的宽度
|
|
|
const pdfHeight = pdf.internal.pageSize.getHeight(); //获取pdf的高度
|
|
|
@@ -584,6 +601,7 @@ export default {
|
|
|
// 确保元素可见并已渲染,并设置为横向排列样式
|
|
|
element.style.visibility = 'visible';
|
|
|
element.offsetHeight; // 触发重排
|
|
|
+
|
|
|
// 等待元素完全渲染
|
|
|
await new Promise(resolve => setTimeout(resolve, 100));
|
|
|
|
|
|
@@ -594,13 +612,11 @@ export default {
|
|
|
width: element.scrollWidth*2,
|
|
|
height: element.scrollHeight*2,
|
|
|
// 提高画布分辨率以获得更清晰的图像
|
|
|
- // canvasWidth: element.scrollWidth * 2,
|
|
|
- // canvasHeight: element.scrollHeight * 2,
|
|
|
- // 新增高清配置
|
|
|
- // pixelRatio: window.devicePixelRatio * 2,
|
|
|
+ canvasWidth: element.scrollWidth * 2,
|
|
|
+ canvasHeight: element.scrollHeight * 2,
|
|
|
style: {
|
|
|
'transform': 'scale(2)',
|
|
|
- 'transform-origin': 'left top',
|
|
|
+ 'transform-origin': 'top left',
|
|
|
'background-color': '#ffffff',
|
|
|
// 关键:背景图尺寸适配原元素
|
|
|
'background-size': `${element.scrollWidth}px ${element.scrollHeight}px`, // 优先铺满且完整显示
|
|
|
@@ -613,10 +629,8 @@ export default {
|
|
|
},
|
|
|
bgcolor: '#ffffff'
|
|
|
});
|
|
|
-
|
|
|
// 获取图像属性并计算缩放比例
|
|
|
const imgProps = pdf.getImageProperties(dataUrl);
|
|
|
-
|
|
|
const imgWidth = imgProps.width;
|
|
|
const imgHeight = imgProps.height;
|
|
|
|
|
|
@@ -628,6 +642,7 @@ export default {
|
|
|
// 居中放置图像
|
|
|
const xPosition = (pdfWidth - adjustWidth) / 2;
|
|
|
const yPosition = (pdfHeight - adjustHeight) / 2;
|
|
|
+
|
|
|
// console.log("打印pdf图片尺寸", imgWidth, imgHeight);
|
|
|
// console.log("打印pdf页面尺寸", pdfWidth, pdfHeight);
|
|
|
// console.log("打印pdf缩放比例", ratio);
|
|
|
@@ -640,16 +655,20 @@ export default {
|
|
|
}
|
|
|
//处理封面图铺满屏
|
|
|
let pdfAdjustHeight = adjustHeight;
|
|
|
- if(pageIndex == 0 || pageIndex == elLens){
|
|
|
+ if(pageIndex == 0 || pageIndex == elLensIndex){
|
|
|
pdfAdjustHeight = adjustHeight + 6
|
|
|
}
|
|
|
pdf.addImage(dataUrl, "JPEG", xPosition, yPosition - 6, adjustWidth, pdfAdjustHeight);
|
|
|
+ this.targetProgress += itemProgress;
|
|
|
+ // 边界处理:进度值不超过100%
|
|
|
+ this.targetProgress = Math.min(this.targetProgress, 100);
|
|
|
}
|
|
|
}
|
|
|
// 保存pdf文件
|
|
|
pdf.save(`${this.reportTitle}_${this.coverTitle}.pdf`);
|
|
|
- // this.showReportLoading = false; //关闭加载loading
|
|
|
- this.loading = false;
|
|
|
+ this.showReportLoading = false; //关闭加载loading
|
|
|
+ this.targetProgress = 0;
|
|
|
+ this.pdfLoading = false;
|
|
|
this.$emit('PdfLoadEnd');
|
|
|
},
|
|
|
}
|