wkjp-list-page 1.0.27 → 1.0.28

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wkjp-list-page",
3
- "version": "1.0.27",
3
+ "version": "1.0.28",
4
4
  "description": "Vue2 + ElementUI CommonListPage component",
5
5
  "main": "src/index.js",
6
6
  "module": "src/index.js",
@@ -128,6 +128,13 @@
128
128
  <slot :name="col.slot" :row="scope.row" :scope="scope"></slot>
129
129
  </template>
130
130
  </el-table-column>
131
+ <nested-table-column
132
+ v-else-if="col.children && col.children.length"
133
+ :key="'col-nested-' + idx + '-' + (col.prop || col.label)"
134
+ :column="col"
135
+ :resolve-cell-text="resolveCellText"
136
+ :column-bind="tableColumnBind"
137
+ />
131
138
  <el-table-column
132
139
  v-else-if="col.type !== 'slot' && isBuiltinCellColumn(col)"
133
140
  :key="'col-builtin-' + idx + '-' + col.type"
@@ -306,6 +313,7 @@ import FloatingSelect from "./FloatingSelect.vue";
306
313
  import FloatingDatePicker from "./FloatingDatePicker.vue";
307
314
  import FloatingCascader from "./FloatingCascader.vue";
308
315
  import ExportFile from "./ExportFile.vue";
316
+ import NestedTableColumn from "./NestedTableColumn.vue";
309
317
 
