@jcyao/print-sdk 1.1.0 → 1.1.2

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
@@ -211,8 +211,9 @@ function generatePrintPageStyles(config) {
211
211
 
212
212
  @media print {
213
213
  body {
214
- background: white;
215
- padding: 0;
214
+ margin: 0 !important;
215
+ padding: 0 !important;
216
+ background: white !important;
216
217
  }
217
218
 
218
219
  @page {
@@ -221,9 +222,9 @@ function generatePrintPageStyles(config) {
221
222
  }
222
223
 
223
224
  .print-page {
225
+ margin: 0 !important;
226
+ box-shadow: none !important;
224
227
  page-break-after: always;
225
- margin-bottom: 0 !important;
226
- box-shadow: none; /* 移除阴影 */
227
228
  }
228
229
 
229
230
  .print-page:last-child {
@@ -250,7 +251,7 @@ function generatePrintPageStyles(config) {
250
251
  * 用于 PrintSDK 的 printMultiple
251
252
  */
252
253
  function generateBatchPrintStyles(config) {
253
- const { pageWidthMm, pageHeightMm, isContinuous = false, minHeightMm = 100, } = config;
254
+ const { pageWidthMm, pageHeightMm, marginTop = 0, marginRight = 0, marginBottom = 0, marginLeft = 0, isContinuous = false, minHeightMm = 100, } = config;
254
255
  return `
255
256
  * { margin: 0; padding: 0; box-sizing: border-box; }
256
257
  body { margin: 0; padding: 0; background: #f5f5f5; }
@@ -261,8 +262,8 @@ function generateBatchPrintStyles(config) {
261
262
  }
262
263
 
263
264
  @media print {
264
- body { margin: 0; padding: 0; background: white; }
265
- .print-page { margin: 0; page-break-after: always; box-shadow: none !important; }
265
+ body { margin: 0 !important; padding: 0 !important; background: white !important; }
266
+ .print-page { margin: 0 !important; page-break-after: always; box-shadow: none !important; }
266
267
  .print-page:last-child { page-break-after: auto; }
267
268
  }
268
269
 
@@ -273,7 +274,7 @@ function generateBatchPrintStyles(config) {
273
274
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
274
275
  }
275
276
  }
276
-
277
+
277
278
  .print-page {
278
279
  width: ${pageWidthMm}mm;
279
280
  height: ${isContinuous ? 'auto' : pageHeightMm + 'mm'};
@@ -281,6 +282,7 @@ function generateBatchPrintStyles(config) {
281
282
  background: white;
282
283
  position: relative;
283
284
  box-sizing: border-box;
285
+ padding: ${marginTop}mm ${marginRight}mm ${marginBottom}mm ${marginLeft}mm;
284
286
  }
285
287
 
286
288
  ${generateComponentStyles()}
@@ -586,6 +588,25 @@ class TextRenderer {
586
588
  /**
587
589
  * 表格组件渲染器
588
590
  */
591
+ /**
592
+ * 根据数据路径从对象中取值
593
+ * 支持嵌套路径,如:'product.name' => obj.product.name
594
+ * @param obj 数据对象
595
+ * @param path 属性路径,支持点号分隔的嵌套路径
596
+ * @returns 属性值,路径不存在时返回 undefined
597
+ */
598
+ function getByPath(obj, path) {
599
+ if (!obj || !path)
600
+ return undefined;
601
+ const keys = path.split('.');
602
+ let value = obj;
603
+ for (const key of keys) {
604
+ if (value === null || value === undefined)
605
+ return undefined;
606
+ value = value[key];
607
+ }
608
+ return value;
609
+ }
589
610
  class TableRenderer {
590
611
  constructor() {
591
612
  this.type = 'table';
@@ -690,7 +711,8 @@ class TableRenderer {
690
711
  .map((row) => {
691
712
  const cells = visibleColumns
692
713
  .map((col) => {
693
- const value = row[col.dataIndex] || '';
714
+ var _a;
715
+ const value = (_a = getByPath(row, col.dataIndex)) !== null && _a !== void 0 ? _a : '';
694
716
  // 使用百分比宽度,min-height 允许内容换行时自然扩展
695
717
  return `<td style="${cellBorder} ${cellPadding} ${cellTextStyle} text-align: ${textAlign}; width: ${colWidthPercent}%; min-height: ${rowHeightPx}px; box-sizing: border-box;">${value}</td>`;
696
718
  })
@@ -771,7 +793,7 @@ class TableRenderer {
771
793
  return '';
772
794
  const values = data
773
795
  .map(row => {
774
- const val = row[column.dataIndex];
796
+ const val = getByPath(row, column.dataIndex);
775
797
  // 尝试转换为数字,失败则返回 null
776
798
  const num = Number(val);
777
799
  return isNaN(num) ? null : num;