ztxkui 4.2.23-335-beta → 4.2.23-336-beta

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.
@@ -143,10 +143,10 @@ var PrintContainerDemo = function () {
143
143
  // deptId="1295909543961944065"
144
144
  // flowId="scm_print_tdtd"
145
145
  // showAboutExport
146
- showPrintBtn: true, showPluginPrintBtn: true }, Array(50)
146
+ showPrintBtn: true, showPluginPrintBtn: true }, Array(2)
147
147
  .fill(1)
148
148
  .map(function (item, index) {
149
- return (React.createElement(React.Fragment, null,
149
+ return (React.createElement("div", null,
150
150
  React.createElement(Tidan, { title: index + '', key: index }),
151
151
  React.createElement("div", { className: "print-page-break-after" })));
152
152
  })));
@@ -111,7 +111,7 @@ var Demo = function () {
111
111
  orientation: 'p',
112
112
  },
113
113
  footerFontConfig: {
114
- fontSize: '12px',
114
+ fontSize: 12,
115
115
  },
116
116
  }))];
117
117
  case 1:
@@ -167,7 +167,7 @@ var Demo = function () {
167
167
  }, onExecuteClick: function (type, data) {
168
168
  console.log('操作执行完成后', type, data);
169
169
  return Promise.resolve(true);
170
- }, ref: printRef, isAutoSeal: true, request: request, deptId: "1514842459376930817", flowId: "scm_print_thd",
170
+ }, ref: printRef, isAutoSeal: true, isWater: false, request: request, deptId: "1514842459376930817", flowId: "scm_print_thd",
171
171
  // pageDom=".html2canvas-container-page"
172
172
  pageDom: ".test111", leftPadding: 50, topPadding: 50, bottomPadding: 50,
173
173
  // insertHeader={(pdf, currentPage) => `1111 ${currentPage}`}
@@ -47,7 +47,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
47
47
  };
48
48
  import { jsPDF } from 'jspdf';
49
49
  import dayjs from 'dayjs';
50
- import { textToImg } from './water';
50
+ import { textToDomToImg } from './water';
51
51
  /**
52
52
  * 图片转PDF
53
53
  */
