@jcyao/print-sdk 1.1.0 → 1.1.1

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
@@ -586,6 +586,25 @@ class TextRenderer {
586
586
  /**
587
587
  * 表格组件渲染器
588
588
  */
589
+ /**
590
+ * 根据数据路径从对象中取值
591
+ * 支持嵌套路径,如:'product.name' => obj.product.name
592
+ * @param obj 数据对象
593
+ * @param path 属性路径,支持点号分隔的嵌套路径
594
+ * @returns 属性值,路径不存在时返回 undefined
595
+ */
596
+ function getByPath(obj, path) {
597
+ if (!obj || !path)
598
+ return undefined;
599
+ const keys = path.split('.');
600
+ let value = obj;
601
+ for (const key of keys) {
602
+ if (value === null || value === undefined)
603
+ return undefined;
604
+ value = value[key];
605
+ }
606
+ return value;
607
+ }
589
608
  class TableRenderer {
590
609
  constructor() {
591
610
  this.type = 'table';
@@ -690,7 +709,8 @@ class TableRenderer {
690
709
  .map((row) => {
691
710
  const cells = visibleColumns
692
711
  .map((col) => {
693
- const value = row[col.dataIndex] || '';
712
+ var _a;
713
+ const value = (_a = getByPath(row, col.dataIndex)) !== null && _a !== void 0 ? _a : '';
694
714
  // 使用百分比宽度,min-height 允许内容换行时自然扩展
695
715
  return `<td style="${cellBorder} ${cellPadding} ${cellTextStyle} text-align: ${textAlign}; width: ${colWidthPercent}%; min-height: ${rowHeightPx}px; box-sizing: border-box;">${value}</td>`;
696
716
  })
@@ -771,7 +791,7 @@ class TableRenderer {
771
791
  return '';
772
792
  const values = data
773
793
  .map(row => {
774
- const val = row[column.dataIndex];
794
+ const val = getByPath(row, column.dataIndex);
775
795
  // 尝试转换为数字,失败则返回 null
776
796
  const num = Number(val);
777
797
  return isNaN(num) ? null : num;