ztxkui 4.2.13 → 4.2.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -57,16 +57,3 @@ export declare function setMinusPosition(dom: any, style: any): void;
57
57
  export declare function initMinusPosition(dom: any): void;
58
58
  export declare function reductionMinusPostion(dom: any, type?: any): void;
59
59
  export declare function useInitSetPostion(): void;
60
- export declare function htmlToPdfUseCanvas({ pageClassName, dom, pdfName, isShowPage, noWater, pdfOptions, imgPositionX, isDownload, }: {
61
- pageClassName?: string;
62
- dom: HTMLElement;
63
- pdfName: string;
64
- isShowPage?: boolean;
65
- noWater?: boolean;
66
- pdfOptions?: any;
67
- imgPositionX?: number;
68
- isDownload?: boolean;
69
- }): Promise<{
70
- pdfs: any;
71
- pdfBase64: any;
72
- }>;
@@ -1,14 +1,3 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -52,8 +41,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
52
41
  import jsPDF from 'jspdf';
53
42
  import { useEffect } from 'react';
54
43
  import { plus } from 'ztxkutils/dist/tools';
55
- import html2canvas from 'html2canvas';
56
- import { getToken, jwtDecode } from 'ztxkutils/dist/authority';
57
44
  /**
58
45
  * 图片转base64
59
46
  */
@@ -414,163 +401,3 @@ export function useInitSetPostion() {
414
401
  }
415
402
  }, []);
416
403
  }
417
- /**
418
- * 创建文本水印图片
419
- * @param waterText 水印文本
420
- * @param opacity 水印透明度
421
- * @returns canvas png
422
- */
423
- function createWaterHandle(obj) {
424
- var token = getToken();
425
- var defaultWaterText = '内部资料,严禁外泄!';
426
- if (token) {
427
- try {
428
- var tokenObj = jwtDecode(token);
429
- defaultWaterText = "\u6D59\u5546\u4E2D\u62D3 " + ((tokenObj === null || tokenObj === void 0 ? void 0 : tokenObj.real_name) || '');
430
- }
431
- catch (err) {
432
- console.log(err);
433
- }
434
- }
435
- var _a = obj || {}, waterText = _a.waterText, opacity = _a.opacity, fontSize = _a.fontSize, cavansWidth = _a.cavansWidth, cavansHeight = _a.cavansHeight;
436
- var canvas = document.createElement('canvas');
437
- canvas.width = cavansWidth || 240;
438
- canvas.height = cavansHeight || 100;
439
- var ctx = canvas.getContext('2d');
440
- if (ctx) {
441
- ctx.rotate((-10 * Math.PI) / 180); // 水印旋转角度
442
- ctx.font = (fontSize || '18px') + " \u5FAE\u8F6F\u96C5\u9ED1";
443
- ctx.fillStyle = "rgba(0,0,0," + (opacity ? opacity : '0.07') + ")";
444
- ctx.textAlign = 'center';
445
- ctx.textBaseline = 'middle';
446
- ctx.fillText(waterText || defaultWaterText, canvas.width / 2, canvas.height); // 水印在画布的位置x,y轴
447
- }
448
- return canvas.toDataURL('image/png');
449
- }
450
- function addPdfWaterHandle(pdf, waterBase64) {
451
- for (var i = 0; i < 10; i++) {
452
- pdf.addImage(waterBase64, 'PNG', 40, 140 * i, 200, 80, "1" + i);
453
- pdf.addImage(waterBase64, 'PNG', 280, 140 * i, 200, 80, "2" + i);
454
- }
455
- }
456
- /**
457
- * html转pdf
458
- */
459
- function createPdf(canvas, pdf, noWater, positionX, options) {
460
- var contentWidth = canvas.width;
461
- var contentHeight = canvas.height;
462
- var setWidth = (options === null || options === void 0 ? void 0 : options.width) || 592.28;
463
- var setHeight = (options === null || options === void 0 ? void 0 : options.height) || 841.89;
464
- // 一页pdf显示html页面生成的canvas高度
465
- // const pageHeight = (contentWidth / 592.28) * 841.89;
466
- var pageHeight = (contentWidth / setWidth) * setHeight;
467
- // 未生成pdf的html页面高度
468
- var leftHeight = contentHeight;
469
- // 页面拍内衣
470
- var position = 0;
471
- //a4纸的尺寸[595.28,841.89],html页面生成的canvas在pdf中图片的宽高
472
- // const imgWidth = 595.28;
473
- // const imgHeight = (592.28 / contentWidth) * contentHeight;
474
- var imgWidth = setWidth - (positionX || 20) - 10;
475
- var imgHeight = (setWidth / contentWidth) * contentHeight;
476
- var pageData = canvas.toDataURL('image/jpeg', 1.0);
477
- //有两个高度需要区分,一个是html页面的实际高度,和生成pdf的页面高度(841.89)
478
- //当内容未超过pdf一页显示的范围,无需分页
479
- if (leftHeight < pageHeight) {
480
- pdf.addImage(pageData, 'JPEG', positionX || 20, 10, imgWidth, imgHeight);
481
- if (!noWater) {
482
- var waterBase64 = createWaterHandle({
483
- opacity: '0.07',
484
- fontSize: '14px',
485
- });
486
- addPdfWaterHandle(pdf, waterBase64);
487
- }
488
- }
489
- else {
490
- while (leftHeight > 0) {
491
- pdf.addImage(pageData, 'JPEG', positionX || 20, position, imgWidth, imgHeight);
492
- if (!noWater) {
493
- var waterBase64 = createWaterHandle({
494
- opacity: '0.07',
495
- fontSize: '14px',
496
- });
497
- addPdfWaterHandle(pdf, waterBase64);
498
- }
499
- leftHeight -= pageHeight;
500
- // position -= 841.89;
501
- position -= setHeight;
502
- //避免添加空白页
503
- if (leftHeight > 0) {
504
- pdf.addPage();
505
- }
506
- }
507
- }
508
- }
509
- export function htmlToPdfUseCanvas(_a) {
510
- var pageClassName = _a.pageClassName, dom = _a.dom, pdfName = _a.pdfName, isShowPage = _a.isShowPage, noWater = _a.noWater, pdfOptions = _a.pdfOptions, imgPositionX = _a.imgPositionX, isDownload = _a.isDownload;
511
- var allDom = document.querySelectorAll(pageClassName ? pageClassName : '.html2canvas-container-page');
512
- var format = (pdfOptions === null || pdfOptions === void 0 ? void 0 : pdfOptions.format) || [632.28, 841.89];
513
- var _pdfOptions = __assign({ unit: 'pt', format: format }, (pdfOptions || {}));
514
- if (allDom.length > 0 && isShowPage) {
515
- var allDomArray = Array.prototype.slice.call(allDom);
516
- var pdfBase64_2 = [];
517
- var pdfs_2 = [];
518
- var promiseAllDomArray_1 = allDomArray.map(function (dom) {
519
- return html2canvas(dom, {
520
- scale: 2,
521
- });
522
- });
523
- return (function () {
524
- return __awaiter(this, void 0, void 0, function () {
525
- var _i, promiseAllDomArray_2, item, pdf, canvas;
526
- return __generator(this, function (_a) {
527
- switch (_a.label) {
528
- case 0:
529
- _i = 0, promiseAllDomArray_2 = promiseAllDomArray_1;
530
- _a.label = 1;
531
- case 1:
532
- if (!(_i < promiseAllDomArray_2.length)) return [3 /*break*/, 4];
533
- item = promiseAllDomArray_2[_i];
534
- pdf = new jsPDF(_pdfOptions);
535
- return [4 /*yield*/, item];
536
- case 2:
537
- canvas = _a.sent();
538
- createPdf(canvas, pdf, noWater, imgPositionX, {
539
- width: format === null || format === void 0 ? void 0 : format[0],
540
- height: format === null || format === void 0 ? void 0 : format[1],
541
- });
542
- if (isDownload) {
543
- pdf.save(pdfName + ".pdf");
544
- }
545
- pdfBase64_2.push(pdf.output('dataurlstring'));
546
- pdfs_2.push(pdf);
547
- _a.label = 3;
548
- case 3:
549
- _i++;
550
- return [3 /*break*/, 1];
551
- case 4: return [2 /*return*/, Promise.resolve({
552
- pdfs: pdfs_2,
553
- pdfBase64: pdfBase64_2,
554
- })];
555
- }
556
- });
557
- });
558
- })();
559
- }
560
- else {
561
- var pdf_2 = new jsPDF(_pdfOptions);
562
- return html2canvas(dom, { scale: 2 }).then(function (canvas) {
563
- createPdf(canvas, pdf_2, noWater, imgPositionX, {
564
- width: format === null || format === void 0 ? void 0 : format[0],
565
- height: format === null || format === void 0 ? void 0 : format[1],
566
- });
567
- if (isDownload) {
568
- pdf_2.save(pdfName + ".pdf");
569
- }
570
- return {
571
- pdfs: [pdf_2],
572
- pdfBase64: [pdf_2.output('dataurlstring')],
573
- };
574
- });
575
- }
576
- }
@@ -63,9 +63,9 @@ import { Button, Spin, message, Modal, Dropdown, Menu } from '../../index';
63
63
  // 自定义组件
