@guozhi5658/srp-table 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/base-table/__tests__/fillRemainingWidth.test.d.ts +1 -1
- package/dist/base-table/calculations.d.ts +3 -3
- package/dist/base-table/colgroup.d.ts +4 -5
- package/dist/base-table/empty.d.ts +9 -9
- package/dist/base-table/header.d.ts +4 -5
- package/dist/base-table/helpers/SpanManager.d.ts +9 -9
- package/dist/base-table/helpers/TableDOMUtils.d.ts +16 -16
- package/dist/base-table/helpers/getMaximumColSpan.d.ts +9 -9
- package/dist/base-table/helpers/getRichVisibleRectsStream.d.ts +23 -23
- package/dist/base-table/helpers/rowHeightManager.d.ts +7 -7
- package/dist/base-table/html-table.d.ts +14 -15
- package/dist/base-table/index.d.ts +3 -3
- package/dist/base-table/interfaces.d.ts +54 -54
- package/dist/base-table/loading.d.ts +13 -13
- package/dist/base-table/styles.d.ts +86 -83
- package/dist/base-table/table.d.ts +185 -185
- package/dist/base-table/utils.d.ts +22 -22
- package/dist/chunks/{srp-table-pipeline-8dff19ec.js → srp-table-pipeline-4c320be5.js} +2075 -2075
- package/dist/chunks/{srp-table-pipeline-0b26f8d2.esm.js → srp-table-pipeline-88f44dd3.esm.js} +2061 -2061
- package/dist/common-views.d.ts +26 -23
- package/dist/fillRemainingWidth.d.ts +9 -9
- package/dist/interfaces.d.ts +65 -65
- package/dist/internals.d.ts +14 -15
- package/dist/pipeline/features/autoRowSpan.d.ts +2 -2
- package/dist/pipeline/features/buildTree.d.ts +2 -2
- package/dist/pipeline/features/columnHover.d.ts +12 -12
- package/dist/pipeline/features/columnRangeHover.d.ts +15 -15
- package/dist/pipeline/features/columnResize.d.ts +24 -24
- package/dist/pipeline/features/fillRemainingWidth.d.ts +2 -2
- package/dist/pipeline/features/index.d.ts +15 -15
- package/dist/pipeline/features/multiSelect.d.ts +27 -27
- package/dist/pipeline/features/rowDetail.d.ts +29 -29
- package/dist/pipeline/features/rowGrouping.d.ts +14 -14
- package/dist/pipeline/features/rowPopover.d.ts +13 -13
- package/dist/pipeline/features/singleSelect.d.ts +23 -23
- package/dist/pipeline/features/sort.d.ts +42 -42
- package/dist/pipeline/features/tips.d.ts +2 -2
- package/dist/pipeline/features/treeMode.d.ts +29 -29
- package/dist/pipeline/features/treeSelect.d.ts +38 -38
- package/dist/pipeline/index.d.ts +3 -3
- package/dist/pipeline/pipeline.d.ts +79 -79
- package/dist/pivot/cross-table/buildCrossTable.d.ts +17 -17
- package/dist/pivot/cross-table/constants.d.ts +1 -1
- package/dist/pivot/cross-table/cross-table.d.ts +18 -18
- package/dist/pivot/cross-table/index.d.ts +4 -4
- package/dist/pivot/cross-table/interfaces.d.ts +29 -29
- package/dist/pivot/cross-table/internals.d.ts +13 -13
- package/dist/pivot/cross-tree-table/buildCrossTreeTable.d.ts +14 -14
- package/dist/pivot/cross-tree-table/cross-tree-table.d.ts +38 -38
- package/dist/pivot/cross-tree-table/index.d.ts +2 -2
- package/dist/pivot/pivot-utils/buildDrillTree.d.ts +16 -16
- package/dist/pivot/pivot-utils/builders.d.ts +26 -26
- package/dist/pivot/pivot-utils/convert-utils.d.ts +31 -31
- package/dist/pivot/pivot-utils/index.d.ts +5 -5
- package/dist/pivot/pivot-utils/interfaces.d.ts +12 -12
- package/dist/pivot/pivot-utils/simpleEncode.d.ts +1 -1
- package/dist/srp-table-pivot.d.ts +3 -3
- package/dist/srp-table-pivot.esm.js +647 -646
- package/dist/srp-table-pivot.js +647 -646
- package/dist/srp-table.d.ts +6 -6
- package/dist/srp-table.esm.js +2334 -2331
- package/dist/srp-table.js +2347 -2344
- package/dist/transforms/autoRowSpan.d.ts +3 -3
- package/dist/transforms/autoWidth.d.ts +25 -25
- package/dist/transforms/buildTree.d.ts +3 -3
- package/dist/transforms/columnHover.d.ts +14 -14
- package/dist/transforms/columnRangeHover.d.ts +14 -14
- package/dist/transforms/columnResize.d.ts +24 -24
- package/dist/transforms/flatten.d.ts +3 -3
- package/dist/transforms/index.d.ts +12 -12
- package/dist/transforms/orderField.d.ts +3 -3
- package/dist/transforms/sort.d.ts +40 -40
- package/dist/transforms/tips.d.ts +8 -8
- package/dist/transforms/treeMode.d.ts +27 -27
- package/dist/transforms/visible.d.ts +2 -2
- package/dist/transforms/warnTransformsDeprecated.d.ts +1 -1
- package/dist/utils/applyTransforms.d.ts +6 -6
- package/dist/utils/buildTree.d.ts +36 -36
- package/dist/utils/collectNodes.d.ts +8 -8
- package/dist/utils/exportTableAsExcel.d.ts +4 -4
- package/dist/utils/getTreeDepth.d.ts +3 -3
- package/dist/utils/groupBy.d.ts +1 -1
- package/dist/utils/groupBy2.d.ts +1 -1
- package/dist/utils/index.d.ts +14 -14
- package/dist/utils/isLeafNode.d.ts +2 -2
- package/dist/utils/layeredSort.d.ts +5 -5
- package/dist/utils/makeRecursiveMapper.d.ts +9 -9
- package/dist/utils/mergeCellProps.d.ts +9 -9
- package/dist/utils/others.d.ts +11 -10
- package/dist/utils/proto.d.ts +21 -21
- package/dist/utils/smartCompare.d.ts +9 -9
- package/dist/utils/traverseColumn.d.ts +11 -11
- package/dist/utils/tree-data-helpers/StrictTreeDataHelper.d.ts +22 -22
- package/dist/utils/tree-data-helpers/TreeDataHelper.d.ts +26 -26
- package/dist/utils/tree-data-helpers/__tests__/helpers.test.d.ts +1 -1
- package/package.json +4 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { l as groupBy2, e as always, i as isLeafNode, n as fromEntries, d as icons, g as getTreeDepth, _ as __rest, B as BaseTable, T as TablePipeline, j as treeMode } from './chunks/srp-table-pipeline-
|
|
1
|
+
import { l as groupBy2, e as always, i as isLeafNode, n as fromEntries, d as icons, g as getTreeDepth, _ as __rest, B as BaseTable, T as TablePipeline, j as treeMode } from './chunks/srp-table-pipeline-88f44dd3.esm.js';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { noop } from 'rxjs';
|
|
4
4
|
import styled__default from 'styled-components';
|
|
@@ -6,214 +6,214 @@ import 'classnames';
|
|
|
6
6
|
import 'rxjs/operators';
|
|
7
7
|
import 'resize-observer-polyfill';
|
|
8
8
|
|
|
9
|
-
function simpleEncode(path) {
|
|
10
|
-
if (path.length === 0) {
|
|
11
|
-
return 'key:@total@';
|
|
12
|
-
}
|
|
13
|
-
return `key:${path.join(' ')}`;
|
|
9
|
+
function simpleEncode(path) {
|
|
10
|
+
if (path.length === 0) {
|
|
11
|
+
return 'key:@total@';
|
|
12
|
+
}
|
|
13
|
+
return `key:${path.join(' ')}`;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
/** 根据指定的 code 序列计算下钻树 */
|
|
17
|
-
function buildDrillTree(data, codes, { encode = simpleEncode, totalValue = '总计', includeTopWrapper = false, isExpand = always(true), enforceExpandTotalNode = true, } = {}) {
|
|
18
|
-
const emptyPath = [];
|
|
19
|
-
const totalKey = encode(emptyPath);
|
|
20
|
-
let array;
|
|
21
|
-
let hasChild = false;
|
|
22
|
-
if (codes.length === 0) {
|
|
23
|
-
array = [];
|
|
24
|
-
}
|
|
25
|
-
else if (!enforceExpandTotalNode && !isExpand(totalKey)) {
|
|
26
|
-
array = [];
|
|
27
|
-
hasChild = data.length > 0;
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
array = dfs(data, []);
|
|
31
|
-
}
|
|
32
|
-
if (includeTopWrapper) {
|
|
33
|
-
const rootNode = {
|
|
34
|
-
key: totalKey,
|
|
35
|
-
value: totalValue,
|
|
36
|
-
path: emptyPath,
|
|
37
|
-
children: array,
|
|
38
|
-
};
|
|
39
|
-
if (hasChild) {
|
|
40
|
-
rootNode.hasChild = hasChild;
|
|
41
|
-
}
|
|
42
|
-
return [rootNode];
|
|
43
|
-
}
|
|
44
|
-
if (includeTopWrapper) {
|
|
45
|
-
return [
|
|
46
|
-
{
|
|
47
|
-
key: totalKey,
|
|
48
|
-
value: totalValue,
|
|
49
|
-
path: emptyPath,
|
|
50
|
-
children: array,
|
|
51
|
-
},
|
|
52
|
-
];
|
|
53
|
-
}
|
|
54
|
-
return array;
|
|
55
|
-
function dfs(slice, path) {
|
|
56
|
-
const depth = path.length;
|
|
57
|
-
const array = [];
|
|
58
|
-
const code = codes[depth];
|
|
59
|
-
const groups = groupBy2(slice, (row) => row[code]);
|
|
60
|
-
for (const groupKey of groups.keys()) {
|
|
61
|
-
path.push(groupKey);
|
|
62
|
-
const node = {
|
|
63
|
-
key: encode(path),
|
|
64
|
-
value: groupKey,
|
|
65
|
-
path: path.slice(),
|
|
66
|
-
};
|
|
67
|
-
array.push(node);
|
|
68
|
-
const group = groups.get(groupKey);
|
|
69
|
-
if (group.length > 0 && depth < codes.length - 1) {
|
|
70
|
-
if (isExpand(node.key)) {
|
|
71
|
-
node.children = dfs(group, path);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
node.hasChild = true;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
path.pop();
|
|
78
|
-
}
|
|
79
|
-
return array;
|
|
80
|
-
}
|
|
16
|
+
/** 根据指定的 code 序列计算下钻树 */
|
|
17
|
+
function buildDrillTree(data, codes, { encode = simpleEncode, totalValue = '总计', includeTopWrapper = false, isExpand = always(true), enforceExpandTotalNode = true, } = {}) {
|
|
18
|
+
const emptyPath = [];
|
|
19
|
+
const totalKey = encode(emptyPath);
|
|
20
|
+
let array;
|
|
21
|
+
let hasChild = false;
|
|
22
|
+
if (codes.length === 0) {
|
|
23
|
+
array = [];
|
|
24
|
+
}
|
|
25
|
+
else if (!enforceExpandTotalNode && !isExpand(totalKey)) {
|
|
26
|
+
array = [];
|
|
27
|
+
hasChild = data.length > 0;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
array = dfs(data, []);
|
|
31
|
+
}
|
|
32
|
+
if (includeTopWrapper) {
|
|
33
|
+
const rootNode = {
|
|
34
|
+
key: totalKey,
|
|
35
|
+
value: totalValue,
|
|
36
|
+
path: emptyPath,
|
|
37
|
+
children: array,
|
|
38
|
+
};
|
|
39
|
+
if (hasChild) {
|
|
40
|
+
rootNode.hasChild = hasChild;
|
|
41
|
+
}
|
|
42
|
+
return [rootNode];
|
|
43
|
+
}
|
|
44
|
+
if (includeTopWrapper) {
|
|
45
|
+
return [
|
|
46
|
+
{
|
|
47
|
+
key: totalKey,
|
|
48
|
+
value: totalValue,
|
|
49
|
+
path: emptyPath,
|
|
50
|
+
children: array,
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
return array;
|
|
55
|
+
function dfs(slice, path) {
|
|
56
|
+
const depth = path.length;
|
|
57
|
+
const array = [];
|
|
58
|
+
const code = codes[depth];
|
|
59
|
+
const groups = groupBy2(slice, (row) => row[code]);
|
|
60
|
+
for (const groupKey of groups.keys()) {
|
|
61
|
+
path.push(groupKey);
|
|
62
|
+
const node = {
|
|
63
|
+
key: encode(path),
|
|
64
|
+
value: groupKey,
|
|
65
|
+
path: path.slice(),
|
|
66
|
+
};
|
|
67
|
+
array.push(node);
|
|
68
|
+
const group = groups.get(groupKey);
|
|
69
|
+
if (group.length > 0 && depth < codes.length - 1) {
|
|
70
|
+
if (isExpand(node.key)) {
|
|
71
|
+
node.children = dfs(group, path);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
node.hasChild = true;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
path.pop();
|
|
78
|
+
}
|
|
79
|
+
return array;
|
|
80
|
+
}
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
function fallbackAggregate(slice) {
|
|
84
|
-
return slice.length === 1 ? slice[0] : {};
|
|
85
|
-
}
|
|
86
|
-
/** 根据表格左侧与上方的下钻树,从全量明细数据中计算对应的数据立方 */
|
|
87
|
-
function buildRecordMatrix({ data, leftCodes, topCodes, aggregate = fallbackAggregate, encode = simpleEncode, isLeftExpand = always(true), isTopExpand = always(true), prebuiltLeftTree, prebuiltTopTree, }) {
|
|
88
|
-
const ctx = {
|
|
89
|
-
peculiarity: new Set(),
|
|
90
|
-
};
|
|
91
|
-
const [leftRootDrillNode] = prebuiltLeftTree !== null && prebuiltLeftTree !== void 0 ? prebuiltLeftTree : buildDrillTree(data, leftCodes, {
|
|
92
|
-
encode,
|
|
93
|
-
includeTopWrapper: true,
|
|
94
|
-
isExpand: isLeftExpand,
|
|
95
|
-
});
|
|
96
|
-
const [topRootDrillNode] = prebuiltTopTree !== null && prebuiltTopTree !== void 0 ? prebuiltTopTree : buildDrillTree(data, topCodes, {
|
|
97
|
-
encode,
|
|
98
|
-
includeTopWrapper: true,
|
|
99
|
-
isExpand: isTopExpand,
|
|
100
|
-
});
|
|
101
|
-
const transientMatrixRow = buildByLeft(ctx, data, leftRootDrillNode, 0);
|
|
102
|
-
return makeMatrix(transientMatrixRow);
|
|
103
|
-
function buildByLeft(ctx, slice, drillNode, depth) {
|
|
104
|
-
let children = null;
|
|
105
|
-
let col;
|
|
106
|
-
if (isLeafNode(drillNode)) {
|
|
107
|
-
col = buildByTop(ctx, slice, topRootDrillNode, 0);
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
children = [];
|
|
111
|
-
const code = leftCodes[depth];
|
|
112
|
-
const groups = groupBy2(slice, (dwdRow) => dwdRow[code]);
|
|
113
|
-
ctx.peculiarity.add(code);
|
|
114
|
-
for (const child of drillNode.children) {
|
|
115
|
-
const group = groups.get(child.value);
|
|
116
|
-
if (group) {
|
|
117
|
-
children.push(buildByLeft(ctx, group, child, depth + 1));
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
ctx.peculiarity.delete(code);
|
|
121
|
-
col = mergeColsByTopTree(ctx, children.map((child) => child.col));
|
|
122
|
-
}
|
|
123
|
-
return {
|
|
124
|
-
leftKey: drillNode.key,
|
|
125
|
-
children,
|
|
126
|
-
col,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
function buildByTop(ctx, slice, drillNode, depth) {
|
|
130
|
-
let children = null;
|
|
131
|
-
let record;
|
|
132
|
-
if (isLeafNode(drillNode)) {
|
|
133
|
-
record = aggregate(slice, ctx);
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
children = [];
|
|
137
|
-
const code = topCodes[depth];
|
|
138
|
-
const groups = groupBy2(slice, (dwdRow) => dwdRow[code]);
|
|
139
|
-
ctx.peculiarity.add(code);
|
|
140
|
-
for (const child of drillNode.children) {
|
|
141
|
-
const group = groups.get(child.value);
|
|
142
|
-
if (group) {
|
|
143
|
-
children.push(buildByTop(ctx, group, child, depth + 1));
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
ctx.peculiarity.delete(code);
|
|
147
|
-
record = aggregate(children.map((child) => child.record), ctx);
|
|
148
|
-
}
|
|
149
|
-
return {
|
|
150
|
-
topKey: drillNode.key,
|
|
151
|
-
topValue: drillNode.value,
|
|
152
|
-
children,
|
|
153
|
-
record,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
function mergeColsByTopTree(ctx, colsToMerge) {
|
|
157
|
-
return dfs(ctx, colsToMerge, topRootDrillNode, 0);
|
|
158
|
-
function dfs(ctx, cols, topDrillNode, depth) {
|
|
159
|
-
let children = null;
|
|
160
|
-
const record = aggregate(cols.map((c) => c.record), ctx);
|
|
161
|
-
if (!isLeafNode(topDrillNode)) {
|
|
162
|
-
const topCode = topCodes[depth];
|
|
163
|
-
ctx.peculiarity.add(topCode);
|
|
164
|
-
const drillChildDict = fromEntries(topDrillNode.children.map((child) => [child.value, child]));
|
|
165
|
-
const colChildDictArray = cols.map((col) => fromEntries(col.children.map((child) => [child.topValue, child])));
|
|
166
|
-
children = topDrillNode.children.map((item) => {
|
|
167
|
-
const childCols = colChildDictArray.map((colChildDict) => colChildDict[item.value]).filter(Boolean);
|
|
168
|
-
return dfs(ctx, childCols, drillChildDict[item.value], depth + 1);
|
|
169
|
-
});
|
|
170
|
-
ctx.peculiarity.delete(topCode);
|
|
171
|
-
}
|
|
172
|
-
return {
|
|
173
|
-
topKey: topDrillNode.key,
|
|
174
|
-
topValue: topDrillNode.value,
|
|
175
|
-
record,
|
|
176
|
-
children,
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
function makeMatrix(rootRow) {
|
|
181
|
-
const result = new Map();
|
|
182
|
-
dfsRow(result, rootRow);
|
|
183
|
-
return result;
|
|
184
|
-
function dfsRow(matrix, row) {
|
|
185
|
-
const subMap = new Map();
|
|
186
|
-
matrix.set(row.leftKey, subMap);
|
|
187
|
-
dfsCol(subMap, row.col);
|
|
188
|
-
if (!isLeafNode(row)) {
|
|
189
|
-
row.children.forEach((childRow) => {
|
|
190
|
-
dfsRow(matrix, childRow);
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
function dfsCol(subMap, col) {
|
|
195
|
-
subMap.set(col.topKey, col.record);
|
|
196
|
-
if (!isLeafNode(col)) {
|
|
197
|
-
col.children.forEach((childCol) => {
|
|
198
|
-
dfsCol(subMap, childCol);
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
/** buildRecordMatrix 的简化版本,只能处理一个维度序列,返回一个 Map。
|
|
205
|
-
* 相当于只处理 matrix 的第一行(汇总行) */
|
|
206
|
-
function buildRecordMap({ codes, encode = simpleEncode, data, aggregate, isExpand, }) {
|
|
207
|
-
const matrix = buildRecordMatrix({
|
|
208
|
-
data,
|
|
209
|
-
leftCodes: [],
|
|
210
|
-
topCodes: codes,
|
|
211
|
-
isTopExpand: isExpand,
|
|
212
|
-
aggregate,
|
|
213
|
-
encode,
|
|
214
|
-
});
|
|
215
|
-
const totalKey = encode([]);
|
|
216
|
-
return matrix.get(totalKey);
|
|
83
|
+
function fallbackAggregate(slice) {
|
|
84
|
+
return slice.length === 1 ? slice[0] : {};
|
|
85
|
+
}
|
|
86
|
+
/** 根据表格左侧与上方的下钻树,从全量明细数据中计算对应的数据立方 */
|
|
87
|
+
function buildRecordMatrix({ data, leftCodes, topCodes, aggregate = fallbackAggregate, encode = simpleEncode, isLeftExpand = always(true), isTopExpand = always(true), prebuiltLeftTree, prebuiltTopTree, }) {
|
|
88
|
+
const ctx = {
|
|
89
|
+
peculiarity: new Set(),
|
|
90
|
+
};
|
|
91
|
+
const [leftRootDrillNode] = prebuiltLeftTree !== null && prebuiltLeftTree !== void 0 ? prebuiltLeftTree : buildDrillTree(data, leftCodes, {
|
|
92
|
+
encode,
|
|
93
|
+
includeTopWrapper: true,
|
|
94
|
+
isExpand: isLeftExpand,
|
|
95
|
+
});
|
|
96
|
+
const [topRootDrillNode] = prebuiltTopTree !== null && prebuiltTopTree !== void 0 ? prebuiltTopTree : buildDrillTree(data, topCodes, {
|
|
97
|
+
encode,
|
|
98
|
+
includeTopWrapper: true,
|
|
99
|
+
isExpand: isTopExpand,
|
|
100
|
+
});
|
|
101
|
+
const transientMatrixRow = buildByLeft(ctx, data, leftRootDrillNode, 0);
|
|
102
|
+
return makeMatrix(transientMatrixRow);
|
|
103
|
+
function buildByLeft(ctx, slice, drillNode, depth) {
|
|
104
|
+
let children = null;
|
|
105
|
+
let col;
|
|
106
|
+
if (isLeafNode(drillNode)) {
|
|
107
|
+
col = buildByTop(ctx, slice, topRootDrillNode, 0);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
children = [];
|
|
111
|
+
const code = leftCodes[depth];
|
|
112
|
+
const groups = groupBy2(slice, (dwdRow) => dwdRow[code]);
|
|
113
|
+
ctx.peculiarity.add(code);
|
|
114
|
+
for (const child of drillNode.children) {
|
|
115
|
+
const group = groups.get(child.value);
|
|
116
|
+
if (group) {
|
|
117
|
+
children.push(buildByLeft(ctx, group, child, depth + 1));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
ctx.peculiarity.delete(code);
|
|
121
|
+
col = mergeColsByTopTree(ctx, children.map((child) => child.col));
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
leftKey: drillNode.key,
|
|
125
|
+
children,
|
|
126
|
+
col,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function buildByTop(ctx, slice, drillNode, depth) {
|
|
130
|
+
let children = null;
|
|
131
|
+
let record;
|
|
132
|
+
if (isLeafNode(drillNode)) {
|
|
133
|
+
record = aggregate(slice, ctx);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
children = [];
|
|
137
|
+
const code = topCodes[depth];
|
|
138
|
+
const groups = groupBy2(slice, (dwdRow) => dwdRow[code]);
|
|
139
|
+
ctx.peculiarity.add(code);
|
|
140
|
+
for (const child of drillNode.children) {
|
|
141
|
+
const group = groups.get(child.value);
|
|
142
|
+
if (group) {
|
|
143
|
+
children.push(buildByTop(ctx, group, child, depth + 1));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
ctx.peculiarity.delete(code);
|
|
147
|
+
record = aggregate(children.map((child) => child.record), ctx);
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
topKey: drillNode.key,
|
|
151
|
+
topValue: drillNode.value,
|
|
152
|
+
children,
|
|
153
|
+
record,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function mergeColsByTopTree(ctx, colsToMerge) {
|
|
157
|
+
return dfs(ctx, colsToMerge, topRootDrillNode, 0);
|
|
158
|
+
function dfs(ctx, cols, topDrillNode, depth) {
|
|
159
|
+
let children = null;
|
|
160
|
+
const record = aggregate(cols.map((c) => c.record), ctx);
|
|
161
|
+
if (!isLeafNode(topDrillNode)) {
|
|
162
|
+
const topCode = topCodes[depth];
|
|
163
|
+
ctx.peculiarity.add(topCode);
|
|
164
|
+
const drillChildDict = fromEntries(topDrillNode.children.map((child) => [child.value, child]));
|
|
165
|
+
const colChildDictArray = cols.map((col) => fromEntries(col.children.map((child) => [child.topValue, child])));
|
|
166
|
+
children = topDrillNode.children.map((item) => {
|
|
167
|
+
const childCols = colChildDictArray.map((colChildDict) => colChildDict[item.value]).filter(Boolean);
|
|
168
|
+
return dfs(ctx, childCols, drillChildDict[item.value], depth + 1);
|
|
169
|
+
});
|
|
170
|
+
ctx.peculiarity.delete(topCode);
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
topKey: topDrillNode.key,
|
|
174
|
+
topValue: topDrillNode.value,
|
|
175
|
+
record,
|
|
176
|
+
children,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function makeMatrix(rootRow) {
|
|
181
|
+
const result = new Map();
|
|
182
|
+
dfsRow(result, rootRow);
|
|
183
|
+
return result;
|
|
184
|
+
function dfsRow(matrix, row) {
|
|
185
|
+
const subMap = new Map();
|
|
186
|
+
matrix.set(row.leftKey, subMap);
|
|
187
|
+
dfsCol(subMap, row.col);
|
|
188
|
+
if (!isLeafNode(row)) {
|
|
189
|
+
row.children.forEach((childRow) => {
|
|
190
|
+
dfsRow(matrix, childRow);
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function dfsCol(subMap, col) {
|
|
195
|
+
subMap.set(col.topKey, col.record);
|
|
196
|
+
if (!isLeafNode(col)) {
|
|
197
|
+
col.children.forEach((childCol) => {
|
|
198
|
+
dfsCol(subMap, childCol);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/** buildRecordMatrix 的简化版本,只能处理一个维度序列,返回一个 Map。
|
|
205
|
+
* 相当于只处理 matrix 的第一行(汇总行) */
|
|
206
|
+
function buildRecordMap({ codes, encode = simpleEncode, data, aggregate, isExpand, }) {
|
|
207
|
+
const matrix = buildRecordMatrix({
|
|
208
|
+
data,
|
|
209
|
+
leftCodes: [],
|
|
210
|
+
topCodes: codes,
|
|
211
|
+
isTopExpand: isExpand,
|
|
212
|
+
aggregate,
|
|
213
|
+
encode,
|
|
214
|
+
});
|
|
215
|
+
const totalKey = encode([]);
|
|
216
|
+
return matrix.get(totalKey);
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
const ExpandSpan = styled__default.span `
|
|
@@ -231,456 +231,457 @@ const ExpandSpan = styled__default.span `
|
|
|
231
231
|
transform: rotate(90deg);
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
|
-
`;
|
|
235
|
-
function convertDrillTreeToCrossTree(drillTree, { indicators, encode = simpleEncode, generateSubtotalNode, enforceExpandTotalNode = true, expandKeys, onChangeExpandKeys = noop, supportsExpand, } = {}) {
|
|
236
|
-
const totalKey = encode([]);
|
|
237
|
-
if (supportsExpand && expandKeys == null) {
|
|
238
|
-
throw new Error('[srp-table] convertDrillTreeToCrossTree(...) 设置 supportsExpand=true 时,expandKeys 不能为 null/undefined.');
|
|
239
|
-
}
|
|
240
|
-
const expandKeySet = new Set(expandKeys);
|
|
241
|
-
return dfs(drillTree);
|
|
242
|
-
/** 在 indicators 非空的情况下获取指标对应的 CrossTreeNode */
|
|
243
|
-
function getIndicators(node, nodeData) {
|
|
244
|
-
return indicators.map((indicator) => (Object.assign({ key: encode(node.path.concat([indicator.code])), value: indicator.name, data: Object.assign(Object.assign({}, nodeData), { indicator }) }, indicator)));
|
|
245
|
-
}
|
|
246
|
-
function drillNodeToTreeNode(node, nodeData) {
|
|
247
|
-
if (indicators != null) {
|
|
248
|
-
return {
|
|
249
|
-
key: node.key,
|
|
250
|
-
value: node.value,
|
|
251
|
-
data: nodeData,
|
|
252
|
-
children: getIndicators(node, nodeData),
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
else {
|
|
256
|
-
return {
|
|
257
|
-
key: node.key,
|
|
258
|
-
value: node.value,
|
|
259
|
-
data: nodeData,
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
function dfs(drillNodes, depth) {
|
|
264
|
-
const result = [];
|
|
265
|
-
for (const node of drillNodes) {
|
|
266
|
-
const nodeData = { dataKey: node.key, dataPath: node.path };
|
|
267
|
-
if (isLeafNode(node) && !node.hasChild) {
|
|
268
|
-
result.push(drillNodeToTreeNode(node, nodeData));
|
|
269
|
-
}
|
|
270
|
-
else {
|
|
271
|
-
let needProcessChildren = true;
|
|
272
|
-
let crossTreeNode = {
|
|
273
|
-
key: node.key,
|
|
274
|
-
value: node.value,
|
|
275
|
-
data: nodeData,
|
|
276
|
-
};
|
|
277
|
-
if (!supportsExpand || (enforceExpandTotalNode && node.key === totalKey)) {
|
|
278
|
-
// 不支持展开功能 或是强制展开
|
|
279
|
-
crossTreeNode.children = dfs(node.children);
|
|
280
|
-
}
|
|
281
|
-
else if (expandKeySet.has(node.key)) {
|
|
282
|
-
// 展开的父节点
|
|
283
|
-
// @ts-ignore
|
|
284
|
-
crossTreeNode.title = (React.createElement(ExpandSpan, { onClick: () => {
|
|
285
|
-
onChangeExpandKeys(expandKeys.filter((k) => k !== node.key), node, 'collapse');
|
|
286
|
-
} },
|
|
287
|
-
React.createElement(icons.CaretRight, { className: "icon expanded" }),
|
|
288
|
-
node.value));
|
|
289
|
-
crossTreeNode.children = dfs(node.children);
|
|
290
|
-
}
|
|
291
|
-
else {
|
|
292
|
-
// 收拢的父节点
|
|
293
|
-
needProcessChildren = false;
|
|
294
|
-
crossTreeNode.title = (React.createElement(ExpandSpan, { onClick: () => {
|
|
295
|
-
onChangeExpandKeys(expandKeys.concat([node.key]), node, 'expand');
|
|
296
|
-
} },
|
|
297
|
-
React.createElement(icons.CaretRight, { className: "icon collapsed" }),
|
|
298
|
-
node.value));
|
|
299
|
-
if (indicators != null) {
|
|
300
|
-
crossTreeNode.children = getIndicators(node, nodeData);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
if (needProcessChildren) {
|
|
304
|
-
const subtotalNodeData = generateSubtotalNode === null || generateSubtotalNode === void 0 ? void 0 : generateSubtotalNode(node);
|
|
305
|
-
if (subtotalNodeData) {
|
|
306
|
-
const { position = 'start', value } = subtotalNodeData;
|
|
307
|
-
const subtotalPath = node.path.concat([value]);
|
|
308
|
-
const subtotalDrillNode = {
|
|
309
|
-
key: encode(subtotalPath),
|
|
310
|
-
path: subtotalPath,
|
|
311
|
-
value,
|
|
312
|
-
};
|
|
313
|
-
const subtotalTreeNode = drillNodeToTreeNode(subtotalDrillNode, nodeData);
|
|
314
|
-
if (position === 'start') {
|
|
315
|
-
crossTreeNode.children.unshift(subtotalTreeNode);
|
|
316
|
-
}
|
|
317
|
-
else {
|
|
318
|
-
crossTreeNode.children.push(subtotalTreeNode);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
result.push(crossTreeNode);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
return result;
|
|
326
|
-
}
|
|
234
|
+
`;
|
|
235
|
+
function convertDrillTreeToCrossTree(drillTree, { indicators, encode = simpleEncode, generateSubtotalNode, enforceExpandTotalNode = true, expandKeys, onChangeExpandKeys = noop, supportsExpand, } = {}) {
|
|
236
|
+
const totalKey = encode([]);
|
|
237
|
+
if (supportsExpand && expandKeys == null) {
|
|
238
|
+
throw new Error('[srp-table] convertDrillTreeToCrossTree(...) 设置 supportsExpand=true 时,expandKeys 不能为 null/undefined.');
|
|
239
|
+
}
|
|
240
|
+
const expandKeySet = new Set(expandKeys);
|
|
241
|
+
return dfs(drillTree);
|
|
242
|
+
/** 在 indicators 非空的情况下获取指标对应的 CrossTreeNode */
|
|
243
|
+
function getIndicators(node, nodeData) {
|
|
244
|
+
return indicators.map((indicator) => (Object.assign({ key: encode(node.path.concat([indicator.code])), value: indicator.name, data: Object.assign(Object.assign({}, nodeData), { indicator }) }, indicator)));
|
|
245
|
+
}
|
|
246
|
+
function drillNodeToTreeNode(node, nodeData) {
|
|
247
|
+
if (indicators != null) {
|
|
248
|
+
return {
|
|
249
|
+
key: node.key,
|
|
250
|
+
value: node.value,
|
|
251
|
+
data: nodeData,
|
|
252
|
+
children: getIndicators(node, nodeData),
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
return {
|
|
257
|
+
key: node.key,
|
|
258
|
+
value: node.value,
|
|
259
|
+
data: nodeData,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
function dfs(drillNodes, depth) {
|
|
264
|
+
const result = [];
|
|
265
|
+
for (const node of drillNodes) {
|
|
266
|
+
const nodeData = { dataKey: node.key, dataPath: node.path };
|
|
267
|
+
if (isLeafNode(node) && !node.hasChild) {
|
|
268
|
+
result.push(drillNodeToTreeNode(node, nodeData));
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
let needProcessChildren = true;
|
|
272
|
+
let crossTreeNode = {
|
|
273
|
+
key: node.key,
|
|
274
|
+
value: node.value,
|
|
275
|
+
data: nodeData,
|
|
276
|
+
};
|
|
277
|
+
if (!supportsExpand || (enforceExpandTotalNode && node.key === totalKey)) {
|
|
278
|
+
// 不支持展开功能 或是强制展开
|
|
279
|
+
crossTreeNode.children = dfs(node.children);
|
|
280
|
+
}
|
|
281
|
+
else if (expandKeySet.has(node.key)) {
|
|
282
|
+
// 展开的父节点
|
|
283
|
+
// @ts-ignore
|
|
284
|
+
crossTreeNode.title = (React.createElement(ExpandSpan, { onClick: () => {
|
|
285
|
+
onChangeExpandKeys(expandKeys.filter((k) => k !== node.key), node, 'collapse');
|
|
286
|
+
} },
|
|
287
|
+
React.createElement(icons.CaretRight, { className: "icon expanded" }),
|
|
288
|
+
node.value));
|
|
289
|
+
crossTreeNode.children = dfs(node.children);
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
// 收拢的父节点
|
|
293
|
+
needProcessChildren = false;
|
|
294
|
+
crossTreeNode.title = (React.createElement(ExpandSpan, { onClick: () => {
|
|
295
|
+
onChangeExpandKeys(expandKeys.concat([node.key]), node, 'expand');
|
|
296
|
+
} },
|
|
297
|
+
React.createElement(icons.CaretRight, { className: "icon collapsed" }),
|
|
298
|
+
node.value));
|
|
299
|
+
if (indicators != null) {
|
|
300
|
+
crossTreeNode.children = getIndicators(node, nodeData);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
if (needProcessChildren) {
|
|
304
|
+
const subtotalNodeData = generateSubtotalNode === null || generateSubtotalNode === void 0 ? void 0 : generateSubtotalNode(node);
|
|
305
|
+
if (subtotalNodeData) {
|
|
306
|
+
const { position = 'start', value } = subtotalNodeData;
|
|
307
|
+
const subtotalPath = node.path.concat([value]);
|
|
308
|
+
const subtotalDrillNode = {
|
|
309
|
+
key: encode(subtotalPath),
|
|
310
|
+
path: subtotalPath,
|
|
311
|
+
value,
|
|
312
|
+
};
|
|
313
|
+
const subtotalTreeNode = drillNodeToTreeNode(subtotalDrillNode, nodeData);
|
|
314
|
+
if (position === 'start') {
|
|
315
|
+
crossTreeNode.children.unshift(subtotalTreeNode);
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
crossTreeNode.children.push(subtotalTreeNode);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
result.push(crossTreeNode);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return result;
|
|
326
|
+
}
|
|
327
327
|
}
|
|
328
328
|
|
|
329
329
|
const ROW_KEY = 'rowKey';
|
|
330
330
|
|
|
331
|
-
function buildCrossTable(options) {
|
|
332
|
-
var _a, _b, _c, _d, _e, _f;
|
|
333
|
-
const { leftTotalNode, topTotalNode } = options;
|
|
334
|
-
const columnOffset = (_a = options.columnOffset) !== null && _a !== void 0 ? _a : 0;
|
|
335
|
-
const rowOffset = (_b = options.rowOffset) !== null && _b !== void 0 ? _b : 0;
|
|
336
|
-
const hasOffset = columnOffset !== 0 || rowOffset !== 0;
|
|
337
|
-
// 有的时候 leftTree/topTree 是通过 node.children 传入的
|
|
338
|
-
// 此时 leftTree/topTree 等于 null 和等于空数组是等价的
|
|
339
|
-
// 故在这里兼容 leftTree/topTree 为空的情况
|
|
340
|
-
const leftTree = (_c = options.leftTree) !== null && _c !== void 0 ? _c : [];
|
|
341
|
-
const topTree = (_d = options.topTree) !== null && _d !== void 0 ? _d : [];
|
|
342
|
-
const getValue = (_e = options.getValue) !== null && _e !== void 0 ? _e : always(null);
|
|
343
|
-
const leftMetaColumns = (_f = options.leftMetaColumns) !== null && _f !== void 0 ? _f : [];
|
|
344
|
-
const leftHeaderWidth = Math.max(leftMetaColumns.length, getTreeDepth(leftTree) + 1);
|
|
345
|
-
return {
|
|
346
|
-
columns: getColumns(),
|
|
347
|
-
dataSource: getDataSource(),
|
|
348
|
-
};
|
|
349
|
-
/** 获取表格的列配置 */
|
|
350
|
-
function getColumns() {
|
|
351
|
-
return [...getLeftPartColumns(), ...getDataPartColumns()];
|
|
352
|
-
function getLeftPartColumns() {
|
|
353
|
-
var _a;
|
|
354
|
-
const leftPartColumns = [];
|
|
355
|
-
for (let index = 0; index < leftHeaderWidth; index++) {
|
|
356
|
-
const metaCol = (_a = leftMetaColumns[index]) !== null && _a !== void 0 ? _a : {};
|
|
357
|
-
const staticMetaColConfig = __rest(metaCol, ["getCellProps", "render"]);
|
|
358
|
-
leftPartColumns.push(Object.assign(Object.assign({ columnType: 'left', lock: true }, staticMetaColConfig), { getCellProps: leftHeaderGetCellPropsFactory(metaCol, index), getSpanRect: leftHeaderGetSpanRectFactory(metaCol, index), getValue: leftHeaderGetValueFactory(metaCol, index), render: leftHeaderRenderFactory(metaCol, index) }));
|
|
359
|
-
}
|
|
360
|
-
return leftPartColumns;
|
|
361
|
-
function leftHeaderGetCellPropsFactory(metaCol, colIndex) {
|
|
362
|
-
return (_value, row, rowIndex) => {
|
|
363
|
-
var _a;
|
|
364
|
-
const node = row.nodes[colIndex];
|
|
365
|
-
return (_a = metaCol.getCellProps) === null || _a === void 0 ? void 0 : _a.call(metaCol, node, colIndex);
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
function leftHeaderGetSpanRectFactory(metaCol, colIndex) {
|
|
369
|
-
return (_value, row) => {
|
|
370
|
-
const rect = row.rects[colIndex];
|
|
371
|
-
if (hasOffset) {
|
|
372
|
-
return {
|
|
373
|
-
left: rect.left + columnOffset,
|
|
374
|
-
right: rect.right + columnOffset,
|
|
375
|
-
top: rect.top + rowOffset,
|
|
376
|
-
bottom: rect.bottom + rowOffset,
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
return rect;
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
function leftHeaderGetValueFactory(metaCol, colIndex) {
|
|
383
|
-
return (row, rowIndex) => {
|
|
384
|
-
const node = row.nodes[colIndex];
|
|
385
|
-
return node.value;
|
|
386
|
-
};
|
|
387
|
-
}
|
|
388
|
-
function leftHeaderRenderFactory(metaCol, colIndex) {
|
|
389
|
-
return (v, row, rowIndex) => {
|
|
390
|
-
var _a;
|
|
391
|
-
const node = row.nodes[colIndex];
|
|
392
|
-
if (metaCol.render) {
|
|
393
|
-
return metaCol.render(node, colIndex);
|
|
394
|
-
}
|
|
395
|
-
return (_a = node.title) !== null && _a !== void 0 ? _a : node.value;
|
|
396
|
-
};
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
/** 获取表格数据部分的列配置 */
|
|
400
|
-
function getDataPartColumns() {
|
|
401
|
-
if (topTree.length > 0) {
|
|
402
|
-
return dfs(topTree, { valuePath: [], depth: 0 });
|
|
403
|
-
}
|
|
404
|
-
else if (topTotalNode) {
|
|
405
|
-
return dfs([topTotalNode], { valuePath: [], depth: 0 });
|
|
406
|
-
}
|
|
407
|
-
else {
|
|
408
|
-
return [];
|
|
409
|
-
}
|
|
410
|
-
function dfs(nodes, ctx) {
|
|
411
|
-
const result = [];
|
|
412
|
-
for (const node of nodes) {
|
|
413
|
-
ctx.valuePath.push(node.value);
|
|
414
|
-
if (isLeafNode(node)) {
|
|
415
|
-
// 叶子节点
|
|
416
|
-
result.push(getDataColumn(node, ctx.depth));
|
|
417
|
-
}
|
|
418
|
-
else {
|
|
419
|
-
const { key, value, children } = node, others = __rest(node
|
|
420
|
-
// 强制展开的节点
|
|
421
|
-
, ["key", "value", "children"]);
|
|
422
|
-
// 强制展开的节点
|
|
423
|
-
result.push(Object.assign(Object.assign({ columnType: 'data-parent' }, others), { name: value, children: dfs(children, { valuePath: ctx.valuePath, depth: ctx.depth + 1 }) }));
|
|
424
|
-
}
|
|
425
|
-
ctx.valuePath.pop();
|
|
426
|
-
}
|
|
427
|
-
return result;
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
function getDataColumn(topNode, topDepth) {
|
|
431
|
-
const columnGetValue = (row) => {
|
|
432
|
-
const leftDepth = row.nodes.length - 1;
|
|
433
|
-
const leftNode = row.nodes[leftDepth];
|
|
434
|
-
return getValue(leftNode, topNode, leftDepth, topDepth);
|
|
435
|
-
};
|
|
436
|
-
const { key, value, children } = topNode, others = __rest(topNode, ["key", "value", "children"]);
|
|
437
|
-
return Object.assign(Object.assign({ columnType: 'data' }, others), { getValue: columnGetValue, name: value, children: null, render(value, row) {
|
|
438
|
-
if (options.render) {
|
|
439
|
-
const leftDepth = row.nodes.length - 1;
|
|
440
|
-
const leftNode = row.nodes[leftDepth];
|
|
441
|
-
return options.render(value, leftNode, topNode, leftDepth, topDepth);
|
|
442
|
-
}
|
|
443
|
-
return value;
|
|
444
|
-
},
|
|
445
|
-
getCellProps(value, row) {
|
|
446
|
-
if (options.getCellProps) {
|
|
447
|
-
const leftDepth = row.nodes.length - 1;
|
|
448
|
-
const leftNode = row.nodes[leftDepth];
|
|
449
|
-
return options.getCellProps(value, leftNode, topNode, leftDepth, topDepth);
|
|
450
|
-
}
|
|
451
|
-
} });
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
function getDataSource() {
|
|
455
|
-
const flatRows = [];
|
|
456
|
-
const ctx = { depth: 0, nodes: [], rects: [], rowIndex: 0 };
|
|
457
|
-
if (leftTree.length > 0) {
|
|
458
|
-
dfs(leftTree, ctx);
|
|
459
|
-
}
|
|
460
|
-
else if (leftTotalNode) {
|
|
461
|
-
dfs([leftTotalNode], ctx);
|
|
462
|
-
} // else 表格没有行,展示空表格
|
|
463
|
-
return flatRows;
|
|
464
|
-
function dfs(nodes, ctx) {
|
|
465
|
-
let count = 0;
|
|
466
|
-
for (const node of nodes) {
|
|
467
|
-
if (node.hidden) {
|
|
468
|
-
// 跳过被隐藏的节点
|
|
469
|
-
continue;
|
|
470
|
-
}
|
|
471
|
-
const rect = {
|
|
472
|
-
top: ctx.rowIndex + count,
|
|
473
|
-
bottom: -1,
|
|
474
|
-
left: ctx.depth,
|
|
475
|
-
right: -1, // 会在 dfs 之后算出结果
|
|
476
|
-
};
|
|
477
|
-
const row = {
|
|
478
|
-
[ROW_KEY]: node.key,
|
|
479
|
-
rects: [...ctx.rects, rect],
|
|
480
|
-
nodes: [...ctx.nodes, node],
|
|
481
|
-
};
|
|
482
|
-
if (isLeafNode(node)) {
|
|
483
|
-
rect.right = leftHeaderWidth;
|
|
484
|
-
rect.bottom = rect.top + 1;
|
|
485
|
-
flatRows.push(row);
|
|
486
|
-
count += 1;
|
|
487
|
-
}
|
|
488
|
-
else {
|
|
489
|
-
ctx.rects.push(rect);
|
|
490
|
-
ctx.nodes.push(node);
|
|
491
|
-
const ret = dfs(node.children, {
|
|
492
|
-
nodes: ctx.nodes,
|
|
493
|
-
rects: ctx.rects,
|
|
494
|
-
depth: ctx.depth + 1,
|
|
495
|
-
rowIndex: ctx.rowIndex + count,
|
|
496
|
-
});
|
|
497
|
-
ctx.rects.pop();
|
|
498
|
-
ctx.nodes.pop();
|
|
499
|
-
count += ret.count;
|
|
500
|
-
rect.right = rect.left + 1;
|
|
501
|
-
rect.bottom = rect.top + ret.count;
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
return { count };
|
|
505
|
-
}
|
|
506
|
-
}
|
|
331
|
+
function buildCrossTable(options) {
|
|
332
|
+
var _a, _b, _c, _d, _e, _f;
|
|
333
|
+
const { leftTotalNode, topTotalNode } = options;
|
|
334
|
+
const columnOffset = (_a = options.columnOffset) !== null && _a !== void 0 ? _a : 0;
|
|
335
|
+
const rowOffset = (_b = options.rowOffset) !== null && _b !== void 0 ? _b : 0;
|
|
336
|
+
const hasOffset = columnOffset !== 0 || rowOffset !== 0;
|
|
337
|
+
// 有的时候 leftTree/topTree 是通过 node.children 传入的
|
|
338
|
+
// 此时 leftTree/topTree 等于 null 和等于空数组是等价的
|
|
339
|
+
// 故在这里兼容 leftTree/topTree 为空的情况
|
|
340
|
+
const leftTree = (_c = options.leftTree) !== null && _c !== void 0 ? _c : [];
|
|
341
|
+
const topTree = (_d = options.topTree) !== null && _d !== void 0 ? _d : [];
|
|
342
|
+
const getValue = (_e = options.getValue) !== null && _e !== void 0 ? _e : always(null);
|
|
343
|
+
const leftMetaColumns = (_f = options.leftMetaColumns) !== null && _f !== void 0 ? _f : [];
|
|
344
|
+
const leftHeaderWidth = Math.max(leftMetaColumns.length, getTreeDepth(leftTree) + 1);
|
|
345
|
+
return {
|
|
346
|
+
columns: getColumns(),
|
|
347
|
+
dataSource: getDataSource(),
|
|
348
|
+
};
|
|
349
|
+
/** 获取表格的列配置 */
|
|
350
|
+
function getColumns() {
|
|
351
|
+
return [...getLeftPartColumns(), ...getDataPartColumns()];
|
|
352
|
+
function getLeftPartColumns() {
|
|
353
|
+
var _a;
|
|
354
|
+
const leftPartColumns = [];
|
|
355
|
+
for (let index = 0; index < leftHeaderWidth; index++) {
|
|
356
|
+
const metaCol = (_a = leftMetaColumns[index]) !== null && _a !== void 0 ? _a : {};
|
|
357
|
+
const staticMetaColConfig = __rest(metaCol, ["getCellProps", "render"]);
|
|
358
|
+
leftPartColumns.push(Object.assign(Object.assign({ columnType: 'left', lock: true }, staticMetaColConfig), { getCellProps: leftHeaderGetCellPropsFactory(metaCol, index), getSpanRect: leftHeaderGetSpanRectFactory(metaCol, index), getValue: leftHeaderGetValueFactory(metaCol, index), render: leftHeaderRenderFactory(metaCol, index) }));
|
|
359
|
+
}
|
|
360
|
+
return leftPartColumns;
|
|
361
|
+
function leftHeaderGetCellPropsFactory(metaCol, colIndex) {
|
|
362
|
+
return (_value, row, rowIndex) => {
|
|
363
|
+
var _a;
|
|
364
|
+
const node = row.nodes[colIndex];
|
|
365
|
+
return (_a = metaCol.getCellProps) === null || _a === void 0 ? void 0 : _a.call(metaCol, node, colIndex);
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
function leftHeaderGetSpanRectFactory(metaCol, colIndex) {
|
|
369
|
+
return (_value, row) => {
|
|
370
|
+
const rect = row.rects[colIndex];
|
|
371
|
+
if (hasOffset) {
|
|
372
|
+
return {
|
|
373
|
+
left: rect.left + columnOffset,
|
|
374
|
+
right: rect.right + columnOffset,
|
|
375
|
+
top: rect.top + rowOffset,
|
|
376
|
+
bottom: rect.bottom + rowOffset,
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
return rect;
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
function leftHeaderGetValueFactory(metaCol, colIndex) {
|
|
383
|
+
return (row, rowIndex) => {
|
|
384
|
+
const node = row.nodes[colIndex];
|
|
385
|
+
return node.value;
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
function leftHeaderRenderFactory(metaCol, colIndex) {
|
|
389
|
+
return (v, row, rowIndex) => {
|
|
390
|
+
var _a;
|
|
391
|
+
const node = row.nodes[colIndex];
|
|
392
|
+
if (metaCol.render) {
|
|
393
|
+
return metaCol.render(node, colIndex);
|
|
394
|
+
}
|
|
395
|
+
return (_a = node.title) !== null && _a !== void 0 ? _a : node.value;
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
/** 获取表格数据部分的列配置 */
|
|
400
|
+
function getDataPartColumns() {
|
|
401
|
+
if (topTree.length > 0) {
|
|
402
|
+
return dfs(topTree, { valuePath: [], depth: 0 });
|
|
403
|
+
}
|
|
404
|
+
else if (topTotalNode) {
|
|
405
|
+
return dfs([topTotalNode], { valuePath: [], depth: 0 });
|
|
406
|
+
}
|
|
407
|
+
else {
|
|
408
|
+
return [];
|
|
409
|
+
}
|
|
410
|
+
function dfs(nodes, ctx) {
|
|
411
|
+
const result = [];
|
|
412
|
+
for (const node of nodes) {
|
|
413
|
+
ctx.valuePath.push(node.value);
|
|
414
|
+
if (isLeafNode(node)) {
|
|
415
|
+
// 叶子节点
|
|
416
|
+
result.push(getDataColumn(node, ctx.depth));
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
const { key, value, children } = node, others = __rest(node
|
|
420
|
+
// 强制展开的节点
|
|
421
|
+
, ["key", "value", "children"]);
|
|
422
|
+
// 强制展开的节点
|
|
423
|
+
result.push(Object.assign(Object.assign({ columnType: 'data-parent' }, others), { name: value, children: dfs(children, { valuePath: ctx.valuePath, depth: ctx.depth + 1 }) }));
|
|
424
|
+
}
|
|
425
|
+
ctx.valuePath.pop();
|
|
426
|
+
}
|
|
427
|
+
return result;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
function getDataColumn(topNode, topDepth) {
|
|
431
|
+
const columnGetValue = (row) => {
|
|
432
|
+
const leftDepth = row.nodes.length - 1;
|
|
433
|
+
const leftNode = row.nodes[leftDepth];
|
|
434
|
+
return getValue(leftNode, topNode, leftDepth, topDepth);
|
|
435
|
+
};
|
|
436
|
+
const { key, value, children } = topNode, others = __rest(topNode, ["key", "value", "children"]);
|
|
437
|
+
return Object.assign(Object.assign({ columnType: 'data' }, others), { getValue: columnGetValue, name: value, children: null, render(value, row) {
|
|
438
|
+
if (options.render) {
|
|
439
|
+
const leftDepth = row.nodes.length - 1;
|
|
440
|
+
const leftNode = row.nodes[leftDepth];
|
|
441
|
+
return options.render(value, leftNode, topNode, leftDepth, topDepth);
|
|
442
|
+
}
|
|
443
|
+
return value;
|
|
444
|
+
},
|
|
445
|
+
getCellProps(value, row) {
|
|
446
|
+
if (options.getCellProps) {
|
|
447
|
+
const leftDepth = row.nodes.length - 1;
|
|
448
|
+
const leftNode = row.nodes[leftDepth];
|
|
449
|
+
return options.getCellProps(value, leftNode, topNode, leftDepth, topDepth);
|
|
450
|
+
}
|
|
451
|
+
} });
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
function getDataSource() {
|
|
455
|
+
const flatRows = [];
|
|
456
|
+
const ctx = { depth: 0, nodes: [], rects: [], rowIndex: 0 };
|
|
457
|
+
if (leftTree.length > 0) {
|
|
458
|
+
dfs(leftTree, ctx);
|
|
459
|
+
}
|
|
460
|
+
else if (leftTotalNode) {
|
|
461
|
+
dfs([leftTotalNode], ctx);
|
|
462
|
+
} // else 表格没有行,展示空表格
|
|
463
|
+
return flatRows;
|
|
464
|
+
function dfs(nodes, ctx) {
|
|
465
|
+
let count = 0;
|
|
466
|
+
for (const node of nodes) {
|
|
467
|
+
if (node.hidden) {
|
|
468
|
+
// 跳过被隐藏的节点
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
const rect = {
|
|
472
|
+
top: ctx.rowIndex + count,
|
|
473
|
+
bottom: -1, // 会在 dfs 之后算出结果
|
|
474
|
+
left: ctx.depth,
|
|
475
|
+
right: -1, // 会在 dfs 之后算出结果
|
|
476
|
+
};
|
|
477
|
+
const row = {
|
|
478
|
+
[ROW_KEY]: node.key,
|
|
479
|
+
rects: [...ctx.rects, rect],
|
|
480
|
+
nodes: [...ctx.nodes, node],
|
|
481
|
+
};
|
|
482
|
+
if (isLeafNode(node)) {
|
|
483
|
+
rect.right = leftHeaderWidth;
|
|
484
|
+
rect.bottom = rect.top + 1;
|
|
485
|
+
flatRows.push(row);
|
|
486
|
+
count += 1;
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
ctx.rects.push(rect);
|
|
490
|
+
ctx.nodes.push(node);
|
|
491
|
+
const ret = dfs(node.children, {
|
|
492
|
+
nodes: ctx.nodes,
|
|
493
|
+
rects: ctx.rects,
|
|
494
|
+
depth: ctx.depth + 1,
|
|
495
|
+
rowIndex: ctx.rowIndex + count,
|
|
496
|
+
});
|
|
497
|
+
ctx.rects.pop();
|
|
498
|
+
ctx.nodes.pop();
|
|
499
|
+
count += ret.count;
|
|
500
|
+
rect.right = rect.left + 1;
|
|
501
|
+
rect.bottom = rect.top + ret.count;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
return { count };
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
507
|
}
|
|
508
508
|
|
|
509
|
-
function CrossTable(_a) {
|
|
510
|
-
var { BaseTableComponent = BaseTable, leftTree, leftTotalNode, topTree, topTotalNode, getValue, getCellProps, leftMetaColumns, render, baseTableRef } = _a, others = __rest(_a, ["BaseTableComponent", "leftTree", "leftTotalNode", "topTree", "topTotalNode", "getValue", "getCellProps", "leftMetaColumns", "render", "baseTableRef"]);
|
|
511
|
-
const { dataSource, columns } = buildCrossTable({
|
|
512
|
-
leftTree,
|
|
513
|
-
topTree,
|
|
514
|
-
leftTotalNode,
|
|
515
|
-
topTotalNode,
|
|
516
|
-
getValue,
|
|
517
|
-
getCellProps,
|
|
518
|
-
render,
|
|
519
|
-
leftMetaColumns,
|
|
520
|
-
});
|
|
521
|
-
return (React.createElement(BaseTableComponent, Object.assign({ ref: baseTableRef }, others, { primaryKey: ROW_KEY, dataSource: dataSource, columns: columns })));
|
|
509
|
+
function CrossTable(_a) {
|
|
510
|
+
var { BaseTableComponent = BaseTable, leftTree, leftTotalNode, topTree, topTotalNode, getValue, getCellProps, leftMetaColumns, render, baseTableRef } = _a, others = __rest(_a, ["BaseTableComponent", "leftTree", "leftTotalNode", "topTree", "topTotalNode", "getValue", "getCellProps", "leftMetaColumns", "render", "baseTableRef"]);
|
|
511
|
+
const { dataSource, columns } = buildCrossTable({
|
|
512
|
+
leftTree,
|
|
513
|
+
topTree,
|
|
514
|
+
leftTotalNode,
|
|
515
|
+
topTotalNode,
|
|
516
|
+
getValue,
|
|
517
|
+
getCellProps,
|
|
518
|
+
render,
|
|
519
|
+
leftMetaColumns,
|
|
520
|
+
});
|
|
521
|
+
return (React.createElement(BaseTableComponent, Object.assign({ ref: baseTableRef }, others, { primaryKey: ROW_KEY, dataSource: dataSource, columns: columns })));
|
|
522
522
|
}
|
|
523
523
|
|
|
524
|
-
function buildCrossTreeTable(options) {
|
|
525
|
-
var _a, _b;
|
|
526
|
-
const { primaryColumn = { name: '' }, openKeys, onChangeOpenKeys, indentSize, isLeafNode: isLeafNodeOpt = isLeafNode, } = options;
|
|
527
|
-
// 有的时候 leftTree/topTree 是通过 node.children 传入的
|
|
528
|
-
// 此时 leftTree/topTree 等于 null 和等于空数组是等价的
|
|
529
|
-
// 故在这里兼容 leftTree/topTree 为空的情况
|
|
530
|
-
const leftTree = (_a = options.leftTree) !== null && _a !== void 0 ? _a : [];
|
|
531
|
-
const topTree = (_b = options.topTree) !== null && _b !== void 0 ? _b : [];
|
|
532
|
-
const pipeline = new TablePipeline({
|
|
533
|
-
state: {},
|
|
534
|
-
setState: noop,
|
|
535
|
-
ctx: { primaryKey: ROW_KEY },
|
|
536
|
-
});
|
|
537
|
-
pipeline.input({ dataSource: getDataSource(), columns: getColumns() });
|
|
538
|
-
pipeline.use(treeMode({
|
|
539
|
-
openKeys,
|
|
540
|
-
onChangeOpenKeys,
|
|
541
|
-
indentSize,
|
|
542
|
-
isLeafNode(row, nodeMeta) {
|
|
543
|
-
// 调用上层 isLeafNodeOpt 时,会从 row.node 中读取该表格行对应的 leftTreeNode
|
|
544
|
-
return isLeafNodeOpt(row.node, nodeMeta);
|
|
545
|
-
},
|
|
546
|
-
}));
|
|
547
|
-
return {
|
|
548
|
-
dataSource: pipeline.getDataSource(),
|
|
549
|
-
columns: pipeline.getColumns(),
|
|
550
|
-
};
|
|
551
|
-
/** 获取表格的列配置 */
|
|
552
|
-
function getColumns() {
|
|
553
|
-
return [
|
|
554
|
-
Object.assign(Object.assign({}, primaryColumn), { getValue(row) {
|
|
555
|
-
return row.node.value;
|
|
556
|
-
},
|
|
557
|
-
getCellProps(value, row) {
|
|
558
|
-
if (primaryColumn.getCellProps) {
|
|
559
|
-
return primaryColumn.getCellProps(row.node, row.nodes.length - 1);
|
|
560
|
-
}
|
|
561
|
-
},
|
|
562
|
-
render(value, row) {
|
|
563
|
-
if (primaryColumn.render) {
|
|
564
|
-
return primaryColumn.render(row.node, row.nodes.length - 1);
|
|
565
|
-
}
|
|
566
|
-
return value;
|
|
567
|
-
} }),
|
|
568
|
-
...getDataPartColumns(),
|
|
569
|
-
];
|
|
570
|
-
/** 获取表格数据部分的列配置 */
|
|
571
|
-
function getDataPartColumns() {
|
|
572
|
-
return dfs(topTree, { depth: 0 });
|
|
573
|
-
function dfs(nodes, ctx) {
|
|
574
|
-
const result = [];
|
|
575
|
-
for (const node of nodes) {
|
|
576
|
-
if (isLeafNode(node)) {
|
|
577
|
-
result.push(getDataColumn(node, ctx.depth));
|
|
578
|
-
}
|
|
579
|
-
else {
|
|
580
|
-
const { key, value, children } = node, others = __rest(node, ["key", "value", "children"]);
|
|
581
|
-
result.push(Object.assign(Object.assign({}, others), { name: value, children: dfs(children, { depth: ctx.depth + 1 }) }));
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
return result;
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
function getDataColumn(topNode, topDepth) {
|
|
588
|
-
const columnGetValue = (row) => {
|
|
589
|
-
const leftDepth = row.nodes.length - 1;
|
|
590
|
-
const leftNode = row.node;
|
|
591
|
-
if (options.getValue) {
|
|
592
|
-
return options.getValue(leftNode, topNode, leftDepth, topDepth);
|
|
593
|
-
}
|
|
594
|
-
return null;
|
|
595
|
-
};
|
|
596
|
-
const { key, value, children } = topNode, others = __rest(topNode, ["key", "value", "children"]);
|
|
597
|
-
return Object.assign(Object.assign({}, others), { getValue: columnGetValue, name: value, children: null, render(value, row) {
|
|
598
|
-
if (options.render) {
|
|
599
|
-
const leftDepth = row.nodes.length - 1;
|
|
600
|
-
const leftNode = row.node;
|
|
601
|
-
return options.render(value, leftNode, topNode, leftDepth, topDepth);
|
|
602
|
-
}
|
|
603
|
-
return value;
|
|
604
|
-
},
|
|
605
|
-
getCellProps(value, row) {
|
|
606
|
-
if (options.getCellProps) {
|
|
607
|
-
const leftDepth = row.nodes.length - 1;
|
|
608
|
-
const leftNode = row.node;
|
|
609
|
-
return options.getCellProps(value, leftNode, topNode, leftDepth, topDepth);
|
|
610
|
-
}
|
|
611
|
-
} });
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
function getDataSource() {
|
|
615
|
-
return dfs(leftTree, { nodes: [] });
|
|
616
|
-
function dfs(nodes, ctx) {
|
|
617
|
-
const result = [];
|
|
618
|
-
for (const node of nodes) {
|
|
619
|
-
if (node.hidden) {
|
|
620
|
-
// 跳过被隐藏的节点
|
|
621
|
-
continue;
|
|
622
|
-
}
|
|
623
|
-
if (isLeafNode(node)) {
|
|
624
|
-
result.push({
|
|
625
|
-
[ROW_KEY]: node.key,
|
|
626
|
-
node,
|
|
627
|
-
nodes: [...ctx.nodes, node],
|
|
628
|
-
});
|
|
629
|
-
}
|
|
630
|
-
else {
|
|
631
|
-
const nodes = [...ctx.nodes, node];
|
|
632
|
-
ctx.nodes.push(node);
|
|
633
|
-
const children = dfs(node.children, ctx);
|
|
634
|
-
result.push({ [ROW_KEY]: node.key, node, nodes, children });
|
|
635
|
-
ctx.nodes.pop();
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
return result;
|
|
639
|
-
}
|
|
640
|
-
}
|
|
524
|
+
function buildCrossTreeTable(options) {
|
|
525
|
+
var _a, _b;
|
|
526
|
+
const { primaryColumn = { name: '' }, openKeys, onChangeOpenKeys, indentSize, isLeafNode: isLeafNodeOpt = isLeafNode, } = options;
|
|
527
|
+
// 有的时候 leftTree/topTree 是通过 node.children 传入的
|
|
528
|
+
// 此时 leftTree/topTree 等于 null 和等于空数组是等价的
|
|
529
|
+
// 故在这里兼容 leftTree/topTree 为空的情况
|
|
530
|
+
const leftTree = (_a = options.leftTree) !== null && _a !== void 0 ? _a : [];
|
|
531
|
+
const topTree = (_b = options.topTree) !== null && _b !== void 0 ? _b : [];
|
|
532
|
+
const pipeline = new TablePipeline({
|
|
533
|
+
state: {},
|
|
534
|
+
setState: noop,
|
|
535
|
+
ctx: { primaryKey: ROW_KEY },
|
|
536
|
+
});
|
|
537
|
+
pipeline.input({ dataSource: getDataSource(), columns: getColumns() });
|
|
538
|
+
pipeline.use(treeMode({
|
|
539
|
+
openKeys,
|
|
540
|
+
onChangeOpenKeys,
|
|
541
|
+
indentSize,
|
|
542
|
+
isLeafNode(row, nodeMeta) {
|
|
543
|
+
// 调用上层 isLeafNodeOpt 时,会从 row.node 中读取该表格行对应的 leftTreeNode
|
|
544
|
+
return isLeafNodeOpt(row.node, nodeMeta);
|
|
545
|
+
},
|
|
546
|
+
}));
|
|
547
|
+
return {
|
|
548
|
+
dataSource: pipeline.getDataSource(),
|
|
549
|
+
columns: pipeline.getColumns(),
|
|
550
|
+
};
|
|
551
|
+
/** 获取表格的列配置 */
|
|
552
|
+
function getColumns() {
|
|
553
|
+
return [
|
|
554
|
+
Object.assign(Object.assign({}, primaryColumn), { getValue(row) {
|
|
555
|
+
return row.node.value;
|
|
556
|
+
},
|
|
557
|
+
getCellProps(value, row) {
|
|
558
|
+
if (primaryColumn.getCellProps) {
|
|
559
|
+
return primaryColumn.getCellProps(row.node, row.nodes.length - 1);
|
|
560
|
+
}
|
|
561
|
+
},
|
|
562
|
+
render(value, row) {
|
|
563
|
+
if (primaryColumn.render) {
|
|
564
|
+
return primaryColumn.render(row.node, row.nodes.length - 1);
|
|
565
|
+
}
|
|
566
|
+
return value;
|
|
567
|
+
} }),
|
|
568
|
+
...getDataPartColumns(),
|
|
569
|
+
];
|
|
570
|
+
/** 获取表格数据部分的列配置 */
|
|
571
|
+
function getDataPartColumns() {
|
|
572
|
+
return dfs(topTree, { depth: 0 });
|
|
573
|
+
function dfs(nodes, ctx) {
|
|
574
|
+
const result = [];
|
|
575
|
+
for (const node of nodes) {
|
|
576
|
+
if (isLeafNode(node)) {
|
|
577
|
+
result.push(getDataColumn(node, ctx.depth));
|
|
578
|
+
}
|
|
579
|
+
else {
|
|
580
|
+
const { key, value, children } = node, others = __rest(node, ["key", "value", "children"]);
|
|
581
|
+
result.push(Object.assign(Object.assign({}, others), { name: value, children: dfs(children, { depth: ctx.depth + 1 }) }));
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
return result;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
function getDataColumn(topNode, topDepth) {
|
|
588
|
+
const columnGetValue = (row) => {
|
|
589
|
+
const leftDepth = row.nodes.length - 1;
|
|
590
|
+
const leftNode = row.node;
|
|
591
|
+
if (options.getValue) {
|
|
592
|
+
return options.getValue(leftNode, topNode, leftDepth, topDepth);
|
|
593
|
+
}
|
|
594
|
+
return null;
|
|
595
|
+
};
|
|
596
|
+
const { key, value, children } = topNode, others = __rest(topNode, ["key", "value", "children"]);
|
|
597
|
+
return Object.assign(Object.assign({}, others), { getValue: columnGetValue, name: value, children: null, render(value, row) {
|
|
598
|
+
if (options.render) {
|
|
599
|
+
const leftDepth = row.nodes.length - 1;
|
|
600
|
+
const leftNode = row.node;
|
|
601
|
+
return options.render(value, leftNode, topNode, leftDepth, topDepth);
|
|
602
|
+
}
|
|
603
|
+
return value;
|
|
604
|
+
},
|
|
605
|
+
getCellProps(value, row) {
|
|
606
|
+
if (options.getCellProps) {
|
|
607
|
+
const leftDepth = row.nodes.length - 1;
|
|
608
|
+
const leftNode = row.node;
|
|
609
|
+
return options.getCellProps(value, leftNode, topNode, leftDepth, topDepth);
|
|
610
|
+
}
|
|
611
|
+
} });
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
function getDataSource() {
|
|
615
|
+
return dfs(leftTree, { nodes: [] });
|
|
616
|
+
function dfs(nodes, ctx) {
|
|
617
|
+
const result = [];
|
|
618
|
+
for (const node of nodes) {
|
|
619
|
+
if (node.hidden) {
|
|
620
|
+
// 跳过被隐藏的节点
|
|
621
|
+
continue;
|
|
622
|
+
}
|
|
623
|
+
if (isLeafNode(node)) {
|
|
624
|
+
result.push({
|
|
625
|
+
[ROW_KEY]: node.key,
|
|
626
|
+
node,
|
|
627
|
+
nodes: [...ctx.nodes, node],
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
else {
|
|
631
|
+
const nodes = [...ctx.nodes, node];
|
|
632
|
+
ctx.nodes.push(node);
|
|
633
|
+
const children = dfs(node.children, ctx);
|
|
634
|
+
result.push({ [ROW_KEY]: node.key, node, nodes, children });
|
|
635
|
+
ctx.nodes.pop();
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
return result;
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
641
|
}
|
|
642
642
|
|
|
643
|
-
class CrossTreeTable extends React.Component {
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
this.
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
}
|
|
662
|
-
render() {
|
|
663
|
-
const _a = this.props, { BaseTableComponent = BaseTable, leftTree, topTree, getValue, getCellProps, primaryColumn, render, openKeys: openKeysProp, defaultOpenKeys, onChangeOpenKeys, indentSize, isLeafNode, baseTableRef } = _a, others = __rest(_a, ["BaseTableComponent", "leftTree", "topTree", "getValue", "getCellProps", "primaryColumn", "render", "openKeys", "defaultOpenKeys", "onChangeOpenKeys", "indentSize", "isLeafNode", "baseTableRef"]) // 透传其他 BaseTable 的 props
|
|
664
|
-
;
|
|
665
|
-
const openKeys = openKeysProp !== null && openKeysProp !== void 0 ? openKeysProp : this.state.openKeys;
|
|
666
|
-
const { dataSource, columns } = buildCrossTreeTable({
|
|
667
|
-
leftTree,
|
|
668
|
-
topTree,
|
|
669
|
-
getValue,
|
|
670
|
-
getCellProps,
|
|
671
|
-
render,
|
|
672
|
-
primaryColumn,
|
|
673
|
-
openKeys,
|
|
674
|
-
onChangeOpenKeys: this.onChangeOpenKeys,
|
|
675
|
-
indentSize,
|
|
676
|
-
isLeafNode,
|
|
677
|
-
});
|
|
678
|
-
return (React.createElement(BaseTableComponent, Object.assign({ ref: baseTableRef }, others, { primaryKey: ROW_KEY, dataSource: dataSource, columns: columns })));
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
CrossTreeTable.defaultProps = {
|
|
682
|
-
defaultOpenKeys: [],
|
|
683
|
-
onChangeOpenKeys: noop,
|
|
643
|
+
class CrossTreeTable extends React.Component {
|
|
644
|
+
static getDerivedStateFromProps(nextProps) {
|
|
645
|
+
if ('openKeys' in nextProps) {
|
|
646
|
+
return { openKeys: nextProps.openKeys };
|
|
647
|
+
}
|
|
648
|
+
return null;
|
|
649
|
+
}
|
|
650
|
+
constructor(props) {
|
|
651
|
+
super(props);
|
|
652
|
+
this.onChangeOpenKeys = (nextOpenKeys) => {
|
|
653
|
+
this.props.onChangeOpenKeys(nextOpenKeys);
|
|
654
|
+
if (!('openKeys' in this.props)) {
|
|
655
|
+
this.setState({ openKeys: nextOpenKeys });
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
this.state = {
|
|
659
|
+
openKeys: props.defaultOpenKeys,
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
render() {
|
|
663
|
+
const _a = this.props, { BaseTableComponent = BaseTable, leftTree, topTree, getValue, getCellProps, primaryColumn, render, openKeys: openKeysProp, defaultOpenKeys, onChangeOpenKeys, indentSize, isLeafNode, baseTableRef } = _a, others = __rest(_a, ["BaseTableComponent", "leftTree", "topTree", "getValue", "getCellProps", "primaryColumn", "render", "openKeys", "defaultOpenKeys", "onChangeOpenKeys", "indentSize", "isLeafNode", "baseTableRef"]) // 透传其他 BaseTable 的 props
|
|
664
|
+
;
|
|
665
|
+
const openKeys = openKeysProp !== null && openKeysProp !== void 0 ? openKeysProp : this.state.openKeys;
|
|
666
|
+
const { dataSource, columns } = buildCrossTreeTable({
|
|
667
|
+
leftTree,
|
|
668
|
+
topTree,
|
|
669
|
+
getValue,
|
|
670
|
+
getCellProps,
|
|
671
|
+
render,
|
|
672
|
+
primaryColumn,
|
|
673
|
+
openKeys,
|
|
674
|
+
onChangeOpenKeys: this.onChangeOpenKeys,
|
|
675
|
+
indentSize,
|
|
676
|
+
isLeafNode,
|
|
677
|
+
});
|
|
678
|
+
return (React.createElement(BaseTableComponent, Object.assign({ ref: baseTableRef }, others, { primaryKey: ROW_KEY, dataSource: dataSource, columns: columns })));
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
CrossTreeTable.defaultProps = {
|
|
682
|
+
defaultOpenKeys: [],
|
|
683
|
+
onChangeOpenKeys: noop,
|
|
684
684
|
};
|
|
685
|
+
var CrossTreeTable$1 = CrossTreeTable;
|
|
685
686
|
|
|
686
|
-
export { CrossTable, CrossTreeTable, ROW_KEY, buildCrossTable, buildCrossTreeTable, buildDrillTree, buildRecordMap, buildRecordMatrix, convertDrillTreeToCrossTree, simpleEncode };
|
|
687
|
+
export { CrossTable, CrossTreeTable$1 as CrossTreeTable, ROW_KEY, buildCrossTable, buildCrossTreeTable, buildDrillTree, buildRecordMap, buildRecordMatrix, convertDrillTreeToCrossTree, simpleEncode };
|