ztxkutils 2.7.16 → 2.7.17

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/print.d.ts CHANGED
@@ -21,17 +21,18 @@ 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, noDownload, }: {
24
+ export declare function htmlToPdf({ pageClassName, dom, pdfName, isShowPage, }: {
25
25
  pageClassName?: string;
26
26
  dom: HTMLElement;
27
27
  pdfName: string;
28
28
  isShowPage?: boolean;
29
- noDownload?: boolean;
29
+ }): Promise<jsPDF>;
30
+ export declare function htmlToPdfForExport({ pageClassName, dom, isShowPage, }: {
31
+ pageClassName?: string;
32
+ dom: HTMLElement;
33
+ isShowPage?: boolean;
30
34
  }): Promise<{
31
- pdf: jsPDF;
32
- pdfBase64: any[];
33
- }> | Promise<{
34
- pdf: jsPDF;
35
- pdfBase64: string;
35
+ pdfs: any;
36
+ pdfBase64: any;
36
37
  }>;
37
38
  export {};
package/dist/print.js CHANGED
@@ -102,13 +102,12 @@ function createPdf(canvas, pdf) {
102
102
  }
103
103
  }
104
104
  function htmlToPdf(_a) {
105
- var pageClassName = _a.pageClassName, dom = _a.dom, pdfName = _a.pdfName, isShowPage = _a.isShowPage, noDownload = _a.noDownload;
105
+ var pageClassName = _a.pageClassName, dom = _a.dom, pdfName = _a.pdfName, isShowPage = _a.isShowPage;
106
106
  var pdf = new jsPDF(undefined, 'pt', 'a4');
107
107
  var allDom = document.querySelectorAll(pageClassName ? pageClassName : '.html2canvas-container-page');
108
108
  if (allDom.length > 0 && isShowPage) {
109
109
  var allDomArray = Array.prototype.slice.call(allDom);
110
110
  var promiseAllDomArray_1 = allDomArray.map(function (dom) { return html2canvas(dom); });
111
- var pdfBase64_1 = [];
112
111
  return (function () {
113
112
  return __awaiter(this, void 0, void 0, function () {
114
113
  var i, _i, promiseAllDomArray_2, item, canvas;
@@ -129,19 +128,13 @@ function htmlToPdf(_a) {
129
128
  if (i < promiseAllDomArray_1.length) {
130
129
  pdf.addPage();
131
130
  }
132
- pdfBase64_1.push(pdf.output('dataurlstring'));
133
131
  _a.label = 3;
134
132
  case 3:
135
133
  _i++;
136
134
  return [3 /*break*/, 1];
137
135
  case 4:
138
- if (!noDownload) {
139
- pdf.save(pdfName + ".pdf");
140
- }
141
- return [2 /*return*/, Promise.resolve({
142
- pdf: pdf,
143
- pdfBase64: pdfBase64_1,
144
- })];
136
+ pdf.save(pdfName + ".pdf");
137
+ return [2 /*return*/, Promise.resolve(pdf)];
145
138
  }
146
139
  });
147
140
  });
@@ -150,15 +143,65 @@ function htmlToPdf(_a) {
150
143
  else {
151
144
  return html2canvas(dom).then(function (canvas) {
152
145
  createPdf(canvas, pdf);
153
- if (!noDownload) {
154
- pdf.save(pdfName + ".pdf");
155
- }
146
+ pdf.save(pdfName + ".pdf");
147
+ return pdf;
148
+ });
149
+ }
150
+ }
151
+ // html转pdf,为了上传用
152
+ function htmlToPdfForExport(_a) {
153
+ var pageClassName = _a.pageClassName, dom = _a.dom, isShowPage = _a.isShowPage;
154
+ // 看是否需要分页
155
+ var allDom = document.querySelectorAll(pageClassName ? pageClassName : '.html2canvas-container-page');
156
+ // 如果需要分页
157
+ if (allDom.length > 0 && isShowPage) {
158
+ // 类数组转为数组
159
+ var allDomArray = Array.prototype.slice.call(allDom);
160
+ // 每个dom添加canvas处理
161
+ var promiseAllDomArray_3 = allDomArray.map(function (dom) { return html2canvas(dom); });
162
+ var pdfBase64_1 = [];
163
+ var pdfs_1 = [];
164
+ return (function () {
165
+ return __awaiter(this, void 0, void 0, function () {
166
+ var _i, promiseAllDomArray_4, item, pdf, canvas;
167
+ return __generator(this, function (_a) {
168
+ switch (_a.label) {
169
+ case 0:
170
+ _i = 0, promiseAllDomArray_4 = promiseAllDomArray_3;
171
+ _a.label = 1;
172
+ case 1:
173
+ if (!(_i < promiseAllDomArray_4.length)) return [3 /*break*/, 4];
174
+ item = promiseAllDomArray_4[_i];
175
+ pdf = new jsPDF(undefined, 'pt', 'a4');
176
+ return [4 /*yield*/, item];
177
+ case 2:
178
+ canvas = _a.sent();
179
+ createPdf(canvas, pdf);
180
+ pdfBase64_1.push(pdf.output('dataurlstring'));
181
+ pdfs_1.push(pdf);
182
+ _a.label = 3;
183
+ case 3:
184
+ _i++;
185
+ return [3 /*break*/, 1];
186
+ case 4: return [2 /*return*/, Promise.resolve({
187
+ pdfs: pdfs_1,
188
+ pdfBase64: pdfBase64_1,
189
+ })];
190
+ }
191
+ });
192
+ });
193
+ })();
194
+ }
195
+ else {
196
+ var pdf_1 = new jsPDF(undefined, 'pt', 'a4');
197
+ return html2canvas(dom).then(function (canvas) {
198
+ createPdf(canvas, pdf_1);
156
199
  return {
157
- pdf: pdf,
158
- pdfBase64: pdf.output('dataurlstring'),
200
+ pdfs: [pdf_1],
201
+ pdfBase64: [pdf_1.output('dataurlstring')],
159
202
  };
160
203
  });
161
204
  }
162
205
  }
163
206
 
164
- export { addWaterHandle, htmlToPdf, printCurrentDom, removeWaterHandle };
207
+ export { addWaterHandle, htmlToPdf, htmlToPdfForExport, printCurrentDom, removeWaterHandle };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkutils",
3
- "version": "2.7.16",
3
+ "version": "2.7.17",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",