64
64
  import PrintModal from './PrintModal';
65
65
  // 其他文件
66
- import { printCurrentDom, htmlToPdfNoCanvas, htmlToPdf, addWaterHandle, removeWaterHandle, } from 'ztxkutils/dist/print';
66
+ import { printCurrentDom, htmlToPdfNoCanvas, htmlToPdf, addWaterHandle, removeWaterHandle, htmlToPdfUseCanvas, } from 'ztxkutils/dist/print';
67
67
  import { createDownloadUrlNoBase, createDownloadUrl, } from 'ztxkutils/dist/fileOperation';
68
- import { dataURLtoFile, setPositionLocal, getPositionLocal, setPositionDom, setPositionDeviation, useInitSetPostion, htmlToPdfUseCanvas, } from './handle';
68
+ import { dataURLtoFile, setPositionLocal, getPositionLocal, setPositionDom, setPositionDeviation, useInitSetPostion, } from './handle';
69
69
  import { autoSealThenDownloadFilesHandle } from './service';
70
70
  import { createTask } from './lodop';
71
71
  import { useNeedLodop } from './utils';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkui",
3
- "version": "4.2.13",
3
+ "version": "4.2.14",
4
4
  "private": false,
5
5
  "description": "React components library",
6
6
  "author": "zt-front-end",
@@ -24,7 +24,7 @@
24
24
  "react-infinite-scroll-component": "^6.1.0",
25
25
  "react-resizable": "^3.0.4",
26
26
  "react-to-print": "^2.14.7",
27
- "ztxkutils": "^2.10.17"
27
+ "ztxkutils": "^2.10.18"
28
28
  },
29
29
  "scripts": {
30
30
  "analyze": "source-map-explorer 'dist/static/js/*.js'",
@@ -96,4 +96,4 @@
96
96
  "react-dom": ">=16.9.0",
97
97
  "ztxkutils": ">=2.1.1"
98
98
  }
99
- }
99
+ }