bookFlip.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. <template>
  2. <div :class="['report_page', { 'full_screen': isShowFullScreen }]" style="position: absolute;top: -9999999px;z-index: -10;">
  3. <!-- 点击封面进入全屏 -->
  4. <div class="joint_print_area">
  5. <!-- 点击封面进入全屏预览模式 -->
  6. <!-- <BookCover :bookBg="`${bookBg}_bg`" :title="coverTitle" :subtitle="subtitle" :showButton="true" :requestLoading="requestLoading" :openLoading="openLoading" @openFullScreen="openFullScreen" :style="{width:`${bookWidth}px`,height:`${bookHeight}px`,margin:'0 auto'}" v-if="!isShowFullScreen"></BookCover> -->
  7. <!-- 全屏预览 -->
  8. <div id="canvas" v-if="isShowFullScreen">
  9. <!-- 右上角放大缩小按钮 -->
  10. <div class="close-zoom-icon" @click="CloseFullScreen"><img class="close" src="@/assets/icon/close.webp" /><span>关闭全屏</span></div>
  11. <div class="magazine-viewport">
  12. <div class="container">
  13. <!-- 翻书容器 -->
  14. <div class="magazine" id="flipbook" ref="bookContainer">
  15. <!-- 封面 -->
  16. <BookCover :showButton="false" :bookBg="`${bookBg}_bg`" :title="coverTitle" :subtitle="subtitle"></BookCover>
  17. <div class="area_page" v-for="(page, index) in bookPages" :key="index">
  18. <!-- 插槽:自定义每页内容 -->
  19. <slot :page="index + 1" :content="page"></slot>
  20. <!-- <div class="area_page_number">第 {{ currentPage }} 页</div> -->
  21. </div>
  22. <!-- 封面 -->
  23. <BookCover :showButton="false" :isCover="true" :bookBg="`${bookBg}_cover_bg`"></BookCover>
  24. <template v-if="bookPages.length % 2 !== 0">
  25. <BookCover :showButton="false" :isCover="true" :bookBg="`${bookBg}_cover_bg`"></BookCover>
  26. </template>
  27. </div>
  28. </div>
  29. <!-- Next button -->
  30. <div ignore="1" class="next-button"><i class="el-icon-arrow-right"></i></div>
  31. <!-- Previous button -->
  32. <div ignore="1" class="previous-button"><i class="el-icon-arrow-left"></i></div>
  33. </div>
  34. <!-- 翻页控制按钮 -->
  35. <div class="thumbnails">
  36. <div class="book_controls">
  37. <div class="zoom">
  38. <img class="zoom_icon zoom_in_icon" src="@/assets/icon/enlarge_icon.png" />
  39. <img class="zoom_icon zoom_out_icon" src="@/assets/icon/shrink_icon.png" />
  40. </div>
  41. <div class="page_size">
  42. <span class="butn_prev" @click="prevPage"><img src="@/assets/report/turn_prev.webp" /></span>
  43. <span class="page_info">{{ currentPage }}{{ bookPages.length }}</span>
  44. <span class="butn_next" @click="nextPage"><img src="@/assets/report/turn_next.webp" /></span>
  45. </div>
  46. <el-button class="download" type="primary" :loading="loading" @click="DownloadPdf">下载报告册</el-button>
  47. </div>
  48. </div>
  49. <!-- <div class="page_dialog">
  50. <el-dialog title="下载PDF" class="page_dialog" :visible.sync="showReportLoading" width="500px" top="15%" append-to-body>
  51. <div class="report_loading">
  52. <div class="report_loading_icon">
  53. <img src="@/assets/report/report_loading.png">
  54. </div>
  55. <div class="report_loading_title">正在努力生成PDF中,请稍等...</div>
  56. <div class="report_loading_progress">
  57. <el-progress :text-inside="true" color="#2E64FA" text-color="#ffffff" :stroke-width="16" :percentage="targetProgress"></el-progress>
  58. </div>
  59. </div>
  60. </el-dialog>
  61. </div> -->
  62. </div>
  63. <!-- 下载模版 -->
  64. <!-- style="position: absolute;top: -9999999px;z-index: -10;" -->
  65. <div class="magazine-viewport web_mode">
  66. <!-- 封面 -->
  67. <BookCover class="web_cover web_area_page" :showButton="false" :bookBg="`${bookBg}_bg`" :title="coverTitle" :subtitle="subtitle"></BookCover>
  68. <slot type="web_mode"></slot>
  69. <!-- 封面 -->
  70. <BookCover class="web_cover web_area_page" :showButton="false" :isCover="true" :bookBg="`${bookBg}_cover_bg`"></BookCover>
  71. </div>
  72. </div>
  73. </div>
  74. </template>
  75. <script>
  76. // import $ from 'jquery'; // 先导入 jQuery
  77. // import 'turn.js';
  78. import turn from '@/utils/turn.js';
  79. import zoom from './js/zoom.min.js';
  80. import BookCover from './bookCover.vue';
  81. import { disableControls, addPage,largeMagazineWidth,resizeViewport,setArrows,loadLargePage,loadSmallPage } from './js/magazine.js';
  82. import { jsPDF } from "jspdf";
  83. import html2canvas from "html2canvas";
  84. import domtoimage from 'dom-to-image';
  85. import { mapGetters } from "vuex";
  86. export default {
  87. props: {
  88. // 书页数据(数组长度建议为偶数)
  89. bookPages: {
  90. type: Array,
  91. required: true,
  92. default: () => []
  93. },
  94. bookBg:{
  95. type:String,
  96. default: 'grade_leader'
  97. },
  98. coverTitle:{//封面标题
  99. type:String,
  100. default: '联校总分分析报告册'
  101. },
  102. subtitle:{//封面副标题
  103. type:String,
  104. default: '联校总分分析报告册'
  105. },
  106. requestLoading:{
  107. type:Boolean,
  108. default: false
  109. },//接口请求的loading
  110. openLoading:{
  111. type:Boolean,
  112. default: false
  113. },//开发全屏预览
  114. },
  115. components:{BookCover},
  116. data() {
  117. return {
  118. isShowFullScreen: false,
  119. bookHeight:780,//封面高度
  120. bookWidth:600,//封面宽度
  121. currentPage: '', // 当前页码
  122. totalPages: 0, // 总页数(由 turn.js 计算)
  123. showReportLoading:false,
  124. targetProgress:0,
  125. loading:false
  126. };
  127. },
  128. computed: {
  129. ...mapGetters(["userInfo"]),
  130. reportTitle() {
  131. return this?.$store?.state?.report?.examSelectItem?.examName ?? '';
  132. }
  133. },
  134. mounted() {
  135. //设置书本宽度和高度
  136. this.setBookSize();
  137. // 监听窗口大小变化,实时更新
  138. window.addEventListener('resize', this.setBookSize);
  139. },
  140. beforeDestroy() {
  141. // 销毁翻书实例,避免内存泄漏
  142. if (this.$refs.bookContainer) {
  143. $(this.$refs.bookContainer).turn('destroy');
  144. }
  145. window.removeEventListener('resize', this.setBookSize);
  146. },
  147. methods: {
  148. //设置书本宽度和高度
  149. setBookSize(){
  150. const bookHeight = $(window).height() - 120;//书本高度
  151. this.bookHeight = bookHeight;
  152. this.bookWidth = Math.round(bookHeight * 0.706);// 书本宽度 0.706 宽高的比例
  153. },
  154. //点击查看全屏
  155. openFullScreen(){
  156. this.$emit('OpenBookImages');
  157. },
  158. //打开全屏预览
  159. showFullScreen() {
  160. $('#canvas').hide();
  161. this.isShowFullScreen = true;//是否显示全屏
  162. this.initBook(); // 初始化翻书效果
  163. },
  164. // 初始化翻书效果
  165. initBook() {
  166. const b_height = $(window).height() - 120;//书本高度
  167. const b_width = Math.round(b_height * 0.706) * 2;// 书本宽度 0.706 宽高的比例
  168. this.$nextTick(() => {
  169. $('#canvas').fadeIn(1000);
  170. const $book = $(this.$refs.bookContainer);
  171. if ($book.width() == 0 || $book.height() == 0) {
  172. setTimeout(loadApp, 10);
  173. return;
  174. }
  175. // 初始化 turn.js
  176. const _that = this;
  177. const totalPages = this.bookPages.length;//总页数
  178. $book.turn({
  179. // 页面尺寸(A4 高度示例)
  180. // height: 1285, // 单页高度(对应 A4 72dpi 高度)
  181. // width: 1816, // 单页宽度(对应 A4 72dpi 宽度)908
  182. width: b_width, // 书本宽度
  183. height: b_height, // 书本高度
  184. duration: 1000, //翻页速度,值越小越快
  185. autoCenter: true, // 自动居中
  186. acceleration: false,//设置硬件加速模式,用于触摸设备此值必须是真的
  187. gradients: true,//置翻页时是否显示翻页跟阴影
  188. display: 'double', // 双页显示(适合PC端)
  189. elevation: 50, // 翻页阴影高度(增强立体感)
  190. pages: totalPages,
  191. when: {
  192. // 翻页前触发
  193. turning: function (event, page, view) {
  194. const book = $(this);
  195. const pages = book.turn('pages') - 2;
  196. if(page > 1 && page < pages){
  197. console.log(page , pages)
  198. const prev = view[0] - 1;
  199. const next = view[1] < pages ? view[1] - 1 : '';
  200. _that.currentPage = next?`${prev}-${next}/`:`${prev}/`;
  201. }else{
  202. _that.currentPage = '';
  203. }
  204. // 显示和隐藏按钮
  205. disableControls(page);
  206. },
  207. // 翻页后触发
  208. turned: function (event, page, view) {
  209. // 显示和隐藏按钮
  210. disableControls(page);
  211. $(this).turn('center');
  212. if (page == 1) {
  213. // 表示调用翻页 API 并指定翻页效果为 “Peel( peeling,即 “剥开” 效果)”,且翻页的起始位置为右下角(br 是 bottom right 的缩写)
  214. $(this).turn('peel', 'br');
  215. }
  216. },
  217. // missing: function (event, pages) {
  218. // // Add pages that aren't in the magazine
  219. // for (var i = 0; i < pages.length; i++){
  220. // addPage(pages[i], $(this));
  221. // }
  222. // }
  223. }
  224. });
  225. // 初始化页码信息
  226. // this.totalPages = $book.turn('pages');
  227. // Zoom.js
  228. $('#canvas .magazine-viewport').zoom({
  229. flipbook: $('.magazine'),
  230. max: function () {
  231. return largeMagazineWidth() / $('.magazine').width();
  232. },
  233. when: {
  234. swipeLeft: function () {
  235. $(this).zoom('flipbook').turn('next');
  236. },
  237. swipeRight: function () {
  238. $(this).zoom('flipbook').turn('previous');
  239. },
  240. resize: function (event, scale, page, pageElement) {
  241. // if (scale == 1)
  242. // loadSmallPage(page, pageElement);
  243. // else
  244. // loadLargePage(page, pageElement);
  245. },
  246. zoomIn: function () {
  247. $('.made').hide();
  248. $('.magazine').removeClass('animated').addClass('zoom-in');
  249. $('.zoom-icon').removeClass('zoom-icon-in').addClass('zoom-icon-out');
  250. // if (!window.escTip && !$.isTouch) {
  251. // escTip = true;
  252. // $('<div />', { 'class': 'exit-message' }).
  253. // html('<div>Press ESC to exit</div>').
  254. // appendTo($('body')).
  255. // delay(2000).
  256. // animate({ opacity: 0 }, 500, function () {
  257. // $(this).remove();
  258. // });
  259. // }
  260. },
  261. zoomOut: function () {
  262. $('.exit-message').hide();
  263. $('.thumbnails').fadeIn();
  264. $('.made').fadeIn();
  265. $('.zoom-icon').removeClass('zoom-icon-out').addClass('zoom-icon-in');
  266. setTimeout(function () {
  267. $('.magazine').addClass('animated').removeClass('zoom-in');
  268. resizeViewport();
  269. }, 0);
  270. }
  271. }
  272. });
  273. $(document).keydown(function (e) {
  274. const previous = 37, next = 39, esc = 27;
  275. switch (e.keyCode) {
  276. case previous:
  277. // left arrow
  278. $('.magazine').turn('previous');
  279. e.preventDefault();
  280. break;
  281. case next:
  282. //right arrow
  283. $('.magazine').turn('next');
  284. e.preventDefault();
  285. break;
  286. case esc:
  287. $('#canvas .magazine-viewport').zoom('zoomOut');
  288. e.preventDefault();
  289. break;
  290. }
  291. });
  292. $(window).resize(function () {
  293. resizeViewport();
  294. }).bind('orientationchange', function () {
  295. resizeViewport();
  296. });
  297. // Events for the next button
  298. $('.next-button').click(function () {
  299. $('.magazine').turn('next');
  300. setTimeout(function () {
  301. setArrows();
  302. }, 300);
  303. });
  304. // Events for the next button
  305. $('.previous-button').bind($.mouseEvents.over, function () {
  306. $(this).addClass('previous-button-hover');
  307. }).bind($.mouseEvents.out, function () {
  308. $(this).removeClass('previous-button-hover');
  309. }).bind($.mouseEvents.down, function () {
  310. $(this).addClass('previous-button-down');
  311. }).bind($.mouseEvents.up, function () {
  312. $(this).removeClass('previous-button-down');
  313. }).click(function () {
  314. $('.magazine').turn('previous');
  315. setTimeout(function () {
  316. setArrows();
  317. }, 300);
  318. });
  319. // Zoom icon
  320. $('.zoom_in_icon').on('click', function () {
  321. $('#canvas .magazine-viewport').zoom('zoomIn');
  322. });
  323. $('.zoom_out_icon').on('click', function () {
  324. $('#canvas .magazine-viewport').zoom('zoomOut');
  325. });
  326. resizeViewport();
  327. $('.magazine').addClass('animated');
  328. })
  329. },
  330. //退出全屏
  331. CloseFullScreen() {
  332. this.isShowFullScreen = false;
  333. },
  334. // 上一页
  335. prevPage() {
  336. $('.magazine').turn('previous');
  337. setTimeout(function () {
  338. setArrows();
  339. }, 300);
  340. },
  341. // 下一页
  342. nextPage() {
  343. $('.magazine').turn('next');
  344. setTimeout(function () {
  345. setArrows();
  346. }, 300);
  347. },
  348. async DownloadPdf() {
  349. this.loading = true;
  350. this.targetProgress = 1;
  351. // this.showReportLoading = true;
  352. //获取所有的area_page 元素
  353. const elements = document.querySelectorAll(".web_mode .web_cover");
  354. const pdf = new jsPDF("p", "pt", "a4"); // 'p'表示纵向,'a4'表示A4纸张尺寸
  355. const pdfWidth = pdf.internal.pageSize.getWidth(); //获取pdf的宽度
  356. const pdfHeight = pdf.internal.pageSize.getHeight(); //获取pdf的高度
  357. let yPos = 0; //当前图像在pdf页面上的垂直位置的变量
  358. let i = 1;
  359. let imageList = [];
  360. // 遍历每个 area_page 元素并按顺序处理
  361. for (const element of elements) {
  362. await html2canvas(element, {
  363. scale: 2, // 增加缩放比例
  364. useCORS: true, // 允许跨域
  365. logging: true, // 是否显示进度条
  366. letterRendering: true, // 文字抗锯齿 启用字母渲染
  367. }).then(async(canvas) => {
  368. // 将 Canvas 对象转换为 PNG 格式的 Data URL 字符串
  369. const blob = await new Promise((resolve) => canvas.toBlob(resolve, "image/png"));
  370. const imgUrl = URL.createObjectURL(blob);
  371. imageList.push(imgUrl)
  372. });
  373. }
  374. imageList.splice(1, 0, ...this.bookPages);
  375. // console.log(imageList)
  376. const stepLens = imageList?.length || 1;
  377. for (const imgData of imageList) {
  378. const imgProps = pdf.getImageProperties(imgData); // 获取图像的属性,包括宽度和高度
  379. const imgWidth = imgProps.width;
  380. const imgHeight = imgProps.height;
  381. const ratio = Math.min(pdfWidth / imgWidth, pdfHeight / imgHeight); //计算图片的缩放比例
  382. const adjustWidth = imgWidth * ratio;
  383. const adjustHeight = imgHeight * ratio;
  384. // 在添加每个图像之前,检查当前页面的高度是否足够。如果不够,则添加新页面,并将 yPos 重置为 0
  385. if (yPos + adjustHeight > pdfHeight) {
  386. pdf.addPage();
  387. yPos = 0;
  388. }
  389. // 将图像添加到pdf中
  390. pdf.addImage(imgData, "PNG", 0, yPos, adjustWidth, adjustHeight);
  391. yPos += adjustHeight;
  392. // 如果添加图像后剩余空间不足一页,则添加新页面
  393. if (yPos > pdfHeight) {
  394. pdf.addPage();
  395. yPos = 0;
  396. }
  397. const currentProgress = Math.min(Math.round((i / stepLens) * 100),100);
  398. this.targetProgress = currentProgress;
  399. i++;
  400. }
  401. // 保存pdf文件
  402. pdf.save(`${this.reportTitle}_${this.coverTitle}.pdf`);
  403. // this.showReportLoading = false; //关闭加载loading
  404. this.loading = false;
  405. },
  406. // async DownloadPdfNew() {
  407. // //获取所有的area_page 元素
  408. // const elements = document.querySelectorAll(".web_mode .web_area_page");
  409. // this.loading = true;
  410. // // this.targetProgress = 1;
  411. // // this.showReportLoading = true;
  412. // const pdf = new jsPDF("p", "pt", "a4"); // 'p'表示纵向,'a4'表示A4纸张尺寸
  413. // const pdfWidth = pdf.internal.pageSize.getWidth(); //获取pdf的宽度
  414. // const pdfHeight = pdf.internal.pageSize.getHeight(); //获取pdf的高度
  415. // let yPos = 0; //当前图像在pdf页面上的垂直位置的变量
  416. // // let i = 1;
  417. // let imageList = [];
  418. // // 遍历每个 area_page 元素并按顺序处理
  419. // for (const element of elements) {
  420. // await html2canvas(element, {
  421. // scale: 2, // 增加缩放比例
  422. // useCORS: true, // 允许跨域
  423. // logging: true, // 是否显示进度条
  424. // letterRendering: true, // 文字抗锯齿 启用字母渲染
  425. // }).then(async(canvas) => {
  426. // // 将 Canvas 对象转换为 PNG 格式的 Data URL 字符串
  427. // const blob = await new Promise((resolve) => canvas.toBlob(resolve, "image/png"));
  428. // const imgUrl = URL.createObjectURL(blob);
  429. // imageList.push(imgUrl)
  430. // });
  431. // }
  432. // // const stepLens = imageList?.length || 1;
  433. // for (const imgData of imageList) {
  434. // const imgProps = pdf.getImageProperties(imgData); // 获取图像的属性,包括宽度和高度
  435. // const imgWidth = imgProps.width;
  436. // const imgHeight = imgProps.height;
  437. // const ratio = Math.min(pdfWidth / imgWidth, pdfHeight / imgHeight); //计算图片的缩放比例
  438. // const adjustWidth = imgWidth * ratio;
  439. // const adjustHeight = imgHeight * ratio;
  440. // // 在添加每个图像之前,检查当前页面的高度是否足够。如果不够,则添加新页面,并将 yPos 重置为 0
  441. // if (yPos + adjustHeight > pdfHeight) {
  442. // pdf.addPage();
  443. // yPos = 0;
  444. // }
  445. // // 将图像添加到pdf中
  446. // pdf.addImage(imgData, "PNG", 0, yPos, adjustWidth, adjustHeight);
  447. // yPos += adjustHeight;
  448. // // 如果添加图像后剩余空间不足一页,则添加新页面
  449. // if (yPos > pdfHeight) {
  450. // pdf.addPage();
  451. // yPos = 0;
  452. // }
  453. // // const currentProgress = Math.min(Math.round((i / stepLens) * 100),100);
  454. // // this.targetProgress = currentProgress;
  455. // // i++;
  456. // }
  457. // // 保存pdf文件
  458. // pdf.save(`${this.reportTitle}_${this.coverTitle}.pdf`);
  459. // // this.showReportLoading = false; //关闭加载loading
  460. // this.loading = false;
  461. // this.$emit('PdfLoadEnd');
  462. // },
  463. async DownloadPdfNew() {
  464. //获取所有的area_page 元素
  465. const elements = document.querySelectorAll(".web_mode .web_area_page");
  466. const elLens = elements.length - 1;
  467. this.loading = true;
  468. // this.targetProgress = 1;
  469. // this.showReportLoading = true;
  470. const pdf = new jsPDF("p", "pt", "a4"); // 'p'表示纵向,'a4'表示A4纸张尺寸
  471. const pdfWidth = pdf.internal.pageSize.getWidth(); //获取pdf的宽度
  472. const pdfHeight = pdf.internal.pageSize.getHeight(); //获取pdf的高度
  473. // 遍历每个 area_page 元素并按顺序处理
  474. for (const [pageIndex, element] of Array.from(elements).entries()) {
  475. // 确保页面元素存在并可见
  476. await this.$nextTick();
  477. if (element) {
  478. // 确保元素可见并已渲染
  479. // 确保元素可见并已渲染,并设置为横向排列样式
  480. element.style.visibility = 'visible';
  481. element.offsetHeight; // 触发重排
  482. // 等待元素完全渲染
  483. await new Promise(resolve => setTimeout(resolve, 100));
  484. // 使用 dom-to-image 生成图片
  485. const dataUrl = await domtoimage.toJpeg(element, {
  486. quality: 0.8,// 降低质量以减小文件大小
  487. // 获取完整尺寸
  488. width: element.scrollWidth*2,
  489. height: element.scrollHeight*2,
  490. // 提高画布分辨率以获得更清晰的图像
  491. // canvasWidth: element.scrollWidth * 2,
  492. // canvasHeight: element.scrollHeight * 2,
  493. // 新增高清配置
  494. // pixelRatio: window.devicePixelRatio * 2,
  495. style: {
  496. 'transform': 'scale(2)',
  497. 'transform-origin': 'left top',
  498. 'background-color': '#ffffff',
  499. // 关键:背景图尺寸适配原元素
  500. 'background-size': `${element.scrollWidth}px ${element.scrollHeight}px`, // 优先铺满且完整显示
  501. 'background-position': 'top left',
  502. 'background-repeat': 'no-repeat', // 防止背景图重复导致视觉不完整
  503. 'overflow': 'visible',
  504. 'white-space': 'normal',
  505. 'position': 'relative',
  506. 'visibility': 'visible'
  507. },
  508. bgcolor: '#ffffff'
  509. });
  510. // 获取图像属性并计算缩放比例
  511. const imgProps = pdf.getImageProperties(dataUrl);
  512. const imgWidth = imgProps.width;
  513. const imgHeight = imgProps.height;
  514. // 计算缩放比例(保持宽高比)
  515. const ratio = Math.min(pdfWidth / imgWidth, pdfHeight / imgHeight);
  516. const adjustWidth = imgWidth * ratio;
  517. const adjustHeight = imgHeight * ratio;
  518. // 居中放置图像
  519. const xPosition = (pdfWidth - adjustWidth) / 2;
  520. const yPosition = (pdfHeight - adjustHeight) / 2;
  521. // console.log("打印pdf图片尺寸", imgWidth, imgHeight);
  522. // console.log("打印pdf页面尺寸", pdfWidth, pdfHeight);
  523. // console.log("打印pdf缩放比例", ratio);
  524. // console.log("打印pdf缩放后尺寸",adjustWidth, adjustHeight);
  525. // console.log("打印pdf图片位置", xPosition, yPosition);
  526. // 如果不是第一页,添加新页面
  527. if (pageIndex > 0)
  528. {
  529. pdf.addPage();
  530. }
  531. //处理封面图铺满屏
  532. let pdfAdjustHeight = adjustHeight;
  533. if(pageIndex == 0 || pageIndex == elLens){
  534. pdfAdjustHeight = adjustHeight + 6
  535. }
  536. pdf.addImage(dataUrl, "JPEG", xPosition, yPosition - 6, adjustWidth, pdfAdjustHeight);
  537. }
  538. }
  539. // 保存pdf文件
  540. pdf.save(`${this.reportTitle}_${this.coverTitle}.pdf`);
  541. // this.showReportLoading = false; //关闭加载loading
  542. this.loading = false;
  543. this.$emit('PdfLoadEnd');
  544. },
  545. }
  546. };
  547. </script>
  548. <style scoped lang="scss">
  549. @import '../components/css/magazine.css'; // 引入 SCSS 文件
  550. .report_page {
  551. display: flex;
  552. flex-direction: column;
  553. align-items: center;
  554. padding: 0;
  555. box-sizing: border-box;
  556. background-color: #F0F4FB;
  557. }
  558. /* 书本容器样式 */
  559. // #flipbook {
  560. // box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
  561. // }
  562. /* 单页样式(注意:宽度为书本的一半,因为默认双页显示) */
  563. // .joint_print_area {
  564. // width: 50%;
  565. // height: 100%;
  566. // background-color: #fff;
  567. // overflow: hidden;
  568. // }
  569. // .area_page {
  570. // width: 100%;
  571. // height: 100%;
  572. // padding: 32px;
  573. // box-sizing: border-box;
  574. // // background: #FFFFFF;
  575. // box-shadow: inset 1px 0px 0px 0px #EEEEEE;
  576. // }
  577. /* 控制按钮样式 */
  578. .book_controls {
  579. display: flex;
  580. align-items: center;
  581. justify-content: space-between;
  582. width: 100%;
  583. height: 60px;
  584. background: #FFFFFF;
  585. // margin-top: 40px;
  586. padding: 12px 24px;
  587. box-sizing: border-box;
  588. .zoom {
  589. display: inline-flex;
  590. align-items: center;
  591. .zoom_icon {
  592. width: 32px;
  593. height: 32px;
  594. margin-right: 20px;
  595. cursor: pointer;
  596. }
  597. }
  598. .page_size {
  599. display: inline-flex;
  600. align-items: center;
  601. .butn_prev{
  602. width: 24px;
  603. height: 24px;
  604. margin-right: 15px;
  605. cursor: pointer;
  606. }
  607. .butn_next{
  608. width: 24px;
  609. height: 24px;
  610. margin-left: 15px;
  611. cursor: pointer;
  612. }
  613. img{
  614. width: 24px;
  615. height: 24px;
  616. }
  617. .page_info {
  618. font-weight: 500;
  619. font-size: 16px;
  620. color: #333333;
  621. }
  622. }
  623. .download {
  624. padding: 8px 16px;
  625. height: 36px;
  626. background-color: #2E64FA;
  627. border-radius: 4px;
  628. font-size: 14px;
  629. color: #FFFFFF;
  630. border: none;
  631. cursor: pointer;
  632. &:disabled {
  633. background-color: #ccc;
  634. cursor: not-allowed;
  635. }
  636. }
  637. }
  638. </style>