310
318
  export default {
311
319
  name: "CommonListPage",
@@ -314,7 +322,8 @@ export default {
314
322
  FloatingSelect,
315
323
  FloatingDatePicker,
316
324
  FloatingCascader,
317
- ExportFile
325
+ ExportFile,
326
+ NestedTableColumn,
318
327
  },
319
328
  props: {
320
329
  filters: { type: Object, required: true },
@@ -689,6 +698,13 @@ export default {
689
698
  /** 表头 + 当前页数据中最长展示文本的字符数(slot 列仅表头) */
690
699
  getColumnMaxContentLength(col) {
691
700
  var labelLen = this.textDisplayLength((col && (col.label || col.prop || col.slot)) || "");
701
+ if (col && col.children && col.children.length) {
702
+ var nestedMax = labelLen;
703
+ for (var c = 0; c < col.children.length; c++) {
704
+ nestedMax = Math.max(nestedMax, this.getColumnMaxContentLength(col.children[c]));
705
+ }
706
+ return nestedMax;
707
+ }
692
708
  if (!col || col.type === "slot" || this.isBuiltinCellColumn(col)) {
693
709
  return labelLen;
694
710
  }
@@ -702,6 +718,12 @@ export default {
702
718
  },
703
719
  resolveAutoColumnLayout(col) {
704
720
  if (!col) return {};
721
+ if (col.children && col.children.length) {
722
+ var nestedLayout = {};
723
+ if (col.width != null && col.width !== "") nestedLayout.width = col.width;
724
+ if (col.minWidth != null && col.minWidth !== "") nestedLayout.minWidth = col.minWidth;
725
+ return nestedLayout;
726
+ }
705
727
  var hasWidth = col.width != null && col.width !== "";
706
728
  var hasMinWidth = col.minWidth != null && col.minWidth !== "";
707
729
  if (hasWidth || hasMinWidth) {
@@ -733,7 +755,16 @@ export default {
733
755
  return layout;
734
756
  },
735
757
  tableColumnBind(col) {
736
- var omit = ["valueGetter", "textFormatter", "defaultText", "emptyText", "hidden", "_visible", "_configKey"];
758
+ var omit = [
759
+ "valueGetter",
760
+ "textFormatter",
761
+ "defaultText",
762
+ "emptyText",
763
+ "hidden",
764
+ "_visible",
765
+ "_configKey",
766
+ "children",
767
+ ];
737
768
  var rest = {};
738
769
  Object.keys(col || {}).forEach(function (k) {
739
770
  if (omit.indexOf(k) === -1) rest[k] = col[k];
@@ -1,34 +1,41 @@
1
1
  <script>
2
2
  /**
3
- * 递归渲染带 children 的列配置(多级表头)
4
- * 由 CommonListPage 在检测到 columns[].children 时使用
3
+ * 递归渲染 el-table-column,支持 columns[].children 多级表头。
5
4
  */
6
5
  export default {
7
6
  name: "NestedTableColumn",
8
7
  props: {
9
8
  column: { type: Object, required: true },
10
- /** (col, row, rowIndex) => 展示文案,与 CommonListPage.resolveCellText 一致 */
11
- formatCell: { type: Function, default: null },
12
- /** (col) => 传给 el-table-column 的绑定对象 */
9
+ resolveCellText: { type: Function, default: null },
13
10
  columnBind: { type: Function, default: null },
14
11
  },
15
12
  render(h) {
16
13
  const col = this.column;
17
14
  const slots = this.$scopedSlots;
18
- const bind = this.columnBind;
19
- const formatCell = this.formatCell;
15
+ const resolveCellText = this.resolveCellText;
16
+ const columnBind = this.columnBind;
20
17
 
21
18
  if (col.children && col.children.length) {
19
+ const parentBind =
20
+ typeof columnBind === "function" ? columnBind(col) || {} : {};
21
+ const parentProps = {
22
+ label: parentBind.label != null ? parentBind.label : col.label,
23
+ align: parentBind.align != null ? parentBind.align : col.align,
24
+ fixed: parentBind.fixed != null ? parentBind.fixed : col.fixed,
25
+ width: parentBind.width != null ? parentBind.width : col.width,
26
+ minWidth: parentBind.minWidth != null ? parentBind.minWidth : col.minWidth,
27
+ headerAlign: parentBind.headerAlign,
28
+ };
22
29
  return h(
23
30
  "el-table-column",
24
- { props: { label: col.label, align: col.align } },
31
+ { props: parentProps },
25
32
  col.children.map((child, idx) =>
26
33
  h("nested-table-column", {
27
34
  key: `${child.prop || child.label || "col"}-${idx}`,
28
35
  props: {
29
36
  column: child,
30
- formatCell,
31
- columnBind: bind,
37
+ resolveCellText,
38
+ columnBind,
32
39
  },
33
40
  scopedSlots: slots,
34
41
  }),
@@ -36,60 +43,31 @@ export default {
36
43
  );
37
44
  }
38
45
 
39
- if (col.type === "slot" && col.slot && slots[col.slot]) {
40
- const slotProps = bind ? bind(this.omitSlotMeta(col)) : this.omitSlotMeta(col);
46
+ const bind = typeof columnBind === "function" ? columnBind(col) || {} : {};
47
+ const columnProps = Object.assign({}, bind);
48
+ delete columnProps.children;
49
+
50
+ if (col.slot && slots[col.slot]) {
41
51
  return h("el-table-column", {
42
- props: slotProps,
52
+ props: columnProps,
43
53
  scopedSlots: {
44
54
  default: (scope) => slots[col.slot](scope),
45
55
  },
46
56
  });
47
57
  }
48
58
 
49
- if (col.type === "selection" || col.type === "index" || col.type === "expand") {
50
- return h("el-table-column", {
51
- props: bind ? bind(col) : col,
52
- });
53
- }
54
-
55
- const columnProps = bind ? bind(col) : this.leafColumnProps(col);
56
-
57
- if (typeof col.formatter === "function") {
58
- columnProps.formatter = col.formatter;
59
- return h("el-table-column", { props: columnProps });
60
- }
61
-
62
59
  return h("el-table-column", {
63
60
  props: columnProps,
64
61
  scopedSlots: {
65
62
  default: (scope) => {
66
63
  const text =
67
- typeof formatCell === "function"
68
- ? formatCell(col, scope.row, scope.$index)
64
+ typeof resolveCellText === "function"
65
+ ? resolveCellText(col, scope.row, scope.$index)
69
66
  : scope.row[col.prop];
70
67
  return h("span", String(text == null ? "" : text));
71
68
  },
72
69
  },
73
70
  });
74
71
  },
75
- methods: {
76
- omitSlotMeta(col) {
77
- const rest = Object.assign({}, col);
78
- delete rest.slot;
79
- delete rest.type;
80
- return rest;
81
- },
82
- leafColumnProps(col) {
83
- return {
84
- prop: col.prop,
85
- label: col.label,
86
- sortable: col.sortable,
87
- width: col.width,
88
- minWidth: col.minWidth,
89
- align: col.align,
90
- showOverflowTooltip: col.showOverflowTooltip,
91
- };
92
- },
93
- },
94
72
  };
95
73
  </script>