@hzab/list-render 1.10.21-alpha.4 → 1.11.0
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/CHANGELOG.md +1 -1
- package/package.json +1 -1
- package/src/components/CellEditTable/Template/ExpandListTemplate/index.less +1 -1
- package/src/components/CellEditTable/Template/ExpandListTemplate/index.tsx +6 -3
- package/src/components/CellEditTable/Template/widthWrap.tsx +9 -4
- package/src/components/CellEditTable/index.less +1 -0
- package/src/components/CellEditTable/index.tsx +65 -58
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MinusSquareOutlined, PlusCircleOutlined } from "@ant-design/icons";
|
|
1
|
+
import { MinusCircleOutlined, MinusSquareOutlined, PlusCircleOutlined } from "@ant-design/icons";
|
|
2
2
|
import { useEffect, useState, memo } from "react";
|
|
3
3
|
import "./index.less";
|
|
4
4
|
export const ExpandListTemplate = (props) => {
|
|
@@ -63,7 +63,7 @@ export const ExpandListTemplate = (props) => {
|
|
|
63
63
|
}}
|
|
64
64
|
/>
|
|
65
65
|
) : (
|
|
66
|
-
<
|
|
66
|
+
<MinusCircleOutlined
|
|
67
67
|
className="expandList-template-icon"
|
|
68
68
|
onClick={() => {
|
|
69
69
|
props.record["expand"] = !expand;
|
|
@@ -81,7 +81,10 @@ export const ExpandListTemplate = (props) => {
|
|
|
81
81
|
</>
|
|
82
82
|
)}
|
|
83
83
|
|
|
84
|
-
<div
|
|
84
|
+
<div
|
|
85
|
+
className={`expandList-template-name ${record?.spiltTag == 0 ? "expandList-template-indent" : ""}`}
|
|
86
|
+
style={record?.spiltTag == 1 && !record?.children ? { marginLeft: "22px" } : {}}
|
|
87
|
+
>
|
|
85
88
|
{Slots?.[item?.columnId] ? colRender("", record) : record[item?.columnId]}
|
|
86
89
|
</div>
|
|
87
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
|
);
|
|
@@ -203,7 +206,7 @@ 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
211
|
if (cell?.nonEditable) {
|
|
209
212
|
return;
|
|
@@ -221,7 +224,7 @@ export const WidthWrap = (opt: any, edit = false) => {
|
|
|
221
224
|
}
|
|
222
225
|
}}
|
|
223
226
|
open={isOpen}
|
|
224
|
-
style={{ width: "100%", display: "flex", alignItems: "center" }}
|
|
227
|
+
style={{ width: "100%", display: "flex", alignItems: "center", justifyContent: "center" }}
|
|
225
228
|
value={cell[_value]}
|
|
226
229
|
options={cell.values}
|
|
227
230
|
onChange={(e) => {
|
|
@@ -246,7 +249,9 @@ export const WidthWrap = (opt: any, edit = false) => {
|
|
|
246
249
|
item={cell}
|
|
247
250
|
/>
|
|
248
251
|
) : (
|
|
249
|
-
<div style={{ height: "100%", display: "flex", alignItems: "center" }}>
|
|
252
|
+
<div style={{ height: "100%", display: "flex", alignItems: "center", justifyContent: "center" }}>
|
|
253
|
+
{echoValue}
|
|
254
|
+
</div>
|
|
250
255
|
)}
|
|
251
256
|
</div>
|
|
252
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>([]);
|
|
@@ -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,
|
|
@@ -158,6 +160,9 @@ export default function CellEditTable(props: any) {
|
|
|
158
160
|
|
|
159
161
|
// 单元格编辑回调
|
|
160
162
|
const handleCellsChanged = (changes) => {
|
|
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;
|
|
161
166
|
setRows((prevRows) => {
|
|
162
167
|
changes.forEach((change) => {
|
|
163
168
|
const changeRowIdx = prevRows.findIndex((el) => el.rowId == change.rowId);
|
|
@@ -230,7 +235,7 @@ export default function CellEditTable(props: any) {
|
|
|
230
235
|
{...props}
|
|
231
236
|
checked={
|
|
232
237
|
rowSelection?.selectedRowKeys?.includes((props?.record && props?.record[rowKey]) || "") ||
|
|
233
|
-
rowSelection?.selectedRowKeys?.length == dataSource?.length
|
|
238
|
+
(rowSelection?.selectedRowKeys?.length == dataSource?.length && dataSource?.length > 0)
|
|
234
239
|
}
|
|
235
240
|
indeterminate={
|
|
236
241
|
!props?.rowId &&
|
|
@@ -277,61 +282,63 @@ export default function CellEditTable(props: any) {
|
|
|
277
282
|
}, [query?.pageNum]);
|
|
278
283
|
|
|
279
284
|
return (
|
|
280
|
-
<
|
|
281
|
-
<
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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;
|
|
296
302
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
303
|
+
if (["_$actions", "rowSelection"]?.includes(cell?.columnId)) {
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
300
306
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
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
|
-
|
|
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
|
+
}}
|
|
330
336
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
337
|
+
// onSelectionChanged={(newSelection) => {
|
|
338
|
+
// console.log("选区发生变化", newSelection[0]);
|
|
339
|
+
// }}
|
|
340
|
+
/>
|
|
341
|
+
</div>
|
|
342
|
+
</Spin>
|
|
336
343
|
);
|
|
337
|
-
}
|
|
344
|
+
});
|