@hzab/list-render 1.10.21-alpha.3 → 1.10.21-alpha.5
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 +1 -1
- package/src/components/CellEditTable/Template/ExpandListTemplate/index.less +1 -1
- package/src/components/CellEditTable/Template/ExpandListTemplate/index.tsx +22 -10
- package/src/components/CellEditTable/Template/widthWrap.tsx +11 -7
- package/src/components/CellEditTable/index.less +1 -0
- package/src/components/CellEditTable/index.tsx +68 -64
- package/src/table-render/index.jsx +1 -1
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MinusSquareOutlined, PlusCircleOutlined } from "@ant-design/icons";
|
|
2
|
-
import { useEffect, useState } from "react";
|
|
1
|
+
import { MinusCircleOutlined, MinusSquareOutlined, PlusCircleOutlined } from "@ant-design/icons";
|
|
2
|
+
import { useEffect, useState, memo } from "react";
|
|
3
3
|
import "./index.less";
|
|
4
4
|
export const ExpandListTemplate = (props) => {
|
|
5
5
|
const [expand, setExpand] = useState<boolean>(false);
|
|
@@ -7,14 +7,18 @@ export const ExpandListTemplate = (props) => {
|
|
|
7
7
|
const { Slots, setExpandKeys, expandKeys }: any = item;
|
|
8
8
|
const onExpand = (isExpand) => {
|
|
9
9
|
item?.setNewDataSource((pre) => {
|
|
10
|
+
const tempPre = [...pre];
|
|
11
|
+
const childrenIds = props?.record?.children?.map((el) => el?.groupId);
|
|
10
12
|
if (isExpand) {
|
|
11
13
|
const findIndex = pre?.findIndex((el) => el?.groupId == props?.record?.groupId);
|
|
12
|
-
pre
|
|
13
|
-
|
|
14
|
+
const filterList = pre?.filter((el) => childrenIds?.includes(el?.groupId)) || [];
|
|
15
|
+
if (filterList?.length == 0) {
|
|
16
|
+
tempPre.splice(findIndex + 1, 0, ...(props?.record?.children || []));
|
|
17
|
+
}
|
|
18
|
+
return [...tempPre];
|
|
14
19
|
}
|
|
15
|
-
const childrenIds = props?.record?.children?.map((el) => el?.groupId);
|
|
16
20
|
|
|
17
|
-
return
|
|
21
|
+
return tempPre?.filter((el) => !childrenIds?.includes(el?.groupId));
|
|
18
22
|
});
|
|
19
23
|
};
|
|
20
24
|
useEffect(() => {
|
|
@@ -29,7 +33,6 @@ export const ExpandListTemplate = (props) => {
|
|
|
29
33
|
// setExpand(props?.record?.expand);
|
|
30
34
|
}, [props?.record]);
|
|
31
35
|
|
|
32
|
-
// console.log(props,"propspropsprops2",Slots[item?.columnId]);
|
|
33
36
|
const colRender = function (text, record) {
|
|
34
37
|
const Slot = Slots[item?.columnId];
|
|
35
38
|
const slotProps = {
|
|
@@ -51,7 +54,7 @@ export const ExpandListTemplate = (props) => {
|
|
|
51
54
|
props.record["expand"] = !expand;
|
|
52
55
|
setExpandKeys((preExpandKeys) => {
|
|
53
56
|
if (preExpandKeys?.includes(props?.record?.groupId)) {
|
|
54
|
-
return preExpandKeys?.filter((el) => el
|
|
57
|
+
return preExpandKeys?.filter((el) => el != props?.record?.groupId);
|
|
55
58
|
}
|
|
56
59
|
return [...preExpandKeys, props?.record?.groupId];
|
|
57
60
|
});
|
|
@@ -60,10 +63,16 @@ export const ExpandListTemplate = (props) => {
|
|
|
60
63
|
}}
|
|
61
64
|
/>
|
|
62
65
|
) : (
|
|
63
|
-
<
|
|
66
|
+
<MinusCircleOutlined
|
|
64
67
|
className="expandList-template-icon"
|
|
65
68
|
onClick={() => {
|
|
66
69
|
props.record["expand"] = !expand;
|
|
70
|
+
setExpandKeys((preExpandKeys) => {
|
|
71
|
+
if (preExpandKeys?.includes(props?.record?.groupId)) {
|
|
72
|
+
return preExpandKeys?.filter((el) => el != props?.record?.groupId);
|
|
73
|
+
}
|
|
74
|
+
return [...preExpandKeys, props?.record?.groupId];
|
|
75
|
+
});
|
|
67
76
|
setExpand(!expand);
|
|
68
77
|
onExpand(!expand);
|
|
69
78
|
}}
|
|
@@ -72,7 +81,10 @@ export const ExpandListTemplate = (props) => {
|
|
|
72
81
|
</>
|
|
73
82
|
)}
|
|
74
83
|
|
|
75
|
-
<div
|
|
84
|
+
<div
|
|
85
|
+
className={`expandList-template-name ${record?.spiltTag == 0 ? "expandList-template-indent" : ""}`}
|
|
86
|
+
style={record?.spiltTag == 1 && !record?.children ? { marginLeft: "22px" } : {}}
|
|
87
|
+
>
|
|
76
88
|
{Slots?.[item?.columnId] ? colRender("", record) : record[item?.columnId]}
|
|
77
89
|
</div>
|
|
78
90
|
</div>
|
|
@@ -152,7 +152,10 @@ export const WidthWrap = (opt: any, edit = false) => {
|
|
|
152
152
|
): React.ReactNode {
|
|
153
153
|
if (edit) {
|
|
154
154
|
return (
|
|
155
|
-
<div
|
|
155
|
+
<div
|
|
156
|
+
onPointerDown={(e) => e.stopPropagation()}
|
|
157
|
+
style={{ display: "flex", justifyContent: "center", alignItems: "center" }}
|
|
158
|
+
>
|
|
156
159
|
<WrapComponent record={cell?.record} rowId={cell?.rowId} item={cell}></WrapComponent>
|
|
157
160
|
</div>
|
|
158
161
|
);
|
|
@@ -192,8 +195,8 @@ export const WidthWrap = (opt: any, edit = false) => {
|
|
|
192
195
|
}, [cell]);
|
|
193
196
|
|
|
194
197
|
const echoValue = useMemo(() => {
|
|
195
|
-
if(!cell?.getField){
|
|
196
|
-
return
|
|
198
|
+
if (!cell?.getField) {
|
|
199
|
+
return;
|
|
197
200
|
}
|
|
198
201
|
return getVal(
|
|
199
202
|
{ ...(cell?.getField && cell?.getField()), enum: cell?.getField()?.enum || cell?.values },
|
|
@@ -203,9 +206,8 @@ export const WidthWrap = (opt: any, edit = false) => {
|
|
|
203
206
|
|
|
204
207
|
return (
|
|
205
208
|
<div
|
|
206
|
-
style={{ width: "100%", height: "100%", display: "flex", alignItems: "center" }}
|
|
209
|
+
style={{ width: "100%", height: "100%", display: "flex", alignItems: "center", justifyContent: "center" }}
|
|
207
210
|
onDoubleClick={(e) => {
|
|
208
|
-
console.log(cell,"c222ellcellcellcellcell");
|
|
209
211
|
if (cell?.nonEditable) {
|
|
210
212
|
return;
|
|
211
213
|
}
|
|
@@ -222,7 +224,7 @@ export const WidthWrap = (opt: any, edit = false) => {
|
|
|
222
224
|
}
|
|
223
225
|
}}
|
|
224
226
|
open={isOpen}
|
|
225
|
-
style={{ width: "100%", display: "flex", alignItems: "center" }}
|
|
227
|
+
style={{ width: "100%", display: "flex", alignItems: "center", justifyContent: "center" }}
|
|
226
228
|
value={cell[_value]}
|
|
227
229
|
options={cell.values}
|
|
228
230
|
onChange={(e) => {
|
|
@@ -247,7 +249,9 @@ export const WidthWrap = (opt: any, edit = false) => {
|
|
|
247
249
|
item={cell}
|
|
248
250
|
/>
|
|
249
251
|
) : (
|
|
250
|
-
<div style={{ height: "100%", display: "flex", alignItems: "center" }}>
|
|
252
|
+
<div style={{ height: "100%", display: "flex", alignItems: "center", justifyContent: "center" }}>
|
|
253
|
+
{echoValue}
|
|
254
|
+
</div>
|
|
251
255
|
)}
|
|
252
256
|
</div>
|
|
253
257
|
)}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect, useMemo, useState } from "react";
|
|
1
|
+
import React, { memo, useEffect, useMemo, useState } from "react";
|
|
2
2
|
import { ReactGrid, Column, Row, CellChange, Cell, CellTemplate } from "@silevis/reactgrid";
|
|
3
3
|
import "@silevis/reactgrid/styles.css";
|
|
4
4
|
import _ from "lodash";
|
|
@@ -7,11 +7,11 @@ import { TextTemplate } from "./Template/TextCellTemplate";
|
|
|
7
7
|
import { antdComponents, customComponents } from "@hzab/form-render/src/index";
|
|
8
8
|
import { WidthWrap } from "./Template/widthWrap";
|
|
9
9
|
import { NumberTemplate } from "./Template/NumberCellTemplate";
|
|
10
|
-
import { Checkbox } from "antd";
|
|
10
|
+
import { Checkbox, Spin } from "antd";
|
|
11
11
|
import { ExpandListTemplate } from "./Template/ExpandListTemplate";
|
|
12
12
|
import { convertColumnsToRows, flattenColumns } from "./Template/utils";
|
|
13
13
|
|
|
14
|
-
export default function CellEditTable(props: any) {
|
|
14
|
+
export default memo(function CellEditTable(props: any) {
|
|
15
15
|
const {
|
|
16
16
|
columns,
|
|
17
17
|
dataSource,
|
|
@@ -27,6 +27,7 @@ export default function CellEditTable(props: any) {
|
|
|
27
27
|
rowSelection,
|
|
28
28
|
rowKey,
|
|
29
29
|
query,
|
|
30
|
+
loading,
|
|
30
31
|
} = props;
|
|
31
32
|
|
|
32
33
|
const [headerList, setHeaderList] = useState<any>([]);
|
|
@@ -107,7 +108,7 @@ export default function CellEditTable(props: any) {
|
|
|
107
108
|
const columnsItem = tableColumns[ind];
|
|
108
109
|
const cellItem = item[el];
|
|
109
110
|
let type: any = columnsItem?.type ?? "text";
|
|
110
|
-
if (!rowSelection && ind == 0
|
|
111
|
+
if (!rowSelection && ind == 0) {
|
|
111
112
|
type = "ExpandListTemplate";
|
|
112
113
|
}
|
|
113
114
|
if (rowSelection && ind == 1) {
|
|
@@ -130,7 +131,7 @@ export default function CellEditTable(props: any) {
|
|
|
130
131
|
return {
|
|
131
132
|
...columnsItem,
|
|
132
133
|
record: item,
|
|
133
|
-
rowId: item
|
|
134
|
+
rowId: item[rowKey] || columnsItem?.type,
|
|
134
135
|
type: type,
|
|
135
136
|
nonEditable: columnsItem?.nonEditable,
|
|
136
137
|
text: String(cellItem || ""),
|
|
@@ -143,6 +144,7 @@ export default function CellEditTable(props: any) {
|
|
|
143
144
|
...(columnsItem?.cellProps || {}),
|
|
144
145
|
setNewDataSource,
|
|
145
146
|
setExpandKeys,
|
|
147
|
+
rowKey,
|
|
146
148
|
expandKeys,
|
|
147
149
|
Slots,
|
|
148
150
|
...newCell,
|
|
@@ -153,14 +155,14 @@ export default function CellEditTable(props: any) {
|
|
|
153
155
|
}),
|
|
154
156
|
};
|
|
155
157
|
});
|
|
156
|
-
setRows([...headerList, ...tempDataSource]);
|
|
158
|
+
setRows(_.uniqBy([...headerList, ...tempDataSource], "rowId"));
|
|
157
159
|
}, [newDataSource, tableColumns, rowSelection]);
|
|
158
|
-
console.log(rows, "rowsrows");
|
|
159
160
|
|
|
160
161
|
// 单元格编辑回调
|
|
161
162
|
const handleCellsChanged = (changes) => {
|
|
162
|
-
|
|
163
|
-
|
|
163
|
+
if (!Array.isArray(changes) || changes.length === 0) return;
|
|
164
|
+
const hasDiff = changes.some((c) => JSON.stringify(c.previousCell) !== JSON.stringify(c.newCell));
|
|
165
|
+
if (!hasDiff) return;
|
|
164
166
|
setRows((prevRows) => {
|
|
165
167
|
changes.forEach((change) => {
|
|
166
168
|
const changeRowIdx = prevRows.findIndex((el) => el.rowId == change.rowId);
|
|
@@ -233,7 +235,7 @@ export default function CellEditTable(props: any) {
|
|
|
233
235
|
{...props}
|
|
234
236
|
checked={
|
|
235
237
|
rowSelection?.selectedRowKeys?.includes((props?.record && props?.record[rowKey]) || "") ||
|
|
236
|
-
rowSelection?.selectedRowKeys?.length == dataSource?.length
|
|
238
|
+
(rowSelection?.selectedRowKeys?.length == dataSource?.length && dataSource?.length > 0)
|
|
237
239
|
}
|
|
238
240
|
indeterminate={
|
|
239
241
|
!props?.rowId &&
|
|
@@ -280,61 +282,63 @@ export default function CellEditTable(props: any) {
|
|
|
280
282
|
}, [query?.pageNum]);
|
|
281
283
|
|
|
282
284
|
return (
|
|
283
|
-
<
|
|
284
|
-
<
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
285
|
+
<Spin spinning={loading}>
|
|
286
|
+
<div className={`grid-container ${className}`} style={reactGridStyle}>
|
|
287
|
+
<ReactGrid
|
|
288
|
+
rows={rows}
|
|
289
|
+
columns={tableColumns}
|
|
290
|
+
onCellsChanged={handleCellsChanged}
|
|
291
|
+
enableFillHandle={true}
|
|
292
|
+
enableRangeSelection={true}
|
|
293
|
+
horizontalStickyBreakpoint={120}
|
|
294
|
+
// stickyLeftColumns={1}
|
|
295
|
+
// onFocusLocationChanging={(location) => {
|
|
296
|
+
// return false;
|
|
297
|
+
// }}
|
|
298
|
+
{...reactGridProps}
|
|
299
|
+
onFocusLocationChanging={(cell: any) => {
|
|
300
|
+
const datatypeId = cell?.columnId + cell?.rowId;
|
|
301
|
+
window.gridEditId = datatypeId;
|
|
299
302
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
+
if (["_$actions", "rowSelection"]?.includes(cell?.columnId)) {
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
303
306
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
307
|
+
if (reactGridProps?.onFocusLocationChanging) {
|
|
308
|
+
return reactGridProps?.onFocusLocationChanging(cell, rows);
|
|
309
|
+
}
|
|
310
|
+
return cell;
|
|
311
|
+
}}
|
|
312
|
+
customCellTemplates={{
|
|
313
|
+
...baseTemplate,
|
|
314
|
+
...reactGridProps?.customCellTemplates,
|
|
315
|
+
_$actions: WidthWrap(
|
|
316
|
+
{
|
|
317
|
+
WrapComponent: ActionDom,
|
|
318
|
+
},
|
|
319
|
+
true,
|
|
320
|
+
),
|
|
321
|
+
rowSelection: WidthWrap(
|
|
322
|
+
{
|
|
323
|
+
WrapComponent: CheckBoxDom,
|
|
324
|
+
},
|
|
325
|
+
true,
|
|
326
|
+
),
|
|
327
|
+
Input: TextTemplate,
|
|
328
|
+
Number: NumberTemplate,
|
|
329
|
+
ExpandListTemplate: WidthWrap(
|
|
330
|
+
{
|
|
331
|
+
WrapComponent: ExpandListTemplate,
|
|
332
|
+
},
|
|
333
|
+
true,
|
|
334
|
+
),
|
|
335
|
+
}}
|
|
333
336
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
337
|
+
// onSelectionChanged={(newSelection) => {
|
|
338
|
+
// console.log("选区发生变化", newSelection[0]);
|
|
339
|
+
// }}
|
|
340
|
+
/>
|
|
341
|
+
</div>
|
|
342
|
+
</Spin>
|
|
339
343
|
);
|
|
340
|
-
}
|
|
344
|
+
});
|
|
@@ -361,7 +361,7 @@ const TableRender = forwardRef(function (props, tableRef) {
|
|
|
361
361
|
|
|
362
362
|
const tableProps = {
|
|
363
363
|
className: "table-render",
|
|
364
|
-
rowKey: props
|
|
364
|
+
rowKey: props?.idKey || "id",
|
|
365
365
|
rowSelection: config?.rowSelection,
|
|
366
366
|
columns: columns,
|
|
367
367
|
dataSource: props.list,
|