@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hzab/list-render",
3
- "version": "1.10.21-alpha.3",
3
+ "version": "1.10.21-alpha.5",
4
4
  "description": "",
5
5
  "main": "src",
6
6
  "scripts": {
@@ -13,6 +13,6 @@
13
13
  }
14
14
 
15
15
  .expandList-template-indent {
16
- margin-left: 26px;
16
+ margin-left: 32px;
17
17
  }
18
18
  }
@@ -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.splice(findIndex + 1, 0, ...(props?.record?.children || []));
13
- return [...pre];
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 pre?.filter((el) => !childrenIds?.includes(el?.groupId));
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?.groupId != props?.record?.groupId);
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
- <MinusSquareOutlined
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 className={`expandList-template-name ${props?.record?.children ? "" : "expandList-template-indent"}`}>
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 onPointerDown={(e) => e.stopPropagation()}>
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" }}>{echoValue}</div>
252
+ <div style={{ height: "100%", display: "flex", alignItems: "center", justifyContent: "center" }}>
253
+ {echoValue}
254
+ </div>
251
255
  )}
252
256
  </div>
253
257
  )}
@@ -1,6 +1,7 @@
1
1
  .grid-container {
2
2
  overflow: auto;
3
3
  position: relative;
4
+ max-height: 80vh;
4
5
 
5
6
 
6
7
 
@@ -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 && item?.children) {
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?.id || columnsItem?.type,
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
- console.log(changes, "changeschangeschanges");
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
- <div className={`grid-container ${className}`} style={reactGridStyle}>
284
- <ReactGrid
285
- rows={rows}
286
- columns={tableColumns}
287
- onCellsChanged={handleCellsChanged}
288
- enableFillHandle={true}
289
- enableRangeSelection={true}
290
- horizontalStickyBreakpoint={120}
291
- // stickyLeftColumns={1}
292
- // onFocusLocationChanging={(location) => {
293
- // return false;
294
- // }}
295
- {...reactGridProps}
296
- onFocusLocationChanging={(cell: any) => {
297
- const datatypeId = cell?.columnId + cell?.rowId;
298
- window.gridEditId = datatypeId;
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
- if (["_$actions", "rowSelection"]?.includes(cell?.columnId)) {
301
- return false;
302
- }
303
+ if (["_$actions", "rowSelection"]?.includes(cell?.columnId)) {
304
+ return false;
305
+ }
303
306
 
304
- if (reactGridProps?.onFocusLocationChanging) {
305
- return reactGridProps?.onFocusLocationChanging(cell, rows);
306
- }
307
- return cell;
308
- }}
309
- customCellTemplates={{
310
- ...baseTemplate,
311
- ...reactGridProps?.customCellTemplates,
312
- _$actions: WidthWrap(
313
- {
314
- WrapComponent: ActionDom,
315
- },
316
- true,
317
- ),
318
- rowSelection: WidthWrap(
319
- {
320
- WrapComponent: CheckBoxDom,
321
- },
322
- true,
323
- ),
324
- Input: TextTemplate,
325
- Number: NumberTemplate,
326
- ExpandListTemplate: WidthWrap(
327
- {
328
- WrapComponent: ExpandListTemplate,
329
- },
330
- true,
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
- // onSelectionChanged={(newSelection) => {
335
- // console.log("选区发生变化", newSelection[0]);
336
- // }}
337
- />
338
- </div>
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.idKey || "id",
364
+ rowKey: props?.idKey || "id",
365
365
  rowSelection: config?.rowSelection,
366
366
  columns: columns,
367
367
  dataSource: props.list,