@@ -197,79 +197,94 @@ export function insertImgToPdf(pdf, pdfWidth, pdfHeight, config) {
197
197
  return __awaiter(this, void 0, void 0, function () {
198
198
  var imageConfig, _d, leftPadding, _e, topPadding, _f, bottomPadding, insertHeader, _g, headerTopMargin, insertFooter, _h, footerTopMargin, waterConfig, _j, footerFontConfig, _k, headerFontConfig, image, width, height, canvasWidth, canvasHeight, contentPdfWidth, contentPdfHeight, onePageCanvasHeight, renderedHeight, imageCtx, count, pageNum, pageCanvasDom, currentPageContentHeight, cropOriginalImageData, result, _l, imageBase64, width_1, height_1, insertPdfHeight, result, _m, imageBase64, width_2, height_2;
199
199
  return __generator(this, function (_o) {
200
- imageConfig = config.imageConfig, _d = config.leftPadding, leftPadding = _d === void 0 ? 15 : _d, _e = config.topPadding, topPadding = _e === void 0 ? 0 : _e, _f = config.bottomPadding, bottomPadding = _f === void 0 ? 0 : _f, insertHeader = config.insertHeader, _g = config.headerTopMargin, headerTopMargin = _g === void 0 ? 20 : _g, insertFooter = config.insertFooter, _h = config.footerTopMargin, footerTopMargin = _h === void 0 ? 20 : _h, waterConfig = config.waterConfig, _j = config.footerFontConfig, footerFontConfig = _j === void 0 ? { fontSize: 13 } : _j, _k = config.headerFontConfig, headerFontConfig = _k === void 0 ? { fontSize: 13 } : _k;
201
- image = imageConfig.image, width = imageConfig.width, height = imageConfig.height;
202
- canvasWidth = width;
203
- canvasHeight = height;
204
- contentPdfWidth = pdfWidth - leftPadding * 2;
205
- contentPdfHeight = pdfHeight - topPadding - bottomPadding;
206
- onePageCanvasHeight = Math.floor(contentPdfHeight * (canvasWidth / contentPdfWidth));
207
- renderedHeight = 0;
208
- imageCtx = (_a = image) === null || _a === void 0 ? void 0 : _a.getContext('2d');
209
- count = Math.ceil(canvasHeight / onePageCanvasHeight);
210
- pageNum = 1;
211
- while (renderedHeight < canvasHeight) {
212
- pageCanvasDom = document.createElement('canvas');
213
- // 新创建的canvas中间者 的 宽度即是原图的宽度
214
- pageCanvasDom.width = canvasWidth;
215
- currentPageContentHeight = Math.min(onePageCanvasHeight, canvasHeight - renderedHeight);
216
- pageCanvasDom.height = currentPageContentHeight;
217
- cropOriginalImageData = imageCtx === null || imageCtx === void 0 ? void 0 : imageCtx.getImageData(0, // 开始复制的x坐标
218
- renderedHeight, // 开始复制的y坐标
219
- canvasWidth, // 复制的矩形区域的宽度
220
- currentPageContentHeight // 复制的矩形区域的高度
221
- );
222
- // 2. 将裁剪好的图片 通过putImageData 绘制到 中间者 canvas上
223
- (_c = (_b = pageCanvasDom.getContext('2d')) === null || _b === void 0 ? void 0 : _b.putImageData) === null || _c === void 0 ? void 0 : _c.call(_b, cropOriginalImageData, // 插入的图片对象
224
- 0, // 左上角x坐标
225
- 0 // 左上角 y坐标
226
- );
227
- // 这里可以添加页眉 !!!
228
- if (insertHeader) {
200
+ switch (_o.label) {
201
+ case 0:
202
+ imageConfig = config.imageConfig, _d = config.leftPadding, leftPadding = _d === void 0 ? 15 : _d, _e = config.topPadding, topPadding = _e === void 0 ? 0 : _e, _f = config.bottomPadding, bottomPadding = _f === void 0 ? 0 : _f, insertHeader = config.insertHeader, _g = config.headerTopMargin, headerTopMargin = _g === void 0 ? 20 : _g, insertFooter = config.insertFooter, _h = config.footerTopMargin, footerTopMargin = _h === void 0 ? 20 : _h, waterConfig = config.waterConfig, _j = config.footerFontConfig, footerFontConfig = _j === void 0 ? { fontSize: 13 } : _j, _k = config.headerFontConfig, headerFontConfig = _k === void 0 ? { fontSize: 13 } : _k;
203
+ image = imageConfig.image, width = imageConfig.width, height = imageConfig.height;
204
+ canvasWidth = width;
205
+ canvasHeight = height;
206
+ contentPdfWidth = pdfWidth - leftPadding * 2;
207
+ contentPdfHeight = pdfHeight - topPadding - bottomPadding;
208
+ onePageCanvasHeight = Math.floor(contentPdfHeight * (canvasWidth / contentPdfWidth));
209
+ renderedHeight = 0;
210
+ imageCtx = (_a = image) === null || _a === void 0 ? void 0 : _a.getContext('2d');
211
+ count = Math.ceil(canvasHeight / onePageCanvasHeight);
212
+ pageNum = 1;
213
+ _o.label = 1;
214
+ case 1:
215
+ if (!(renderedHeight < canvasHeight)) return [3 /*break*/, 6];
216
+ pageCanvasDom = document.createElement('canvas');
217
+ // 新创建的canvas中间者 宽度即是原图的宽度
218
+ pageCanvasDom.width = canvasWidth;
219
+ currentPageContentHeight = Math.min(onePageCanvasHeight, canvasHeight - renderedHeight);
220
+ pageCanvasDom.height = currentPageContentHeight;
221
+ cropOriginalImageData = imageCtx === null || imageCtx === void 0 ? void 0 : imageCtx.getImageData(0, // 开始复制的x坐标
222
+ renderedHeight, // 开始复制的y坐标
223
+ canvasWidth, // 复制的矩形区域的宽度
224
+ currentPageContentHeight // 复制的矩形区域的高度
225
+ );
226
+ // 2. 将裁剪好的图片 通过putImageData 绘制到 中间者 canvas上
227
+ (_c = (_b = pageCanvasDom.getContext('2d')) === null || _b === void 0 ? void 0 : _b.putImageData) === null || _c === void 0 ? void 0 : _c.call(_b, cropOriginalImageData, // 插入的图片对象
228
+ 0, // 左上角x坐标
229
+ 0 // 左上角 y坐标
230
+ );
231
+ if (!insertHeader) return [3 /*break*/, 3];
229
232
  result = insertHeader(pdf, pageNum, count);
230
- if (typeof result === 'string') {
231
- _l = textToImg({
233
+ if (!(typeof result === 'string')) return [3 /*break*/, 3];
234
+ return [4 /*yield*/, textToDomToImg({
232
235
  text: result,
233
236
  font: headerFontConfig,
234
- }), imageBase64 = _l.imageBase64, width_1 = _l.width, height_1 = _l.height;
235
- pdf.addImage(imageBase64, 'PNG', pdfWidth / 2, headerTopMargin, width_1, height_1);
237
+ })];
238
+ case 2:
239
+ _l = _o.sent(), imageBase64 = _l.imageBase64, width_1 = _l.width, height_1 = _l.height;
240
+ // const { imageBase64, width, height } = textToImg({
241
+ // text: result,
242
+ // font: headerFontConfig,
243
+ // });
244
+ pdf.addImage(imageBase64, 'PNG', pdfWidth / 2, headerTopMargin, width_1, height_1);
245
+ _o.label = 3;
246
+ case 3:
247
+ insertPdfHeight = Math.min(contentPdfHeight, (contentPdfWidth * currentPageContentHeight) / canvasWidth);
248
+ pdf.addImage(pageCanvasDom.toDataURL('image/jpeg', 1.0), 'JPEG', leftPadding, topPadding, contentPdfWidth, insertPdfHeight);
249
+ // 判断是否添加水印
250
+ if (waterConfig) {
251
+ addImageWater(pdf, waterConfig.image, {
252
+ width: waterConfig.width,
253
+ height: waterConfig.height,
254
+ });
236
255
  }
237
- }
238
- insertPdfHeight = Math.min(contentPdfHeight, (contentPdfWidth * currentPageContentHeight) / canvasWidth);
239
- pdf.addImage(pageCanvasDom.toDataURL('image/jpeg', 1.0), 'JPEG', leftPadding, topPadding, contentPdfWidth, insertPdfHeight);
240
- // 判断是否添加水印
241
- if (waterConfig) {
242
- addImageWater(pdf, waterConfig.image, {
243
- width: waterConfig.width,
244
- height: waterConfig.height,
245
- });
246
- }
247
- // 这里可以添加页脚
248
- if (insertFooter) {
256
+ if (!insertFooter) return [3 /*break*/, 5];
249
257
  result = insertFooter(pdf, pageNum, count);
250
- if (typeof result === 'string') {
251
- _m = textToImg({
258
+ if (!(typeof result === 'string')) return [3 /*break*/, 5];
259
+ return [4 /*yield*/, textToDomToImg({
252
260
  text: result,
253
261
  font: footerFontConfig,
254
- }), imageBase64 = _m.imageBase64, width_2 = _m.width, height_2 = _m.height;
255
- pdf.addImage(imageBase64, 'PNG', pdfWidth / 2 - width_2 / 2, contentPdfHeight + topPadding + footerTopMargin, width_2, height_2);
262
+ })];
263
+ case 4:
264
+ _m = _o.sent(), imageBase64 = _m.imageBase64, width_2 = _m.width, height_2 = _m.height;
265
+ // const { imageBase64, width, height } = textToImg({
266
+ // text: result,
267
+ // font: footerFontConfig,
268
+ // });
269
+ pdf.addImage(imageBase64, 'PNG', pdfWidth / 2 - width_2 / 2, contentPdfHeight + topPadding + footerTopMargin, width_2, height_2);
270
+ _o.label = 5;
271
+ case 5:
272
+ // 移动偏移量
273
+ renderedHeight += onePageCanvasHeight;
274
+ // 如果移动完后,原图内容还有的话。那么继续分页
275
+ if (renderedHeight < canvasHeight) {
276
+ pdf.addPage();
277
+ pageNum++;
256
278
  }
257
- }
258
- // 移动偏移量
259
- renderedHeight += onePageCanvasHeight;
260
- // 如果移动完后,原图内容还有的话。那么继续分页
261
- if (renderedHeight < canvasHeight) {
262
- pdf.addPage();
263
- pageNum++;
264
- }
265
- try {
266
- pageCanvasDom = null;
267
- }
268
- catch (err) {
269
- console.log('[ 裁剪过程中遇到异常 err ] =>', err);
270
- }
279
+ try {
280
+ pageCanvasDom = null;
281
+ }
282
+ catch (err) {
283
+ console.log('[ 裁剪过程中遇到异常 err ] =>', err);
284
+ }
285
+ return [3 /*break*/, 1];
286
+ case 6: return [2 /*return*/];
271
287
  }
272
- return [2 /*return*/];
273
288
  });
274
289
  });
275
290
  }
@@ -14,6 +14,14 @@ export declare function textToImg(config: ITextToImg): {
14
14
  width: any;
15
15
  height: any;
16
16
  };
17
+ /**
18
+ * 将文本生成高清canvas图片
19
+ */
20
+ export declare function textToDomToImg(config: ITextToImg): Promise<{
21
+ imageBase64: string;
22
+ width: number;
23
+ height: number;
24
+ }>;
17
25
  /**
18
26
  * 默认配置
19
27
  */
@@ -1,5 +1,42 @@
1
1
  // import dayjs from 'dayjs';
2
2
  // import { parseToken } from './auth';
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ var __generator = (this && this.__generator) || function (thisArg, body) {
13
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
14
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
15
+ function verb(n) { return function (v) { return step([n, v]); }; }
16
+ function step(op) {
17
+ if (f) throw new TypeError("Generator is already executing.");
18
+ while (_) try {
19
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
20
+ if (y = 0, t) op = [op[0] & 2, t.value];
21
+ switch (op[0]) {
22
+ case 0: case 1: t = op; break;
23
+ case 4: _.label++; return { value: op[1], done: false };
24
+ case 5: _.label++; y = op[1]; op = [0]; continue;
25
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
26
+ default:
27
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
28
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
29
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
30
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
31
+ if (t[2]) _.ops.pop();
32
+ _.trys.pop(); continue;
33
+ }
34
+ op = body.call(thisArg, _);
35
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
36
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
37
+ }
38
+ };
39
+ import { domToCanvas } from './canvas';
3
40
  /**
4
41
  * 创建水印
5
42
  */
@@ -55,7 +92,7 @@ export function textToImg(config) {
55
92
  var ctx = canvas.getContext('2d');
56
93
  if (ctx) {
57
94
  // 获取设备像素密度和浏览器绘制比例
58
- var ratio = window.devicePixelRatio || 1 + 0.5;
95
+ var ratio = window.devicePixelRatio || 1 + 1.5;
59
96
  // 设置canvas的逻辑尺寸
60
97
  canvas.width = width * ratio;
61
98
  canvas.height = height * ratio;
@@ -76,6 +113,45 @@ export function textToImg(config) {
76
113
  height: height,
77
114
  };
78
115
  }
116
+ /**
117
+ * 将文本生成高清canvas图片
118
+ */
119
+ export function textToDomToImg(config) {
120
+ return __awaiter(this, void 0, void 0, function () {
121
+ var text, fontOption, font, span, textCanvas, imageBase64, width, height;
122
+ return __generator(this, function (_a) {
123
+ switch (_a.label) {
124
+ case 0:
125
+ text = config.text, fontOption = config.font;
126
+ font = getDefaultFont(fontOption);
127
+ span = document.createElement('span');
128
+ span.innerText = text;
129
+ span.style.color = font.color;
130
+ span.style.fontSize = font.fontSize + "px";
131
+ span.style.fontWeight = font.fontWeight + '';
132
+ span.style.fontStyle = font.fontStyle;
133
+ span.style.fontFamily = font.fontFamily;
134
+ span.style.textAlign = font.textAlign;
135
+ document.body.appendChild(span);
136
+ return [4 /*yield*/, domToCanvas(span)];
137
+ case 1:
138
+ textCanvas = _a.sent();
139
+ imageBase64 = textCanvas.toDataURL('image/jpeg', 1.0);
140
+ width = span.offsetWidth;
141
+ height = span.offsetHeight;
142
+ document.body.removeChild(span);
143
+ return [2 /*return*/, {
144
+ imageBase64: imageBase64,
145
+ width: width,
146
+ height: height,
147
+ }];
148
+ }
149
+ });
150
+ });
151
+ }
152
+ /**
153
+ * 将dom字符串生成高清的canvas图片
154
+ */
79
155
  /**
80
156
  * 根据文本内容 获取字段宽度
81
157
  */
@@ -1,5 +1,7 @@
1
1
  import { getToken } from 'ztxkutils/dist/authority';
2
+ import { encodeFileIdByDownload } from 'ztxkutils/dist/fileOperation';
2
3
  function createDownloadUrl(apiUrl, fileId, otherOptions) {
4
+ fileId = encodeFileIdByDownload(fileId);
3
5
  var token = getToken();
4
6
  var _apiUrl = apiUrl.endsWith('/')
5
7
  ? apiUrl.slice(0, apiUrl.length - 1)
@@ -609,19 +609,12 @@ function setPdfWater(pdf, waterBase64, imgWidth, imgHeight) {
609
609
  /**
610
610
  * @author xjy
611
611
  * @description 性能优化,减少页面dom数量
612
- * @param allDom需要打印的dom节点,parentDom需要打印的dom的父节点
612
+ * @param allDom 需要打印的dom节点,parentDom 需要打印的dom的父节点
613
+ * @param handler 处理每个dom节点的函数,返回Promise
613
614
  */
614
615
  function reduceDom(allDom, parentDom, handler) {
615
616
  return __awaiter(this, void 0, void 0, function () {
616
- function getSpinning() {
617
- return new Promise(function (resolve) {
618
- setTimeout(function () {
619
- var spinning = document.querySelector('.ant-spin-spinning');
620
- resolve(spinning);
621
- }, 0);
622
- });
623
- }
624
- var domList, children, spinning, promiseAllDomArray, _a, _b, _i, i, element, _c, _d, _e, children_1, element;
617
+ var domList, children, spinning, fragment, _i, children_1, element, promiseAllDomArray, _a, _b, _c, i_3, element, _d, _e, i, timer;
625
618
  return __generator(this, function (_f) {
626
619
  switch (_f.label) {
627
620
  case 0:
@@ -638,39 +631,66 @@ function reduceDom(allDom, parentDom, handler) {
638
631
  spinning.style.alignItems = 'center';
639
632
  spinning.innerHTML = '正在生成PDF...';
640
633
  }
634
+ fragment = document.createDocumentFragment();
641
635
  // 卸载dom
642
- parentDom.innerHTML = '';
636
+ for (_i = 0, children_1 = children; _i < children_1.length; _i++) {
637
+ element = children_1[_i];
638
+ parentDom.removeChild(element);
639
+ fragment.appendChild(element);
640
+ }
643
641
  promiseAllDomArray = [];
644
642
  _a = [];
645
643
  for (_b in domList)
646
644
  _a.push(_b);
647
- _i = 0;
645
+ _c = 0;
648
646
  _f.label = 2;
649
647
  case 2:
650
- if (!(_i < _a.length)) return [3 /*break*/, 5];
651
- i = _a[_i];
648
+ if (!(_c < _a.length)) return [3 /*break*/, 5];
649
+ i_3 = _a[_c];
652
650
  if (spinning) {
653
- spinning.innerHTML = "<p>\u6B63\u5728\u751F\u6210PDF...</p><p>\u5F53\u524D\u8FDB\u5EA6" + (1 + Number(i)) + "/" + domList.length + "\u9875</p>";
651
+ spinning.innerHTML = "<p>\u6B63\u5728\u751F\u6210PDF...</p><p>\u5F53\u524D\u8FDB\u5EA6" + (1 + Number(i_3)) + "/" + domList.length + "\u9875</p>";
654
652
  }
655
- element = domList[i];
653
+ element = domList[i_3].cloneNode(true);
656
654
  parentDom.appendChild(element);
657
- _d = (_c = promiseAllDomArray).push;
658
- return [4 /*yield*/, handler(element, i)];
655
+ _e = (_d = promiseAllDomArray).push;
656
+ return [4 /*yield*/, handler(element, i_3)];
659
657
  case 3:
660
- _d.apply(_c, [_f.sent()]);
658
+ _e.apply(_d, [_f.sent()]);
661
659
  parentDom.removeChild(element);
662
660
  _f.label = 4;
663
661
  case 4:
664
- _i++;
662
+ _c++;
665
663
  return [3 /*break*/, 2];
666
664
  case 5:
667
665
  // 添加dom
668
- for (_e = 0, children_1 = children; _e < children_1.length; _e++) {
669
- element = children_1[_e];
670
- parentDom.appendChild(element);
666
+ // for (let element of children) {
667
+ // parentDom.appendChild(element);
668
+ // }
669
+ parentDom.appendChild(fragment);
670
+ i = 0;
671
+ if (spinning) {
672
+ spinning.innerHTML = "<p>\u6B63\u5728\u5BFC\u51FAPDF...</p><p>\u7B49\u5F85" + (1 + i) + "\u79D2";
671
673
  }
674
+ timer = setInterval(function () {
675
+ var spinning = document.querySelector('.ant-spin-spinning');
676
+ if (spinning) {
677
+ spinning.innerHTML = "<p>\u6B63\u5728\u5BFC\u51FAPDF...</p><p>\u7B49\u5F85" + (1 + i) + "\u79D2";
678
+ i++;
679
+ }
680
+ else {
681
+ timer && clearInterval(timer);
682
+ }
683
+ }, 1000);
672
684
  return [2 /*return*/, promiseAllDomArray];
673
685
  }
674
686
  });
675
687
  });
676
688
  }
689
+ function getSpinning() {
690
+ return new Promise(function (resolve) {
691
+ setTimeout(function () {
692
+ var spinning = document.querySelector('.ant-spin-spinning');
693
+ resolve(spinning);
694
+ }, 0);
695
+ });
696
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkui",
3
- "version": "4.2.23-335-beta",
3
+ "version": "4.2.23-336-beta",
4
4
  "private": false,
5
5
  "description": "React components library",
6
6
  "author": "zt-front-end",