ztxkutils 2.10.27 → 2.10.29

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-e6bde99f.js';
2
2
  export { d as dataModel } from './dataModel-1fbaff40.js';
3
3
  export { t as tools } from './tools-09a4d620.js';
4
4
  export { v as validate } from './validate-6e735536.js';
5
- export { r as request } from './request-c1ed2e36.js';
5
+ export { r as request } from './request-944adae3.js';
6
6
  export { r as reqUrl } from './reqUrl-787dd9e5.js';
7
7
  import './tslib.es6-35653116.js';
8
8
  import 'dayjs';
package/dist/print.d.ts CHANGED
@@ -21,7 +21,7 @@ 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, noWater, pdfOptions, imgPositionX, }: {
24
+ export declare function htmlToPdf({ pageClassName, dom, pdfName, isShowPage, noWater, pdfOptions, imgPositionX, waterText, }: {
25
25
  pageClassName?: string;
26
26
  dom: HTMLElement;
27
27
  pdfName: string;
@@ -29,12 +29,14 @@ export declare function htmlToPdf({ pageClassName, dom, pdfName, isShowPage, noW
29
29
  noWater?: boolean;
30
30
  pdfOptions?: any;
31
31
  imgPositionX?: number;
32
+ waterText?: string;
32
33
  }): Promise<jsPDF>;
33
- export declare function htmlToPdfUseCanvas({ pageClassName, dom, pdfName, isShowPage, noWater, pdfOptions, imgPositionX, isDownload, }: {
34
+ export declare function htmlToPdfUseCanvas({ pageClassName, dom, pdfName, isShowPage, isOnlyOne, noWater, pdfOptions, imgPositionX, isDownload, }: {
34
35
  pageClassName?: string;
35
36
  dom: HTMLElement;
36
37
  pdfName: string;
37
38
  isShowPage?: boolean;
39
+ isOnlyOne?: boolean;
38
40
  noWater?: boolean;
39
41
  pdfOptions?: any;
40
42
  imgPositionX?: number;
@@ -55,7 +57,7 @@ export interface IPdfOption {
55
57
  /** 上下边距 */
56
58
  pageMarginY?: number;
57
59
  }
58
- export declare function htmlToPdfNoCanvas({ pageClassName, dom, isShowPage, fileBinary, pdfName, isDownload, pdfOption, isAddWater, waterBase64, imgWidth, imgHeight, isCompress, }: {
60
+ export declare function htmlToPdfNoCanvas({ pageClassName, dom, isShowPage, fileBinary, pdfName, isDownload, pdfOption, isAddWater, waterBase64, imgWidth, imgHeight, isCompress, waterText, }: {
59
61
  pageClassName?: string;
60
62
  dom: HTMLElement;
61
63
  isShowPage?: boolean;
@@ -70,5 +72,6 @@ export declare function htmlToPdfNoCanvas({ pageClassName, dom, isShowPage, file
70
72
  imgWidth?: number;
71
73
  imgHeight?: number;
72
74
  isCompress?: boolean;
75
+ waterText?: string;
73
76
  }): Promise<unknown>;
74
77
  export {};
package/dist/print.js CHANGED
@@ -16,7 +16,7 @@ function addWaterHandle(_a) {
16
16
  }
17
17
  var canvasImg = createWaterHandle({
18
18
  waterText: waterText,
19
- });
19
+ }).imgBase64;
20
20
  var styleDom = document.createElement('style');
21
21
  styleDom.setAttribute('type', 'text/css');
22
22
  styleDom.setAttribute('id', 'water-style-dom-110011');
@@ -77,8 +77,18 @@ function createWaterHandle(obj) {
77
77
  var defaultWaterText = '浙商中拓';
78
78
  var _a = obj || {}, waterText = _a.waterText, opacity = _a.opacity, fontSize = _a.fontSize, cavansWidth = _a.cavansWidth, cavansHeight = _a.cavansHeight;
79
79
  var canvas = document.createElement('canvas');
80
- canvas.width = cavansWidth || 240;
81
- canvas.height = cavansHeight || 100;
80
+ var defaultCanvasWidth = waterText
81
+ ? waterText.length > 10
82
+ ? waterText.length * 22
83
+ : 240
84
+ : 240;
85
+ var defaultCanvasHeight = waterText
86
+ ? waterText.length > 10
87
+ ? waterText.length * 9
88
+ : 100
89
+ : 100;
90
+ canvas.width = cavansWidth || defaultCanvasWidth;
91
+ canvas.height = cavansHeight || defaultCanvasHeight;
82
92
  var ctx = canvas.getContext('2d');
83
93
  if (ctx) {
84
94
  ctx.rotate((-10 * Math.PI) / 180); // 水印旋转角度
@@ -88,12 +98,22 @@ function createWaterHandle(obj) {
88
98
  ctx.textBaseline = 'middle';
89
99
  ctx.fillText(waterText || defaultWaterText, canvas.width / 2, canvas.height); // 水印在画布的位置x,y轴
90
100
  }
91
- return canvas.toDataURL('image/png');
101
+ return {
102
+ imgBase64: canvas.toDataURL('image/png'),
103
+ width: canvas.width,
104
+ height: canvas.height,
105
+ };
92
106
  }
93
- function addPdfWaterHandle(pdf, waterBase64) {
107
+ function addPdfWaterHandle(pdf, waterBase64, imgInfo) {
108
+ var width = 200;
109
+ var height = 80;
110
+ if (imgInfo) {
111
+ width = imgInfo === null || imgInfo === void 0 ? void 0 : imgInfo.width;
112
+ height = imgInfo === null || imgInfo === void 0 ? void 0 : imgInfo.height;
113
+ }
94
114
  for (var i = 0; i < 10; i++) {
95
- pdf.addImage(waterBase64, 'PNG', 40, 140 * i, 200, 80, "1" + i);
96
- pdf.addImage(waterBase64, 'PNG', 280, 140 * i, 200, 80, "2" + i);
115
+ pdf.addImage(waterBase64, 'PNG', 40, 140 * i, width, height, "1" + i);
116
+ pdf.addImage(waterBase64, 'PNG', 80 + width, 140 * i, width, height, "2" + i);
97
117
  }
98
118
  }
99
119
  /**
@@ -122,22 +142,24 @@ function createPdf(canvas, pdf, noWater, positionX, options) {
122
142
  if (leftHeight < pageHeight) {
123
143
  pdf.addImage(pageData, 'JPEG', positionX || 20, 10, imgWidth, imgHeight);
124
144
  if (!noWater) {
125
- var waterBase64 = createWaterHandle({
145
+ var _a = createWaterHandle({
126
146
  opacity: '0.07',
127
147
  fontSize: '14px',
128
- });
129
- addPdfWaterHandle(pdf, waterBase64);
148
+ waterText: (options === null || options === void 0 ? void 0 : options.waterText) || '',
149
+ }), waterBase64 = _a.imgBase64, width = _a.width, height = _a.height;
150
+ addPdfWaterHandle(pdf, waterBase64, { width: width, height: height });
130
151
  }
131
152
  }
132
153
  else {
133
154
  while (leftHeight > 0) {
134
155
  pdf.addImage(pageData, 'JPEG', positionX || 20, position, imgWidth, imgHeight);
135
156
  if (!noWater) {
136
- var waterBase64 = createWaterHandle({
157
+ var _b = createWaterHandle({
137
158
  opacity: '0.07',
138
159
  fontSize: '14px',
139
- });
140
- addPdfWaterHandle(pdf, waterBase64);
160
+ waterText: (options === null || options === void 0 ? void 0 : options.waterText) || '',
161
+ }), waterBase64 = _b.imgBase64, width = _b.width, height = _b.height;
162
+ addPdfWaterHandle(pdf, waterBase64, { width: width, height: height });
141
163
  }
142
164
  leftHeight -= pageHeight;
143
165
  // position -= 841.89;
@@ -150,7 +172,7 @@ function createPdf(canvas, pdf, noWater, positionX, options) {
150
172
  }
151
173
  }
152
174
  function htmlToPdf(_a) {
153
- var pageClassName = _a.pageClassName, dom = _a.dom, pdfName = _a.pdfName, isShowPage = _a.isShowPage, noWater = _a.noWater, pdfOptions = _a.pdfOptions, imgPositionX = _a.imgPositionX;
175
+ var pageClassName = _a.pageClassName, dom = _a.dom, pdfName = _a.pdfName, isShowPage = _a.isShowPage, noWater = _a.noWater, pdfOptions = _a.pdfOptions, imgPositionX = _a.imgPositionX, waterText = _a.waterText;
154
176
  var allDom = document.querySelectorAll(pageClassName ? pageClassName : '.html2canvas-container-page');
155
177
  var format = (pdfOptions === null || pdfOptions === void 0 ? void 0 : pdfOptions.format) || [632.28, 841.89];
156
178
  var pdf = new jsPDF(__assign({ unit: 'pt', format: format }, (pdfOptions || {})));
@@ -180,6 +202,7 @@ function htmlToPdf(_a) {
180
202
  createPdf(canvas, pdf, noWater, imgPositionX, {
181
203
  width: format === null || format === void 0 ? void 0 : format[0],
182
204
  height: format === null || format === void 0 ? void 0 : format[1],
205
+ waterText: waterText,
183
206
  });
184
207
  if (i < promiseAllDomArray_1.length) {
185
208
  pdf.addPage();
@@ -201,6 +224,7 @@ function htmlToPdf(_a) {
201
224
  createPdf(canvas, pdf, noWater, imgPositionX, {
202
225
  width: format === null || format === void 0 ? void 0 : format[0],
203
226
  height: format === null || format === void 0 ? void 0 : format[1],
227
+ waterText: waterText,
204
228
  });
205
229
  pdf.save(pdfName + ".pdf");
206
230
  return pdf;
@@ -208,7 +232,7 @@ function htmlToPdf(_a) {
208
232
  }
209
233
  }
210
234
  function htmlToPdfUseCanvas(_a) {
211
- 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;
235
+ var pageClassName = _a.pageClassName, dom = _a.dom, pdfName = _a.pdfName, isShowPage = _a.isShowPage, isOnlyOne = _a.isOnlyOne, noWater = _a.noWater, pdfOptions = _a.pdfOptions, imgPositionX = _a.imgPositionX, isDownload = _a.isDownload;
212
236
  var allDom = document.querySelectorAll(pageClassName ? pageClassName : '.html2canvas-container-page');
213
237
  var format = (pdfOptions === null || pdfOptions === void 0 ? void 0 : pdfOptions.format) || [632.28, 841.89];
214
238
  var _pdfOptions = __assign({ unit: 'pt', format: format }, (pdfOptions || {}));
@@ -221,17 +245,59 @@ function htmlToPdfUseCanvas(_a) {
221
245
  scale: 2,
222
246
  });
223
247
  });
248
+ if (isOnlyOne) {
249
+ var pdf_1 = new jsPDF(_pdfOptions);
250
+ return (function () {
251
+ return __awaiter(this, void 0, void 0, function () {
252
+ var i, _i, promiseAllDomArray_4, item, canvas;
253
+ return __generator(this, function (_a) {
254
+ switch (_a.label) {
255
+ case 0:
256
+ i = 0;
257
+ _i = 0, promiseAllDomArray_4 = promiseAllDomArray_3;
258
+ _a.label = 1;
259
+ case 1:
260
+ if (!(_i < promiseAllDomArray_4.length)) return [3 /*break*/, 4];
261
+ item = promiseAllDomArray_4[_i];
262
+ i++;
263
+ return [4 /*yield*/, item];
264
+ case 2:
265
+ canvas = _a.sent();
266
+ createPdf(canvas, pdf_1, noWater, imgPositionX, {
267
+ width: format === null || format === void 0 ? void 0 : format[0],
268
+ height: format === null || format === void 0 ? void 0 : format[1],
269
+ });
270
+ if (i < promiseAllDomArray_3.length) {
271
+ pdf_1.addPage();
272
+ }
273
+ _a.label = 3;
274
+ case 3:
275
+ _i++;
276
+ return [3 /*break*/, 1];
277
+ case 4:
278
+ if (isDownload) {
279
+ pdf_1.save(pdfName + ".pdf");
280
+ }
281
+ return [2 /*return*/, Promise.resolve({
282
+ pdfs: [pdf_1],
283
+ pdfBase64: [pdf_1.output('dataurlstring')],
284
+ })];
285
+ }
286
+ });
287
+ });
288
+ })();
289
+ }
224
290
  return (function () {
225
291
  return __awaiter(this, void 0, void 0, function () {
226
- var _i, promiseAllDomArray_4, item, pdf, canvas;
292
+ var _i, promiseAllDomArray_5, item, pdf, canvas;
227
293
  return __generator(this, function (_a) {
228
294
  switch (_a.label) {
229
295
  case 0:
230
- _i = 0, promiseAllDomArray_4 = promiseAllDomArray_3;
296
+ _i = 0, promiseAllDomArray_5 = promiseAllDomArray_3;
231
297
  _a.label = 1;
232
298
  case 1:
233
- if (!(_i < promiseAllDomArray_4.length)) return [3 /*break*/, 4];
234
- item = promiseAllDomArray_4[_i];
299
+ if (!(_i < promiseAllDomArray_5.length)) return [3 /*break*/, 4];
300
+ item = promiseAllDomArray_5[_i];
235
301
  pdf = new jsPDF(_pdfOptions);
236
302
  return [4 /*yield*/, item];
237
303
  case 2:
@@ -259,27 +325,27 @@ function htmlToPdfUseCanvas(_a) {
259
325
  })();
260
326
  }
261
327
  else {
262
- var pdf_1 = new jsPDF(_pdfOptions);
328
+ var pdf_2 = new jsPDF(_pdfOptions);
263
329
  return html2canvas(dom, { scale: 2 }).then(function (canvas) {
264
- createPdf(canvas, pdf_1, noWater, imgPositionX, {
330
+ createPdf(canvas, pdf_2, noWater, imgPositionX, {
265
331
  width: format === null || format === void 0 ? void 0 : format[0],
266
332
  height: format === null || format === void 0 ? void 0 : format[1],
267
333
  });
268
334
  if (isDownload) {
269
- pdf_1.save(pdfName + ".pdf");
335
+ pdf_2.save(pdfName + ".pdf");
270
336
  }
271
337
  return {
272
- pdfs: [pdf_1],
273
- pdfBase64: [pdf_1.output('dataurlstring')],
338
+ pdfs: [pdf_2],
339
+ pdfBase64: [pdf_2.output('dataurlstring')],
274
340
  };
275
341
  });
276
342
  }
277
343
  }
278
344
  function htmlToPdfNoCanvas(_a) {
279
345
  var _b, _c;
280
- var pageClassName = _a.pageClassName, dom = _a.dom, isShowPage = _a.isShowPage, fileBinary = _a.fileBinary, pdfName = _a.pdfName, isDownload = _a.isDownload, pdfOption = _a.pdfOption, isAddWater = _a.isAddWater, waterBase64 = _a.waterBase64, imgWidth = _a.imgWidth, imgHeight = _a.imgHeight, isCompress = _a.isCompress;
346
+ var pageClassName = _a.pageClassName, dom = _a.dom, isShowPage = _a.isShowPage, fileBinary = _a.fileBinary, pdfName = _a.pdfName, isDownload = _a.isDownload, pdfOption = _a.pdfOption, isAddWater = _a.isAddWater, waterBase64 = _a.waterBase64, imgWidth = _a.imgWidth, imgHeight = _a.imgHeight, isCompress = _a.isCompress; _a.waterText;
281
347
  return __awaiter(this, void 0, void 0, function () {
282
- var allDom, pageFormat, pageOrient, pageMarginX, pageMarginY, pdfOptions, allDomArray_1, pdfBase64_2, pdfs_2, pdf_2, pageWidth_1;
348
+ var allDom, pageFormat, pageOrient, pageMarginX, pageMarginY, pdfOptions, allDomArray_1, pdfBase64_2, pdfs_2, pdf_3, pageWidth_1;
283
349
  return __generator(this, function (_d) {
284
350
  allDom = dom.querySelectorAll(pageClassName ? pageClassName : '.html2canvas-container-page');
285
351
  pageFormat = (pdfOption === null || pdfOption === void 0 ? void 0 : pdfOption.pageFormat) ? pdfOption.pageFormat : 'a4';
@@ -384,10 +450,10 @@ function htmlToPdfNoCanvas(_a) {
384
450
  })()];
385
451
  }
386
452
  else {
387
- pdf_2 = new jsPDF(pdfOptions);
388
- pageWidth_1 = pdf_2.internal.pageSize.width - pageMarginX * 2;
389
- setPdfVersion(pdf_2);
390
- supportJsPdfChinese(pdf_2, fileBinary);
453
+ pdf_3 = new jsPDF(pdfOptions);
454
+ pageWidth_1 = pdf_3.internal.pageSize.width - pageMarginX * 2;
455
+ setPdfVersion(pdf_3);
456
+ supportJsPdfChinese(pdf_3, fileBinary);
391
457
  return [2 /*return*/, new Promise(function (resolve) {
392
458
  new jsPDF(pdfOptions).html(dom, {
393
459
  autoPaging: 'text',
@@ -397,28 +463,28 @@ function htmlToPdfNoCanvas(_a) {
397
463
  callback: function (res) {
398
464
  // 添加呈现的HTML所需的页面(从第2页开始)
399
465
  for (var i = 2, j = res.internal.getNumberOfPages(); i <= j; i++) {
400
- pdf_2.addPage(pageFormat, pageOrient);
466
+ pdf_3.addPage(pageFormat, pageOrient);
401
467
  }
402
468
  // 正确呈现文档
403
- pdf_2.html(dom, {
469
+ pdf_3.html(dom, {
404
470
  autoPaging: 'text',
405
471
  margin: [pageMarginY, pageMarginX, pageMarginY, pageMarginX],
406
472
  width: pageWidth_1,
407
473
  windowWidth: pageWidth_1,
408
474
  callback: function () {
409
475
  for (var i = 1, j = res.internal.getNumberOfPages(); i <= j; i++) {
410
- pdf_2.setPage(i);
476
+ pdf_3.setPage(i);
411
477
  // 添加水印
412
478
  if (isAddWater) {
413
- setPdfWater(pdf_2, waterBase64, imgWidth, imgHeight);
479
+ setPdfWater(pdf_3, waterBase64, imgWidth, imgHeight);
414
480
  }
415
481
  }
416
482
  if (isDownload) {
417
- pdf_2.save(pdfName + ".pdf");
483
+ pdf_3.save(pdfName + ".pdf");
418
484
  }
419
485
  resolve({
420
- pdfs: [pdf_2],
421
- pdfBase64: [pdf_2.output('dataurlstring')],
486
+ pdfs: [pdf_3],
487
+ pdfBase64: [pdf_3.output('dataurlstring')],
422
488
  });
423
489
  },
424
490
  });