ztxkutils 2.9.14 → 2.10.0

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.
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ export { c as authority } from './authority-118dc4b1.js';
2
2
  export { d as dataModel } from './dataModel-1fbaff40.js';
3
3
  export { t as tools } from './tools-1e6fe951.js';
4
4
  export { v as validate } from './validate-3e15dd74.js';
5
- export { r as request } from './request-c3ba0965.js';
5
+ export { r as request } from './request-f89650d7.js';
6
6
  export { r as reqUrl } from './reqUrl-4700395b.js';
7
7
  import './tslib.es6-f9459658.js';
8
8
  import 'dayjs';
package/dist/print.d.ts CHANGED
@@ -21,11 +21,12 @@ interface IParams {
21
21
  hiddenClassNames?: string[];
22
22
  }
23
23
  export declare function printCurrentDom({ hiddenClassNames }?: IParams): void;
24
- export declare function htmlToPdf({ pageClassName, dom, pdfName, isShowPage, }: {
24
+ export declare function htmlToPdf({ pageClassName, dom, pdfName, isShowPage, noWater, }: {
25
25
  pageClassName?: string;
26
26
  dom: HTMLElement;
27
27
  pdfName: string;
28
28
  isShowPage?: boolean;
29
+ noWater?: boolean;
29
30
  }): Promise<jsPDF>;
30
31
  export interface IPdfOption {
31
32
  /** 是否压缩 */
package/dist/print.js CHANGED
@@ -76,10 +76,10 @@ function createWaterHandle(obj) {
76
76
  console.log(err);
77
77
  }
78
78
  }
79
- var _a = obj || {}, waterText = _a.waterText, opacity = _a.opacity, fontSize = _a.fontSize;
79
+ var _a = obj || {}, waterText = _a.waterText, opacity = _a.opacity, fontSize = _a.fontSize, cavansWidth = _a.cavansWidth, cavansHeight = _a.cavansHeight;
80
80
  var canvas = document.createElement('canvas');
81
- canvas.width = 200;
82
- canvas.height = 80;
81
+ canvas.width = cavansWidth || 200;
82
+ canvas.height = cavansHeight || 80;
83
83
  var ctx = canvas.getContext('2d');
84
84
  if (ctx) {
85
85
  ctx.rotate((-10 * Math.PI) / 180); // 水印旋转角度
@@ -93,15 +93,14 @@ function createWaterHandle(obj) {
93
93
  }
94
94
  function addPdfWaterHandle(pdf, waterBase64) {
95
95
  for (var i = 0; i < 10; i++) {
96
- pdf.addImage(waterBase64, 'PNG', 0, 80 * i, 200, 80, "1" + i);
97
- pdf.addImage(waterBase64, 'PNG', 200, 80 * i, 200, 80, "2" + i);
98
- pdf.addImage(waterBase64, 'PNG', 400, 80 * i, 200, 80, "3" + i);
96
+ pdf.addImage(waterBase64, 'PNG', 40, 140 * i, 200, 80, "1" + i);
97
+ pdf.addImage(waterBase64, 'PNG', 280, 140 * i, 200, 80, "2" + i);
99
98
  }
100
99
  }
101
100
  /**
102
101
  * html转pdf
103
102
  */
104
- function createPdf(canvas, pdf) {
103
+ function createPdf(canvas, pdf, noWater) {
105
104
  var contentWidth = canvas.width;
106
105
  var contentHeight = canvas.height;
107
106
  // 一页pdf显示html页面生成的canvas高度
@@ -117,21 +116,25 @@ function createPdf(canvas, pdf) {
117
116
  //有两个高度需要区分,一个是html页面的实际高度,和生成pdf的页面高度(841.89)
118
117
  //当内容未超过pdf一页显示的范围,无需分页
119
118
  if (leftHeight < pageHeight) {
120
- pdf.addImage(pageData, 'JPEG', 0, 0, imgWidth, imgHeight);
121
- var waterBase64 = createWaterHandle({
122
- opacity: '0.5',
123
- fontSize: '15px',
124
- });
125
- addPdfWaterHandle(pdf, waterBase64);
126
- }
127
- else {
128
- while (leftHeight > 0) {
129
- pdf.addImage(pageData, 'JPEG', 0, position, imgWidth, imgHeight);
119
+ pdf.addImage(pageData, 'JPEG', 20, 10, imgWidth, imgHeight);
120
+ if (!noWater) {
130
121
  var waterBase64 = createWaterHandle({
131
- opacity: '0.5',
132
- fontSize: '15px',
122
+ opacity: '0.2',
123
+ fontSize: '14px',
133
124
  });
134
125
  addPdfWaterHandle(pdf, waterBase64);
126
+ }
127
+ }
128
+ else {
129
+ while (leftHeight > 0) {
130
+ pdf.addImage(pageData, 'JPEG', 20, position, imgWidth, imgHeight);
131
+ if (!noWater) {
132
+ var waterBase64 = createWaterHandle({
133
+ opacity: '0.2',
134
+ fontSize: '14px',
135
+ });
136
+ addPdfWaterHandle(pdf, waterBase64);
137
+ }
135
138
  leftHeight -= pageHeight;
136
139
  position -= 841.89;
137
140
  //避免添加空白页
@@ -142,9 +145,12 @@ function createPdf(canvas, pdf) {
142
145
  }
143
146
  }
144
147
  function htmlToPdf(_a) {
145
- var pageClassName = _a.pageClassName, dom = _a.dom, pdfName = _a.pdfName, isShowPage = _a.isShowPage;
146
- var pdf = new jsPDF(undefined, 'pt', 'a4');
148
+ var pageClassName = _a.pageClassName, dom = _a.dom, pdfName = _a.pdfName, isShowPage = _a.isShowPage, noWater = _a.noWater;
147
149
  var allDom = document.querySelectorAll(pageClassName ? pageClassName : '.html2canvas-container-page');
150
+ var pdf = new jsPDF({
151
+ unit: 'pt',
152
+ format: [632.28, 841.89],
153
+ });
148
154
  if (allDom.length > 0 && isShowPage) {
149
155
  var allDomArray = Array.prototype.slice.call(allDom);
150
156
  var promiseAllDomArray_1 = allDomArray.map(function (dom) {
@@ -168,7 +174,7 @@ function htmlToPdf(_a) {
168
174
  return [4 /*yield*/, item];
169
175
  case 2:
170
176
  canvas = _a.sent();
171
- createPdf(canvas, pdf);
177
+ createPdf(canvas, pdf, noWater);
172
178
  if (i < promiseAllDomArray_1.length) {
173
179
  pdf.addPage();
174
180
  }
@@ -186,7 +192,7 @@ function htmlToPdf(_a) {
186
192
  }
187
193
  else {
188
194
  return html2canvas(dom, { scale: 2 }).then(function (canvas) {
189
- createPdf(canvas, pdf);
195
+ createPdf(canvas, pdf, noWater);
190
196
  pdf.save(pdfName + ".pdf");
191
197
  return pdf;
192
198
  });