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