@hzab/list-render 1.10.21-alpha.5 → 1.10.21-alpha.6
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 +2 -1
- package/src/DetailModal/index.jsx +120 -120
- package/src/FormModal/index.tsx +210 -210
- package/src/components/CellEditTable/Template/ExpandListTemplate/index.less +1 -1
- package/src/components/CellEditTable/Template/ExpandListTemplate/index.tsx +30 -56
- package/src/components/CellEditTable/Template/GetBaseTemplate.tsx +33 -0
- package/src/components/CellEditTable/Template/widthWrap.tsx +16 -7
- package/src/components/CellEditTable/common/WidthWrapHoc.tsx +215 -0
- package/src/components/CellEditTable/common/childAntdComponent.ts +14 -0
- package/src/components/CellEditTable/common/utils.ts +257 -0
- package/src/components/CellEditTable/index.less +17 -0
- package/src/components/CellEditTable/index.tsx +60 -95
- package/src/table-render/index.jsx +124 -119
- package/src/components/CellEditTable/Template/SelectCellTemplate.tsx +0 -202
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
export const getNavigatorLanguage = (): string => navigator.language || "en-US";
|
|
2
|
+
|
|
3
|
+
function getLocaleSeparators(locale: string) {
|
|
4
|
+
const testNumber = 123456.789;
|
|
5
|
+
const localeFormattedNumber = Intl.NumberFormat(locale).format(testNumber);
|
|
6
|
+
|
|
7
|
+
// Get the thousands separator of the locale
|
|
8
|
+
const thousandsSeparator = localeFormattedNumber.split("123")[1][0];
|
|
9
|
+
|
|
10
|
+
// Get the decimal separator of the locale
|
|
11
|
+
const decimalSeparator = localeFormattedNumber.split("123")[1][4];
|
|
12
|
+
return { thousandsSeparator, decimalSeparator };
|
|
13
|
+
}
|
|
14
|
+
export function parseLocaleNumber(stringNumber: string, locale = getNavigatorLanguage()): number {
|
|
15
|
+
if (!stringNumber.trim()) return NaN;
|
|
16
|
+
const { thousandsSeparator, decimalSeparator } = getLocaleSeparators(locale);
|
|
17
|
+
const normalizedStringNumber = stringNumber.replace(/\u00A0/g, " "); // Replace non-breaking space with normal space
|
|
18
|
+
const numberString = normalizedStringNumber
|
|
19
|
+
.replace(new RegExp(`[${thousandsSeparator}\\s]`, "g"), "") // Replace thousands separator and white-space
|
|
20
|
+
.replace(new RegExp(`\\${decimalSeparator}`, "g"), "."); // Replace decimal separator
|
|
21
|
+
|
|
22
|
+
const trimmedNumberString = numberString.replace(/^(?!-)\D+|\D+$/g, ""); // Remove characters before first and after last number, but keep negative sign
|
|
23
|
+
if (trimmedNumberString === null || trimmedNumberString.trim().length === 0) {
|
|
24
|
+
return NaN;
|
|
25
|
+
}
|
|
26
|
+
return Number(trimmedNumberString);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
function isReactElement(value) {
|
|
31
|
+
return value !== null && typeof value === "object";
|
|
32
|
+
}
|
|
33
|
+
const getTitle = (item) => {
|
|
34
|
+
return typeof item?.title == "function"
|
|
35
|
+
? isReactElement(item?.title())
|
|
36
|
+
? item?.title()?.props.children
|
|
37
|
+
: String(item?.title()) || ""
|
|
38
|
+
: String(item?.title) || ""
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function convertColumnsToRows(columns, headerRowHeight = 40) {
|
|
42
|
+
// 获取所有叶子节点
|
|
43
|
+
const getLeaves = (cols) => {
|
|
44
|
+
return cols.reduce((acc, col) => {
|
|
45
|
+
if (col.children?.length) {
|
|
46
|
+
return [...acc, ...getLeaves(col.children)];
|
|
47
|
+
}
|
|
48
|
+
return [...acc, col];
|
|
49
|
+
}, []);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// 计算最大深度
|
|
53
|
+
const getDepth = (cols, depth = 1) => {
|
|
54
|
+
return cols.reduce((max, col) => {
|
|
55
|
+
if (col.children?.length) {
|
|
56
|
+
return Math.max(max, getDepth(col.children, depth + 1));
|
|
57
|
+
}
|
|
58
|
+
return Math.max(max, depth);
|
|
59
|
+
}, depth);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const leafColumns = getLeaves(columns);
|
|
63
|
+
const totalDepth = getDepth(columns);
|
|
64
|
+
const totalCols = leafColumns.length;
|
|
65
|
+
|
|
66
|
+
// 构建表头树
|
|
67
|
+
const buildTree = (cols, depth = 0) => {
|
|
68
|
+
return cols.map((col) => {
|
|
69
|
+
const hasChildren = col.children?.length > 0;
|
|
70
|
+
if (!hasChildren) {
|
|
71
|
+
return {
|
|
72
|
+
...col,
|
|
73
|
+
rowspan: totalDepth - depth,
|
|
74
|
+
colspan: 1,
|
|
75
|
+
_depth: depth,
|
|
76
|
+
_isLeaf: true,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const leafCount = getLeaves(col.children).length;
|
|
80
|
+
return {
|
|
81
|
+
...col,
|
|
82
|
+
rowspan: 1,
|
|
83
|
+
colspan: leafCount,
|
|
84
|
+
_depth: depth,
|
|
85
|
+
_isLeaf: false,
|
|
86
|
+
children: buildTree(col.children, depth + 1),
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const tree = buildTree(columns, 0);
|
|
92
|
+
|
|
93
|
+
// 初始化行
|
|
94
|
+
const rows: any = Array.from({ length: totalDepth }, (_, i) => ({
|
|
95
|
+
rowId: `header-${i}`,
|
|
96
|
+
height: headerRowHeight,
|
|
97
|
+
cells: [],
|
|
98
|
+
}));
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
// 递归填充行
|
|
102
|
+
const fillRow = (nodes, rowIndex = 0) => {
|
|
103
|
+
nodes.forEach((node) => {
|
|
104
|
+
if (node._isLeaf) {
|
|
105
|
+
const cell = {
|
|
106
|
+
...node,
|
|
107
|
+
type: node?.type == "rowSelection" ? "rowSelection" : "header",
|
|
108
|
+
text: getTitle(node),
|
|
109
|
+
dataIndex: node.dataIndex,
|
|
110
|
+
width: node.width,
|
|
111
|
+
rowspan: node.rowspan,
|
|
112
|
+
style: node?.type == "rowSelection" ? node?.style : {},
|
|
113
|
+
};
|
|
114
|
+
if (node.sorter) cell.sorter = node.sorter;
|
|
115
|
+
if (node.key) cell.key = node.key;
|
|
116
|
+
rows[rowIndex].cells.push(cell);
|
|
117
|
+
} else {
|
|
118
|
+
// 父节点:添加colspan
|
|
119
|
+
rows[rowIndex].cells.push({
|
|
120
|
+
...node,
|
|
121
|
+
type: node?.type == "rowSelection" ? "rowSelection" : "header",
|
|
122
|
+
text: getTitle(node),
|
|
123
|
+
colspan: node.colspan,
|
|
124
|
+
});
|
|
125
|
+
if (node.children) {
|
|
126
|
+
fillRow(node.children, rowIndex + 1);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
fillRow(tree, 0);
|
|
133
|
+
|
|
134
|
+
// 补全每一行的cell,使长度一致
|
|
135
|
+
rows.forEach((row, rowIndex) => {
|
|
136
|
+
const newCells = [];
|
|
137
|
+
let colIndex = 0;
|
|
138
|
+
let cellIndex = 0;
|
|
139
|
+
|
|
140
|
+
while (colIndex < totalCols) {
|
|
141
|
+
const currentCell = row.cells[cellIndex];
|
|
142
|
+
|
|
143
|
+
if (!currentCell) {
|
|
144
|
+
// 如果当前行没有足够的cell,从叶子节点补充
|
|
145
|
+
const leaf = leafColumns[colIndex];
|
|
146
|
+
newCells.push({
|
|
147
|
+
...leaf,
|
|
148
|
+
type: leaf?.type == "rowSelection" ? "rowSelection" : "header",
|
|
149
|
+
text: getTitle(leaf),
|
|
150
|
+
dataIndex: leaf.dataIndex,
|
|
151
|
+
width: leaf.width,
|
|
152
|
+
rowspan: rowIndex === totalDepth - 1 ? 1 : undefined,
|
|
153
|
+
});
|
|
154
|
+
colIndex++;
|
|
155
|
+
cellIndex++;
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const colspan = currentCell.colspan || 1;
|
|
160
|
+
const rowspan = currentCell.rowspan || 1;
|
|
161
|
+
|
|
162
|
+
// 检查当前cell是否应该出现在这一行
|
|
163
|
+
// 如果rowspan > 1,表示它跨多行,但只在第一行出现
|
|
164
|
+
if (rowspan > 1 && rowIndex > 0) {
|
|
165
|
+
// 这个cell不应该出现在当前行,跳过
|
|
166
|
+
colIndex += colspan;
|
|
167
|
+
cellIndex++;
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// 如果当前cell有colspan,需要补全后面的空cell
|
|
172
|
+
newCells.push(currentCell);
|
|
173
|
+
colIndex += colspan;
|
|
174
|
+
cellIndex++;
|
|
175
|
+
|
|
176
|
+
// 如果colspan > 1,后面补充空cell
|
|
177
|
+
for (let i = 1; i < colspan; i++) {
|
|
178
|
+
newCells.push({
|
|
179
|
+
type: "header",
|
|
180
|
+
text: "",
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
row.cells = newCells;
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// 最后一行的特殊处理:确保所有叶子节点都有对应的cell
|
|
189
|
+
const lastRow = rows[totalDepth - 1];
|
|
190
|
+
const lastRowCells = [];
|
|
191
|
+
let leafIndex = 0;
|
|
192
|
+
|
|
193
|
+
// 遍历所有叶子节点
|
|
194
|
+
leafColumns.forEach((leaf, index) => {
|
|
195
|
+
// 检查是否已经在lastRow中有对应的cell
|
|
196
|
+
const existingCell = lastRow.cells.find((cell) => cell.dataIndex === leaf.dataIndex && cell.text === leaf.title);
|
|
197
|
+
|
|
198
|
+
if (existingCell) {
|
|
199
|
+
lastRowCells.push(existingCell);
|
|
200
|
+
} else {
|
|
201
|
+
// 创建新的cell
|
|
202
|
+
lastRowCells.push({
|
|
203
|
+
...leaf,
|
|
204
|
+
type: leaf?.type == "rowSelection" ? "rowSelection" : "header",
|
|
205
|
+
text: getTitle(leaf),
|
|
206
|
+
dataIndex: leaf.dataIndex,
|
|
207
|
+
width: leaf.width,
|
|
208
|
+
rowspan: 1,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
lastRow.cells = lastRowCells;
|
|
214
|
+
|
|
215
|
+
// 确保所有行的cell数量等于totalCols
|
|
216
|
+
rows.forEach((row) => {
|
|
217
|
+
// 如果cell数量少于totalCols,补充空cell
|
|
218
|
+
while (row.cells.length < totalCols) {
|
|
219
|
+
row.cells.push({
|
|
220
|
+
type: "header",
|
|
221
|
+
text: "",
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
return rows;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
export function flattenColumns(columns: any[]) {
|
|
231
|
+
const result: any[] = [];
|
|
232
|
+
|
|
233
|
+
function traverse(cols) {
|
|
234
|
+
cols.forEach((col) => {
|
|
235
|
+
if (col.children && col.children.length > 0) {
|
|
236
|
+
traverse(col.children);
|
|
237
|
+
} else {
|
|
238
|
+
// 创建新对象,只保留需要的属性
|
|
239
|
+
const { title, dataIndex, key, width, sorter, k, ...rest } = col;
|
|
240
|
+
result.push({
|
|
241
|
+
type: "Input",
|
|
242
|
+
dataIndex,
|
|
243
|
+
title,
|
|
244
|
+
...(key && { key }),
|
|
245
|
+
...(width && { width }),
|
|
246
|
+
...(sorter && { sorter }),
|
|
247
|
+
...(k && { k }),
|
|
248
|
+
// 如果需要保留其他属性
|
|
249
|
+
...rest,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
traverse(columns);
|
|
256
|
+
return result;
|
|
257
|
+
}
|
|
@@ -8,4 +8,21 @@
|
|
|
8
8
|
.ant-select {
|
|
9
9
|
width: 100% !important;
|
|
10
10
|
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
.reactgrid-content .rg-pane .rg-cell {
|
|
14
|
+
padding: 0;
|
|
15
|
+
|
|
16
|
+
>div:nth-child(1) {
|
|
17
|
+
padding: 0 4px;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
11
20
|
}
|
|
21
|
+
|
|
22
|
+
.base-hoc {
|
|
23
|
+
width: 100%;
|
|
24
|
+
height: 100%;
|
|
25
|
+
display: flex;
|
|
26
|
+
align-items: center;
|
|
27
|
+
justify-content: center;
|
|
28
|
+
}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import React, { memo, useEffect, useMemo, useState } from "react";
|
|
1
|
+
import React, { memo, useEffect, useMemo, useRef, useState } from "react";
|
|
2
2
|
import { ReactGrid, Column, Row, CellChange, Cell, CellTemplate } from "@silevis/reactgrid";
|
|
3
3
|
import "@silevis/reactgrid/styles.css";
|
|
4
|
-
import _ from "lodash";
|
|
5
|
-
import "./index.less";
|
|
6
4
|
import { TextTemplate } from "./Template/TextCellTemplate";
|
|
7
5
|
import { antdComponents, customComponents } from "@hzab/form-render/src/index";
|
|
8
|
-
import {
|
|
6
|
+
import { WidthWrapHoc } from "./common/WidthWrapHoc";
|
|
9
7
|
import { NumberTemplate } from "./Template/NumberCellTemplate";
|
|
10
8
|
import { Checkbox, Spin } from "antd";
|
|
11
9
|
import { ExpandListTemplate } from "./Template/ExpandListTemplate";
|
|
12
|
-
import { convertColumnsToRows, flattenColumns } from "./
|
|
10
|
+
import { convertColumnsToRows, flattenColumns } from "./common/utils";
|
|
11
|
+
import { childAntdComponent } from "./common/childAntdComponent";
|
|
12
|
+
import { GetBaseTemplate } from "./Template/GetBaseTemplate";
|
|
13
|
+
import "./index.less";
|
|
13
14
|
|
|
14
|
-
export default
|
|
15
|
+
export default function CellEditTable(props: any) {
|
|
15
16
|
const {
|
|
16
17
|
columns,
|
|
17
18
|
dataSource,
|
|
@@ -36,6 +37,7 @@ export default memo(function CellEditTable(props: any) {
|
|
|
36
37
|
const [selectedRowKeys, setSelectedRowKeys] = useState<any>([]);
|
|
37
38
|
const [newDataSource, setNewDataSource] = useState<any>([]);
|
|
38
39
|
const [expandKeys, setExpandKeys] = useState<any>([]);
|
|
40
|
+
const gridRef = useRef<any>();
|
|
39
41
|
useEffect(() => {
|
|
40
42
|
setNewDataSource(dataSource);
|
|
41
43
|
}, [dataSource]);
|
|
@@ -72,19 +74,6 @@ export default memo(function CellEditTable(props: any) {
|
|
|
72
74
|
},
|
|
73
75
|
});
|
|
74
76
|
}
|
|
75
|
-
// const cells = columns?.map((item, index) => {
|
|
76
|
-
// return {
|
|
77
|
-
// type: item?.type == "rowSelection" ? "rowSelection" : "header",
|
|
78
|
-
// text:
|
|
79
|
-
// typeof item?.title == "function"
|
|
80
|
-
// ? isReactElement(item?.title())
|
|
81
|
-
// ? item?.title()?.props.children
|
|
82
|
-
// : String(item?.title()) || ""
|
|
83
|
-
// : String(item?.title) || "",
|
|
84
|
-
// style: item?.type == "rowSelection" ? item?.style : {},
|
|
85
|
-
// onCell: item?.onCell,
|
|
86
|
-
// };
|
|
87
|
-
// });
|
|
88
77
|
setHeaderList(convertColumnsToRows(columns, headerRowHeight));
|
|
89
78
|
const newColumns = flattenColumns(columns);
|
|
90
79
|
setTableColumns(
|
|
@@ -108,13 +97,14 @@ export default memo(function CellEditTable(props: any) {
|
|
|
108
97
|
const columnsItem = tableColumns[ind];
|
|
109
98
|
const cellItem = item[el];
|
|
110
99
|
let type: any = columnsItem?.type ?? "text";
|
|
100
|
+
/** 是否有复选框 */
|
|
111
101
|
if (!rowSelection && ind == 0) {
|
|
112
102
|
type = "ExpandListTemplate";
|
|
113
103
|
}
|
|
114
104
|
if (rowSelection && ind == 1) {
|
|
115
105
|
type = "ExpandListTemplate";
|
|
116
106
|
}
|
|
117
|
-
|
|
107
|
+
//设置单元格颜色及回显
|
|
118
108
|
if (formulaConfig) {
|
|
119
109
|
for (let key in formulaConfig) {
|
|
120
110
|
if (key == el) {
|
|
@@ -137,8 +127,6 @@ export default memo(function CellEditTable(props: any) {
|
|
|
137
127
|
text: String(cellItem || ""),
|
|
138
128
|
value: cellItem,
|
|
139
129
|
selectedValue: cellItem || "",
|
|
140
|
-
// rowspan: item?.extendedConfig?.name == el ? item?.extendedConfig?.rowspan || 0 : 0,
|
|
141
|
-
// colspan: item?.extendedConfig?.name == el ? item?.extendedConfig?.colspan || 0 : 0,
|
|
142
130
|
style: columnsItem?.type == "rowSelection" ? { display: "flex", justifyContent: "center" } : {},
|
|
143
131
|
...((columnsItem?.onCell && columnsItem?.onCell(item, index, ind)) || {}),
|
|
144
132
|
...(columnsItem?.cellProps || {}),
|
|
@@ -148,26 +136,28 @@ export default memo(function CellEditTable(props: any) {
|
|
|
148
136
|
expandKeys,
|
|
149
137
|
Slots,
|
|
150
138
|
...newCell,
|
|
151
|
-
|
|
152
|
-
// style:item?.extendedConfig?.name==el?item?.extendedConfig?.style||{}:{}
|
|
153
|
-
// ...handleType(item[el],tableColumns[ind]),
|
|
154
139
|
};
|
|
155
140
|
}),
|
|
156
141
|
};
|
|
157
142
|
});
|
|
158
|
-
setRows(
|
|
159
|
-
}, [newDataSource, tableColumns
|
|
143
|
+
setRows([...headerList, ...tempDataSource]);
|
|
144
|
+
}, [newDataSource, tableColumns]);
|
|
160
145
|
|
|
161
146
|
// 单元格编辑回调
|
|
162
147
|
const handleCellsChanged = (changes) => {
|
|
163
148
|
if (!Array.isArray(changes) || changes.length === 0) return;
|
|
164
|
-
|
|
165
|
-
|
|
149
|
+
/** 批量提交 */
|
|
150
|
+
let isBatchSubmit = false;
|
|
151
|
+
if (changes?.length > 1) {
|
|
152
|
+
isBatchSubmit = true;
|
|
153
|
+
}
|
|
166
154
|
setRows((prevRows) => {
|
|
167
155
|
changes.forEach((change) => {
|
|
156
|
+
const hasDiff = JSON.stringify((window as any).preCell?.text) != JSON.stringify(change.newCell?.text);
|
|
157
|
+
if (!hasDiff) return;
|
|
168
158
|
const changeRowIdx = prevRows.findIndex((el) => el.rowId == change.rowId);
|
|
169
159
|
const changeColumnIdx = tableColumns.findIndex((el) => el.columnId == change.columnId);
|
|
170
|
-
prevRows[changeRowIdx].cells[changeColumnIdx] = change.newCell;
|
|
160
|
+
prevRows[changeRowIdx].cells[changeColumnIdx] = { ...change.newCell };
|
|
171
161
|
if (formulaConfig) {
|
|
172
162
|
for (let key in formulaConfig) {
|
|
173
163
|
const item = formulaConfig[key];
|
|
@@ -181,39 +171,23 @@ export default memo(function CellEditTable(props: any) {
|
|
|
181
171
|
prevRows[changeRowIdx].cells[resultColumnIdx] = newCell;
|
|
182
172
|
}
|
|
183
173
|
}
|
|
184
|
-
|
|
174
|
+
if (change?.newCell?.commit == "submit") {
|
|
175
|
+
onEditSubmit && onEditSubmit(handleArrayToObj(prevRows[changeRowIdx]));
|
|
176
|
+
}
|
|
185
177
|
onChange && onChange(prevRows[changeRowIdx]);
|
|
186
178
|
});
|
|
187
179
|
return [...prevRows];
|
|
188
180
|
});
|
|
189
181
|
};
|
|
190
|
-
|
|
191
|
-
/**提取组件内部子组件 */
|
|
192
|
-
function extractSubComponents(comp, compName): any {
|
|
193
|
-
if (!comp || typeof comp !== "object") return {};
|
|
194
|
-
|
|
195
|
-
return Object.entries(comp).reduce((result, [key, value]) => {
|
|
196
|
-
// 匹配 antd 规范子组件命名:XXPicker / XX / 驼峰组件名
|
|
197
|
-
// 排除普通函数、数字、布尔、内部私有属性(带下划线)、原型上的方法
|
|
198
|
-
const isNativeFunc = ["render", "defaultProps", "propTypes", "displayName", "Group", "$$typeof"].includes(key);
|
|
199
|
-
// 判定为子组件:值是函数(React组件本质是函数/类),且不是内部方法
|
|
200
|
-
const isSubComponent = typeof comp == "object" && !isNativeFunc;
|
|
201
|
-
|
|
202
|
-
if (isSubComponent) {
|
|
203
|
-
result[`${compName}.${key}`] = value;
|
|
204
|
-
}
|
|
205
|
-
return result;
|
|
206
|
-
}, {});
|
|
207
|
-
}
|
|
208
182
|
/** 自定义组件注册 */
|
|
209
183
|
const baseTemplate = useMemo(() => {
|
|
210
|
-
const mergeTemplate: any = { ...(antdComponents || {}), ...(customComponents || {}) };
|
|
184
|
+
const mergeTemplate: any = { ...(antdComponents || {}), ...(customComponents || {}), ...childAntdComponent };
|
|
211
185
|
const newMergeTemplate: any = {};
|
|
212
186
|
for (let key in mergeTemplate) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
newMergeTemplate[key] =
|
|
187
|
+
const NewCom = (props) => {
|
|
188
|
+
return <GetBaseTemplate {...props} Com={mergeTemplate[key]} />;
|
|
189
|
+
};
|
|
190
|
+
newMergeTemplate[key] = WidthWrapHoc(NewCom);
|
|
217
191
|
}
|
|
218
192
|
return newMergeTemplate;
|
|
219
193
|
}, [antdComponents, customComponents]);
|
|
@@ -221,42 +195,43 @@ export default memo(function CellEditTable(props: any) {
|
|
|
221
195
|
const ActionDom = (props) => {
|
|
222
196
|
return (
|
|
223
197
|
<div onPointerDown={(e) => e.stopPropagation()}>
|
|
224
|
-
{Slots?.tableActionsSlot && <Slots.tableActionsSlot {...props} />}
|
|
225
|
-
{Slots?.actionPrefixSlot && <Slots.actionPrefixSlot {...props} />}
|
|
226
|
-
{Slots?.actionCenterSlot && <Slots.actionCenterSlot {...props} />}
|
|
227
|
-
{Slots?.actionSuffixSlot && <Slots.actionSuffixSlot {...props} />}
|
|
198
|
+
{Slots?.tableActionsSlot && <Slots.tableActionsSlot {...props?.cell} />}
|
|
199
|
+
{Slots?.actionPrefixSlot && <Slots.actionPrefixSlot {...props?.cell} />}
|
|
200
|
+
{Slots?.actionCenterSlot && <Slots.actionCenterSlot {...props?.cell} />}
|
|
201
|
+
{Slots?.actionSuffixSlot && <Slots.actionSuffixSlot {...props?.cell} />}
|
|
228
202
|
</div>
|
|
229
203
|
);
|
|
230
204
|
};
|
|
231
205
|
|
|
232
206
|
const CheckBoxDom = (props) => {
|
|
207
|
+
const { record, rowId } = props?.cell;
|
|
233
208
|
return (
|
|
234
209
|
<Checkbox
|
|
235
|
-
{...props}
|
|
210
|
+
{...props?.componentProps}
|
|
236
211
|
checked={
|
|
237
|
-
rowSelection?.selectedRowKeys?.includes((
|
|
212
|
+
rowSelection?.selectedRowKeys?.includes((record && record[rowKey]) || "") ||
|
|
238
213
|
(rowSelection?.selectedRowKeys?.length == dataSource?.length && dataSource?.length > 0)
|
|
239
214
|
}
|
|
240
215
|
indeterminate={
|
|
241
|
-
!
|
|
216
|
+
!rowId &&
|
|
242
217
|
rowSelection?.selectedRowKeys?.length > 0 &&
|
|
243
218
|
rowSelection?.selectedRowKeys?.length < dataSource?.length
|
|
244
219
|
}
|
|
245
220
|
onChange={(e) => {
|
|
246
|
-
if (e.target.checked &&
|
|
247
|
-
const newSelectedRowKeys = [...rowSelection?.selectedRowKeys,
|
|
221
|
+
if (e.target.checked && rowId) {
|
|
222
|
+
const newSelectedRowKeys = [...rowSelection?.selectedRowKeys, record[rowKey]];
|
|
248
223
|
const rows = dataSource?.filter((el) => newSelectedRowKeys?.includes(el[rowKey]));
|
|
249
224
|
|
|
250
225
|
rowSelection?.onChange(newSelectedRowKeys, rows);
|
|
251
|
-
} else if (!e.target.checked &&
|
|
252
|
-
const newSelectedRowKeys = rowSelection?.selectedRowKeys?.filter((el) => el !=
|
|
226
|
+
} else if (!e.target.checked && rowId) {
|
|
227
|
+
const newSelectedRowKeys = rowSelection?.selectedRowKeys?.filter((el) => el != record[rowKey]);
|
|
253
228
|
const rows = dataSource?.filter((el) => newSelectedRowKeys?.includes(el[rowKey]));
|
|
254
229
|
|
|
255
230
|
rowSelection?.onChange(
|
|
256
|
-
rowSelection?.selectedRowKeys?.filter((el) => el !=
|
|
231
|
+
rowSelection?.selectedRowKeys?.filter((el) => el != record[rowKey]),
|
|
257
232
|
rows,
|
|
258
233
|
);
|
|
259
|
-
} else if (e.target.checked && !
|
|
234
|
+
} else if (e.target.checked && !rowId) {
|
|
260
235
|
const newSelectedRowKeys = dataSource?.map((el) => el[rowKey]);
|
|
261
236
|
const rows = dataSource?.filter((el) => newSelectedRowKeys?.includes(el[rowKey]));
|
|
262
237
|
|
|
@@ -264,7 +239,7 @@ export default memo(function CellEditTable(props: any) {
|
|
|
264
239
|
dataSource?.map((el) => el[rowKey]),
|
|
265
240
|
rows,
|
|
266
241
|
);
|
|
267
|
-
} else if (!e.target.checked && !
|
|
242
|
+
} else if (!e.target.checked && !rowId) {
|
|
268
243
|
rowSelection?.onChange([], []);
|
|
269
244
|
}
|
|
270
245
|
}}
|
|
@@ -281,57 +256,47 @@ export default memo(function CellEditTable(props: any) {
|
|
|
281
256
|
setSelectedRowKeys([]);
|
|
282
257
|
}, [query?.pageNum]);
|
|
283
258
|
|
|
259
|
+
const customCellTemplates = useMemo(() => {
|
|
260
|
+
const templatesObj: any = {};
|
|
261
|
+
for (let key in reactGridProps?.customCellTemplates) {
|
|
262
|
+
const item = reactGridProps?.customCellTemplates[key];
|
|
263
|
+
templatesObj[key] = WidthWrapHoc(item);
|
|
264
|
+
}
|
|
265
|
+
return templatesObj;
|
|
266
|
+
}, [reactGridProps?.customCellTemplates]);
|
|
267
|
+
|
|
284
268
|
return (
|
|
285
269
|
<Spin spinning={loading}>
|
|
286
270
|
<div className={`grid-container ${className}`} style={reactGridStyle}>
|
|
287
271
|
<ReactGrid
|
|
272
|
+
ref={gridRef}
|
|
288
273
|
rows={rows}
|
|
289
274
|
columns={tableColumns}
|
|
290
275
|
onCellsChanged={handleCellsChanged}
|
|
291
276
|
enableFillHandle={true}
|
|
292
277
|
enableRangeSelection={true}
|
|
293
278
|
horizontalStickyBreakpoint={120}
|
|
294
|
-
// stickyLeftColumns={1}
|
|
295
|
-
// onFocusLocationChanging={(location) => {
|
|
296
|
-
// return false;
|
|
297
|
-
// }}
|
|
298
279
|
{...reactGridProps}
|
|
299
280
|
onFocusLocationChanging={(cell: any) => {
|
|
300
281
|
const datatypeId = cell?.columnId + cell?.rowId;
|
|
301
|
-
window.gridEditId = datatypeId;
|
|
302
|
-
|
|
282
|
+
(window as any).gridEditId = datatypeId;
|
|
303
283
|
if (["_$actions", "rowSelection"]?.includes(cell?.columnId)) {
|
|
304
284
|
return false;
|
|
305
285
|
}
|
|
306
|
-
|
|
307
286
|
if (reactGridProps?.onFocusLocationChanging) {
|
|
308
287
|
return reactGridProps?.onFocusLocationChanging(cell, rows);
|
|
309
288
|
}
|
|
310
289
|
return cell;
|
|
311
290
|
}}
|
|
312
291
|
customCellTemplates={{
|
|
292
|
+
ExpandListTemplate: WidthWrapHoc(ExpandListTemplate),
|
|
313
293
|
...baseTemplate,
|
|
314
|
-
...
|
|
315
|
-
_$actions:
|
|
316
|
-
|
|
317
|
-
WrapComponent: ActionDom,
|
|
318
|
-
},
|
|
319
|
-
true,
|
|
320
|
-
),
|
|
321
|
-
rowSelection: WidthWrap(
|
|
322
|
-
{
|
|
323
|
-
WrapComponent: CheckBoxDom,
|
|
324
|
-
},
|
|
325
|
-
true,
|
|
326
|
-
),
|
|
294
|
+
...customCellTemplates,
|
|
295
|
+
_$actions: WidthWrapHoc(ActionDom),
|
|
296
|
+
rowSelection: WidthWrapHoc(CheckBoxDom),
|
|
327
297
|
Input: TextTemplate,
|
|
328
298
|
Number: NumberTemplate,
|
|
329
|
-
ExpandListTemplate: WidthWrap(
|
|
330
|
-
{
|
|
331
|
-
WrapComponent: ExpandListTemplate,
|
|
332
|
-
},
|
|
333
|
-
true,
|
|
334
|
-
),
|
|
299
|
+
// ExpandListTemplate: WidthWrap({ WrapComponent: ExpandListTemplate }, true),
|
|
335
300
|
}}
|
|
336
301
|
|
|
337
302
|
// onSelectionChanged={(newSelection) => {
|
|
@@ -341,4 +306,4 @@ export default memo(function CellEditTable(props: any) {
|
|
|
341
306
|
</div>
|
|
342
307
|
</Spin>
|
|
343
308
|
);
|
|
344
|
-
}
|
|
309
|
+
}
|