ztxkutils 2.7.14 → 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
@@ -1,3 +1,8 @@
1
+ /**
2
+ * @author 陈亚雄
3
+ * @description 打印相关方法
4
+ */
5
+ import { jsPDF } from 'jspdf';
1
6
  /**
2
7
  * 添加水印
3
8
  */
@@ -21,5 +26,13 @@ export declare function htmlToPdf({ pageClassName, dom, pdfName, isShowPage, }:
21
26
  dom: HTMLElement;
22
27
  pdfName: string;
23
28
  isShowPage?: boolean;
24
- }): Promise<void>;
29
+ }): Promise<jsPDF>;
30
+ export declare function htmlToPdfForExport({ pageClassName, dom, isShowPage, }: {
31
+ pageClassName?: string;
32
+ dom: HTMLElement;
33
+ isShowPage?: boolean;
34
+ }): Promise<{
35
+ pdfs: any;
36
+ pdfBase64: any;
37
+ }>;
25
38
  export {};
package/dist/print.js CHANGED
@@ -134,7 +134,7 @@ function htmlToPdf(_a) {
134
134
  return [3 /*break*/, 1];
135
135
  case 4:
136
136
  pdf.save(pdfName + ".pdf");
137
- return [2 /*return*/, Promise.resolve()];
137
+ return [2 /*return*/, Promise.resolve(pdf)];
138
138
  }
139
139
  });
140
140
  });
@@ -144,8 +144,64 @@ function htmlToPdf(_a) {
144
144
  return html2canvas(dom).then(function (canvas) {
145
145
  createPdf(canvas, pdf);
146
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);
199
+ return {
200
+ pdfs: [pdf_1],
201
+ pdfBase64: [pdf_1.output('dataurlstring')],
202
+ };
147
203
  });
148
204
  }
149
205
  }
150
206
 
151
- 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.14",
3
+ "version": "2.7.17",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",