@hzab/list-render 1.10.0-beta4 → 1.10.0-beta6
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
CHANGED
package/README.md
CHANGED
|
@@ -101,7 +101,8 @@ const listDM = useMemo(
|
|
|
101
101
|
| queryFormInitialValues | Object | | {} | 列表上方查询 Form 默认值 |
|
|
102
102
|
| queryFormIsExtendModelQuery | Boolean | | false | 列表上方查询 Form 默认值是否继承 data-model.query 置 |
|
|
103
103
|
| useFormData | boolean | 否 | | 是否使用 form data 提交数据 |
|
|
104
|
-
| isEditTable | boolean | 否 |
|
|
104
|
+
| isEditTable | boolean | 否 | false | 是否行内编辑表格 |
|
|
105
|
+
| editBtnType | cell/action | 否 | action | 编辑按钮位置 cell 各单元格内 action 操作列中 |
|
|
105
106
|
|
|
106
107
|
- fetchOnEdit 展示编辑弹框时,是否会调用一次详情接口进行回填(某些场景下,列表接口只返回部分部分字段,只有详情接口会返回全部字段);若为 false,则会使用表格列表接口返回的 row 数据进行回填
|
|
107
108
|
|
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { useState, useCallback, useRef } from "react";
|
|
2
2
|
import { Card, Slider, Rate, Form, Button } from "antd";
|
|
3
|
+
import { EditOutlined } from "@ant-design/icons";
|
|
3
4
|
import { createSchemaField, FormProvider, FormConsumer } from "@formily/react";
|
|
4
5
|
import { cloneDeep } from "lodash";
|
|
5
6
|
|
|
@@ -24,6 +25,12 @@ export interface EditableCellProps extends React.HTMLAttributes<HTMLElement> {
|
|
|
24
25
|
inputType: "number" | "text";
|
|
25
26
|
record: Item;
|
|
26
27
|
index: number;
|
|
28
|
+
editable: boolean;
|
|
29
|
+
onEdit: (record: Partial<Item> & { key: React.Key }) => void;
|
|
30
|
+
topProps: {
|
|
31
|
+
config: { hasEdit: boolean | Function };
|
|
32
|
+
editBtnType: "cell" | "action";
|
|
33
|
+
};
|
|
27
34
|
children: React.ReactNode;
|
|
28
35
|
}
|
|
29
36
|
|
|
@@ -36,13 +43,26 @@ export const EditableCell: React.FC<EditableCellProps> = ({
|
|
|
36
43
|
inputType,
|
|
37
44
|
record,
|
|
38
45
|
index,
|
|
46
|
+
onEdit,
|
|
47
|
+
editable,
|
|
48
|
+
topProps,
|
|
39
49
|
children,
|
|
40
50
|
...restProps
|
|
41
51
|
}) => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
52
|
+
const fPattern = field?.["x-pattern"];
|
|
53
|
+
const fDisplay = field?.["x-display"];
|
|
54
|
+
const { hasEdit } = topProps?.config || {};
|
|
55
|
+
//编辑按钮权限
|
|
56
|
+
const _hasEdit = hasEdit && typeof hasEdit === "function" ? hasEdit(record, index) : hasEdit !== false;
|
|
57
|
+
let _editable = _hasEdit && editable && !(fPattern === "disabled" || fPattern === "readOnly" || fDisplay === "none");
|
|
58
|
+
if (!_editable) {
|
|
59
|
+
return <td {...restProps}>{children}</td>;
|
|
60
|
+
}
|
|
61
|
+
// 编辑中状态
|
|
62
|
+
if (editing) {
|
|
63
|
+
// 使用 Schema 渲染模式
|
|
64
|
+
return (
|
|
65
|
+
<td {...restProps}>
|
|
46
66
|
<SchemaField
|
|
47
67
|
schema={{
|
|
48
68
|
type: "object",
|
|
@@ -51,11 +71,36 @@ export const EditableCell: React.FC<EditableCellProps> = ({
|
|
|
51
71
|
},
|
|
52
72
|
}}
|
|
53
73
|
/>
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
74
|
+
</td>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
// 行内单元格编辑按钮
|
|
78
|
+
const showEditIcon = topProps.editBtnType === "cell";
|
|
79
|
+
if (showEditIcon) {
|
|
80
|
+
return (
|
|
81
|
+
<td {...restProps}>
|
|
82
|
+
<div
|
|
83
|
+
className="table-cell"
|
|
84
|
+
onDoubleClick={(e) => {
|
|
85
|
+
e?.preventDefault();
|
|
86
|
+
e?.stopPropagation();
|
|
87
|
+
onEdit(record);
|
|
88
|
+
}}
|
|
89
|
+
>
|
|
90
|
+
{children}
|
|
91
|
+
<EditOutlined
|
|
92
|
+
className="table-cell-edit-icon"
|
|
93
|
+
onClick={(e) => {
|
|
94
|
+
e?.preventDefault();
|
|
95
|
+
e?.stopPropagation();
|
|
96
|
+
onEdit(record);
|
|
97
|
+
}}
|
|
98
|
+
/>
|
|
99
|
+
</div>
|
|
100
|
+
</td>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
return <td {...restProps}>{children}</td>;
|
|
59
104
|
};
|
|
60
105
|
|
|
61
106
|
export const useEditTable = (props) => {
|
|
@@ -124,10 +169,11 @@ export const useEditTable = (props) => {
|
|
|
124
169
|
};
|
|
125
170
|
|
|
126
171
|
const mergedColumns = cloneDeep(columns)?.map((col) => {
|
|
127
|
-
|
|
172
|
+
const isActions = col.key === "_$actions";
|
|
173
|
+
if (!col.editable && !isActions) {
|
|
128
174
|
return col;
|
|
129
175
|
}
|
|
130
|
-
|
|
176
|
+
|
|
131
177
|
const resCol = {
|
|
132
178
|
...col,
|
|
133
179
|
onCell: (record: Item, ...args) => ({
|
|
@@ -137,7 +183,10 @@ export const useEditTable = (props) => {
|
|
|
137
183
|
field: col.field,
|
|
138
184
|
dataIndex: col.dataIndex,
|
|
139
185
|
title: col.title,
|
|
186
|
+
editable: col.editable,
|
|
140
187
|
editing: isActions ? false : isEditing(record),
|
|
188
|
+
topProps: props.topProps,
|
|
189
|
+
onEdit,
|
|
141
190
|
}),
|
|
142
191
|
};
|
|
143
192
|
// 操作列编辑态改成保存、取消按钮
|
package/src/list-render.jsx
CHANGED
|
@@ -88,6 +88,9 @@ function TableRender(props) {
|
|
|
88
88
|
onEdit: props.onEdit,
|
|
89
89
|
onEditSubmit: props.onEditSubmit,
|
|
90
90
|
formRender,
|
|
91
|
+
components: props.components,
|
|
92
|
+
schemaScope: props.schemaScope,
|
|
93
|
+
topProps: props.topProps,
|
|
91
94
|
});
|
|
92
95
|
|
|
93
96
|
useEffect(() => {
|
|
@@ -230,7 +233,6 @@ function TableRender(props) {
|
|
|
230
233
|
|
|
231
234
|
columns.push({
|
|
232
235
|
..._colConf,
|
|
233
|
-
editable: isEditTable,
|
|
234
236
|
title: "操作",
|
|
235
237
|
key: "_$actions",
|
|
236
238
|
render: getColRender(function (text, record, index) {
|
|
@@ -242,7 +244,9 @@ function TableRender(props) {
|
|
|
242
244
|
}
|
|
243
245
|
|
|
244
246
|
//编辑按钮权限
|
|
245
|
-
const _hasEdit =
|
|
247
|
+
const _hasEdit =
|
|
248
|
+
props.topProps.editBtnType !== "cell" &&
|
|
249
|
+
(hasEdit && typeof hasEdit === "function" ? hasEdit(record, index) : hasEdit !== false);
|
|
246
250
|
|
|
247
251
|
//详情按钮权限
|
|
248
252
|
const _hasDetail =
|
|
@@ -344,6 +348,7 @@ function TableRender(props) {
|
|
|
344
348
|
expandable: config.expandable,
|
|
345
349
|
loading: props.loading,
|
|
346
350
|
onRow: config?.onRow,
|
|
351
|
+
topProps: props.topProps,
|
|
347
352
|
...props.tableProps,
|
|
348
353
|
};
|
|
349
354
|
|
|
@@ -36,10 +36,15 @@
|
|
|
36
36
|
text-overflow: ellipsis;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
.table-cell-edit-icon {
|
|
40
|
+
margin-left: 8px;
|
|
41
|
+
cursor: pointer;
|
|
42
|
+
color: var(--ant-primary-color, #1890ff);
|
|
43
|
+
}
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
.row-dragging {
|
|
42
|
-
background: #
|
|
47
|
+
background: #fff;
|
|
43
48
|
border: 1px solid #ccc;
|
|
44
49
|
display: flex;
|
|
45
50
|
justify-content: space-between;
|
|
@@ -63,4 +68,4 @@
|
|
|
63
68
|
margin-bottom: 8px;
|
|
64
69
|
margin-left: 0 !important;
|
|
65
70
|
}
|
|
66
|
-
}
|
|
71
|
+
}
|