ztxkutils 2.10.15 → 2.10.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.
@@ -51,6 +51,14 @@ export declare function createPublicDownloadUrl(apiUrl: string, fileId: string):
51
51
  * @param {string} fileName 文件名
52
52
  */
53
53
  export declare function previewFile(fileUrl: string, fileId: string, otherOption?: any): void;
54
+ /**
55
+ * @description 批量文件预览方法,只针对图片类型
56
+ * @param {string} fileUrl 文件服务器ip端口
57
+ * @param {string} fileId 文件id
58
+ * @param {string} fileType 文件类型
59
+ * @param {string} fileName 文件名
60
+ */
61
+ export declare function batchPreviewFile(fileUrl: string, fileId: string, otherOption?: any): void;
54
62
  /**
55
63
  * @description 生成原始图片路径
56
64
  * @param {string} fileUrl 文件服务器ip端口
@@ -212,6 +212,38 @@ function previewFile(fileUrl, fileId, otherOption) {
212
212
  window.open(fileUrl + "/attchPreview?attachId=" + fileId + "&Zmdms-Auth=bearer " + token + "&officePreviewType=pdf");
213
213
  }
214
214
  }
215
+ /**
216
+ * @description 批量文件预览方法,只针对图片类型
217
+ * @param {string} fileUrl 文件服务器ip端口
218
+ * @param {string} fileId 文件id
219
+ * @param {string} fileType 文件类型
220
+ * @param {string} fileName 文件名
221
+ */
222
+ function batchPreviewFile(fileUrl, fileId, otherOption) {
223
+ var token = '';
224
+ if (typeof otherOption === 'object') {
225
+ token = getToken() || (otherOption === null || otherOption === void 0 ? void 0 : otherOption.authToken);
226
+ }
227
+ else {
228
+ token = getToken() || otherOption;
229
+ }
230
+ var titleName = dangerouslySetXss(otherOption === null || otherOption === void 0 ? void 0 : otherOption.titleName);
231
+ try {
232
+ titleName = titleName.replaceAll('%', '');
233
+ }
234
+ catch (err) {
235
+ console.log(err);
236
+ }
237
+ var _fileUrl = fileUrl.endsWith('/')
238
+ ? fileUrl.slice(0, fileUrl.length - 1)
239
+ : fileUrl;
240
+ if (titleName) {
241
+ window.open(_fileUrl + "/picturesAttchPreview?attachIds=" + fileId + "&Zmdms-Auth=bearer " + token + "&titleName=" + encodeURIComponent(titleName));
242
+ }
243
+ else {
244
+ window.open(fileUrl + "/picturesAttchPreview?attachIds=" + fileId + "&Zmdms-Auth=bearer " + token);
245
+ }
246
+ }
215
247
  /**
216
248
  * @description 生成原始图片路径
217
249
  * @param {string} fileUrl 文件服务器ip端口
@@ -251,4 +283,4 @@ function createThumbnailUrl(apiUrl, fileId, scale, otherOption) {
251
283
  return _apiUrl + "/api/zmdms-resource/oss/endpoint/thumbnail/" + fileId + "?scale=" + scale + "&Zmdms-Auth=bearer " + token;
252
284
  }
253
285
 
254
- export { batchDownloadFileCallBack, createDownloadUrl, createDownloadUrlNoBase, createOriginalUrl, createPublicDownloadUrl, createThumbnailUrl, downloadFile, downloadFileCallBack, downloadPublicFile, previewFile };
286
+ export { batchDownloadFileCallBack, batchPreviewFile, createDownloadUrl, createDownloadUrlNoBase, createOriginalUrl, createPublicDownloadUrl, createThumbnailUrl, downloadFile, downloadFileCallBack, downloadPublicFile, previewFile };
package/dist/print.js CHANGED
@@ -100,18 +100,23 @@ function addPdfWaterHandle(pdf, waterBase64) {
100
100
  /**
101
101
  * html转pdf
102
102
  */
103
- function createPdf(canvas, pdf, noWater, positionX) {
103
+ function createPdf(canvas, pdf, noWater, positionX, options) {
104
104
  var contentWidth = canvas.width;
105
105
  var contentHeight = canvas.height;
106
+ var setWidth = (options === null || options === void 0 ? void 0 : options.width) || 592.28;
107
+ var setHeight = (options === null || options === void 0 ? void 0 : options.height) || 841.89;
106
108
  // 一页pdf显示html页面生成的canvas高度
107
- var pageHeight = (contentWidth / 592.28) * 841.89;
109
+ // const pageHeight = (contentWidth / 592.28) * 841.89;
110
+ var pageHeight = (contentWidth / setWidth) * setHeight;
108
111
  // 未生成pdf的html页面高度
109
112
  var leftHeight = contentHeight;
110
113
  // 页面拍内衣
111
114
  var position = 0;
112
115
  //a4纸的尺寸[595.28,841.89],html页面生成的canvas在pdf中图片的宽高
113
- var imgWidth = 595.28;
114
- var imgHeight = (592.28 / contentWidth) * contentHeight;
116
+ // const imgWidth = 595.28;
117
+ // const imgHeight = (592.28 / contentWidth) * contentHeight;
118
+ var imgWidth = setWidth - (positionX || 20) - 10;
119
+ var imgHeight = (setWidth / contentWidth) * contentHeight;
115
120
  var pageData = canvas.toDataURL('image/jpeg', 1.0);
116
121
  //有两个高度需要区分,一个是html页面的实际高度,和生成pdf的页面高度(841.89)
117
122
  //当内容未超过pdf一页显示的范围,无需分页
@@ -136,7 +141,8 @@ function createPdf(canvas, pdf, noWater, positionX) {
136
141
  addPdfWaterHandle(pdf, waterBase64);
137
142
  }
138
143
  leftHeight -= pageHeight;
139
- position -= 841.89;
144
+ // position -= 841.89;
145
+ position -= setHeight;
140
146
  //避免添加空白页
141
147
  if (leftHeight > 0) {
142
148
  pdf.addPage();
@@ -147,7 +153,8 @@ function createPdf(canvas, pdf, noWater, positionX) {
147
153
  function htmlToPdf(_a) {
148
154
  var pageClassName = _a.pageClassName, dom = _a.dom, pdfName = _a.pdfName, isShowPage = _a.isShowPage, noWater = _a.noWater, pdfOptions = _a.pdfOptions, imgPositionX = _a.imgPositionX;
149
155
  var allDom = document.querySelectorAll(pageClassName ? pageClassName : '.html2canvas-container-page');
150
- var pdf = new jsPDF(__assign({ unit: 'pt', format: [632.28, 841.89] }, (pdfOptions || {})));
156
+ var format = (pdfOptions === null || pdfOptions === void 0 ? void 0 : pdfOptions.format) || [632.28, 841.89];
157
+ var pdf = new jsPDF(__assign({ unit: 'pt', format: format }, (pdfOptions || {})));
151
158
  if (allDom.length > 0 && isShowPage) {
152
159
  var allDomArray = Array.prototype.slice.call(allDom);
153
160
  var promiseAllDomArray_1 = allDomArray.map(function (dom) {
@@ -171,7 +178,10 @@ function htmlToPdf(_a) {
171
178
  return [4 /*yield*/, item];
172
179
  case 2:
173
180
  canvas = _a.sent();
174
- createPdf(canvas, pdf, noWater, imgPositionX);
181
+ createPdf(canvas, pdf, noWater, imgPositionX, {
182
+ width: format === null || format === void 0 ? void 0 : format[0],
183
+ height: format === null || format === void 0 ? void 0 : format[1],
184
+ });
175
185
  if (i < promiseAllDomArray_1.length) {
176
186
  pdf.addPage();
177
187
  }
@@ -189,7 +199,10 @@ function htmlToPdf(_a) {
189
199
  }
190
200
  else {
191
201
  return html2canvas(dom, { scale: 2 }).then(function (canvas) {
192
- createPdf(canvas, pdf, noWater, imgPositionX);
202
+ createPdf(canvas, pdf, noWater, imgPositionX, {
203
+ width: format === null || format === void 0 ? void 0 : format[0],
204
+ height: format === null || format === void 0 ? void 0 : format[1],
205
+ });
193
206
  pdf.save(pdfName + ".pdf");
194
207
  return pdf;
195
208
  });
@@ -225,15 +238,17 @@ function htmlToPdfNoCanvas(_a) {
225
238
  pdfs_1 = [];
226
239
  return [2 /*return*/, (function () {
227
240
  return __awaiter(this, void 0, void 0, function () {
228
- var _loop_1, _i, allDomArray_2, item;
241
+ var i, _loop_1, _i, allDomArray_2, item;
229
242
  return __generator(this, function (_a) {
230
243
  switch (_a.label) {
231
244
  case 0:
245
+ i = 0;
232
246
  _loop_1 = function (item) {
233
247
  var pdf, pageWidth;
234
248
  return __generator(this, function (_b) {
235
249
  switch (_b.label) {
236
250
  case 0:
251
+ i++;
237
252
  pdf = new jsPDF(pdfOptions);
238
253
  pageWidth = pdf.internal.pageSize.width - pageMarginX * 2;
239
254
  setPdfVersion(pdf);
@@ -246,7 +261,7 @@ function htmlToPdfNoCanvas(_a) {
246
261
  windowWidth: pageWidth,
247
262
  callback: function (res) {
248
263
  // 添加呈现的HTML所需的页面(从第2页开始)
249
- for (var i = 2, j = res.internal.getNumberOfPages(); i <= j; i++) {
264
+ for (var i_1 = 2, j = res.internal.getNumberOfPages(); i_1 <= j; i_1++) {
250
265
  pdf.addPage(pageFormat, pageOrient);
251
266
  }
252
267
  // 正确呈现文档
@@ -256,15 +271,15 @@ function htmlToPdfNoCanvas(_a) {
256
271
  width: pageWidth,
257
272
  windowWidth: pageWidth,
258
273
  callback: function () {
259
- for (var i = 1, j = res.internal.getNumberOfPages(); i <= j; i++) {
260
- pdf.setPage(i);
274
+ for (var i_2 = 1, j = res.internal.getNumberOfPages(); i_2 <= j; i_2++) {
275
+ pdf.setPage(i_2);
261
276
  // 添加水印
262
277
  if (isAddWater) {
263
278
  setPdfWater(pdf, waterBase64, imgWidth, imgHeight);
264
279
  }
265
280
  }
266
281
  if (isDownload) {
267
- pdf.save(pdfName + ".pdf");
282
+ pdf.save(pdfName + "_" + i + ".pdf");
268
283
  }
269
284
  pdfBase64_1.push(pdf.output('dataurlstring'));
270
285
  pdfs_1.push(pdf);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkutils",
3
- "version": "2.10.15",
3
+ "version": "2.10.17",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",