@hzab/list-render 1.10.20-alpha.0 → 1.10.20-alpha.3
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 +4 -0
- package/README.md +0 -3
- package/package.json +3 -3
- package/src/EditArrayTable/index.tsx +87 -13
- package/src/components/Formily/FormilyEditTable/EditTableCell.tsx +2 -0
- package/src/components/Formily/FormilyEditTable/EditTableRow.tsx +5 -1
- package/src/components/Formily/FormilyEditTable/index.tsx +7 -19
- package/src/components/Formily/FormilyEditTable/type.d.ts +1 -1
- package/src/components/Formily/SchemaToArrayTable.ts +18 -14
- package/src/components/Formily/useComponents.tsx +80 -0
- package/src/pagination-render/index.less +54 -11
- package/src/table-render/TableActions.tsx +95 -0
- package/src/table-render/index.jsx +23 -80
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -112,11 +112,8 @@ const listDM = useMemo(
|
|
|
112
112
|
- table-edit 整个 table 一起编辑;
|
|
113
113
|
- table-edit-show 整个 table 可 一起编辑,直接显示表单;
|
|
114
114
|
- line 编辑整行,编辑按钮在操作列;
|
|
115
|
-
- line-show 编辑整行,直接显示表单,编辑按钮在操作列;
|
|
116
115
|
- line-cell 编辑整行,操作按钮在单元格;
|
|
117
|
-
- line-cell-show 编辑整行,直接显示表单,操作按钮在单元格;
|
|
118
116
|
- cell 编辑指定单元格
|
|
119
|
-
- cell-show 编辑指定单元格,直接显示表单
|
|
120
117
|
|
|
121
118
|
#### tableConf
|
|
122
119
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hzab/list-render",
|
|
3
|
-
"version": "1.10.20-alpha.
|
|
3
|
+
"version": "1.10.20-alpha.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src",
|
|
6
6
|
"scripts": {
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"license": "ISC",
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@ant-design/icons": "^4.8.1",
|
|
28
|
-
"@hzab/data-model": "^
|
|
29
|
-
"@hzab/form-render": "^1.7.
|
|
28
|
+
"@hzab/data-model": "^2.0.2",
|
|
29
|
+
"@hzab/form-render": "^1.7.13",
|
|
30
30
|
"@hzab/formily-result-utils": "^1.2.0",
|
|
31
31
|
"@hzab/permissions": "^1.0.0",
|
|
32
32
|
"@hzab/schema-descriptions": "^1.3.0",
|
|
@@ -4,8 +4,11 @@ import { cloneDeep } from "lodash";
|
|
|
4
4
|
import { Schema } from "@formily/json-schema";
|
|
5
5
|
|
|
6
6
|
import FormRender from "@hzab/form-render";
|
|
7
|
-
import { useIndex } from "@hzab/form-render/src/components/ArrayBase";
|
|
7
|
+
import { useIndex, useArray, useRecord, SortHandle } from "@hzab/form-render/src/components/ArrayBase";
|
|
8
|
+
|
|
8
9
|
import SchemaToArrayTable from "../components/Formily/SchemaToArrayTable";
|
|
10
|
+
import { useSlotsComponents } from "../components/Formily/useComponents";
|
|
11
|
+
import TableActions from "../table-render/TableActions";
|
|
9
12
|
|
|
10
13
|
import "./index.less";
|
|
11
14
|
|
|
@@ -15,15 +18,32 @@ export interface IEditArrayTableProps {
|
|
|
15
18
|
fetchOnEdit?: boolean;
|
|
16
19
|
hasAction?: boolean;
|
|
17
20
|
hideMessage?: boolean;
|
|
21
|
+
Slots?: Object;
|
|
18
22
|
};
|
|
19
23
|
config?: {
|
|
20
24
|
isDargTable?: boolean;
|
|
21
25
|
orderColType?: string;
|
|
26
|
+
colConf?: {
|
|
27
|
+
_$actions: Object;
|
|
28
|
+
};
|
|
29
|
+
rowSelection: {
|
|
30
|
+
selectedRowKeys: any[];
|
|
31
|
+
};
|
|
32
|
+
tableProps: {
|
|
33
|
+
rowSelection: {
|
|
34
|
+
selectedRowKeys: any[];
|
|
35
|
+
};
|
|
36
|
+
};
|
|
22
37
|
};
|
|
23
38
|
schema: Schema;
|
|
24
39
|
list: Object[];
|
|
25
40
|
components: Object[];
|
|
26
41
|
schemaScope: Object;
|
|
42
|
+
onDetail;
|
|
43
|
+
onEdit;
|
|
44
|
+
onEditByTable;
|
|
45
|
+
onDel;
|
|
46
|
+
onSearch;
|
|
27
47
|
getList: () => Promise<{ list: any[] }>;
|
|
28
48
|
onEditSubmit: (val) => void;
|
|
29
49
|
handleMessage: (msg) => void;
|
|
@@ -33,13 +53,11 @@ export interface IEditArrayTableProps {
|
|
|
33
53
|
};
|
|
34
54
|
}
|
|
35
55
|
|
|
36
|
-
// TODO:
|
|
56
|
+
// TODO: 权限、列显隐
|
|
37
57
|
export const EditArrayTable = forwardRef(function (props: IEditArrayTableProps, parentRef) {
|
|
38
58
|
const { topProps, schemaScope, getList, handleMessage, config, query } = props;
|
|
39
59
|
const { hasAction, editMode } = topProps || {};
|
|
40
|
-
const { orderColType
|
|
41
|
-
|
|
42
|
-
console.log("config", config, query);
|
|
60
|
+
const { orderColType, tableProps } = config || {};
|
|
43
61
|
|
|
44
62
|
const [editing, setEditing] = useState(false);
|
|
45
63
|
const [loading, setLoading] = useState(false);
|
|
@@ -52,16 +70,15 @@ export const EditArrayTable = forwardRef(function (props: IEditArrayTableProps,
|
|
|
52
70
|
const schema = useMemo(() => {
|
|
53
71
|
const schemaToArrayTable = new SchemaToArrayTable({
|
|
54
72
|
schema: props.schema,
|
|
55
|
-
|
|
73
|
+
config: { hasAction, hasIndex: orderColType === "page" || orderColType === "all", ...config },
|
|
74
|
+
topProps,
|
|
56
75
|
});
|
|
57
76
|
return schemaToArrayTable.handleSchema();
|
|
58
77
|
}, [props.schema]);
|
|
59
78
|
|
|
79
|
+
const slotComponents = useSlotsComponents(topProps);
|
|
60
80
|
const components = useMemo(() => {
|
|
61
|
-
|
|
62
|
-
TableActions() {
|
|
63
|
-
return <div>TableActions</div>;
|
|
64
|
-
},
|
|
81
|
+
const coms = {
|
|
65
82
|
TableIndex() {
|
|
66
83
|
const index = useIndex();
|
|
67
84
|
// 序号列
|
|
@@ -74,9 +91,41 @@ export const EditArrayTable = forwardRef(function (props: IEditArrayTableProps,
|
|
|
74
91
|
}
|
|
75
92
|
return null;
|
|
76
93
|
},
|
|
77
|
-
...
|
|
94
|
+
...slotComponents,
|
|
95
|
+
TableActions(tProps) {
|
|
96
|
+
const index = useIndex();
|
|
97
|
+
const array = useArray();
|
|
98
|
+
const { onDetail, onEdit, onDel, onSearch, getList } = props;
|
|
99
|
+
const record = useRecord();
|
|
100
|
+
const cProps = {
|
|
101
|
+
...tProps,
|
|
102
|
+
record,
|
|
103
|
+
index,
|
|
104
|
+
Slots: topProps.Slots,
|
|
105
|
+
onEdit,
|
|
106
|
+
onDel() {
|
|
107
|
+
array.field?.remove?.(index);
|
|
108
|
+
array.props?.onRemove?.(index);
|
|
109
|
+
onDel && onDel(record, index);
|
|
110
|
+
},
|
|
111
|
+
onDetail,
|
|
112
|
+
onSearch,
|
|
113
|
+
// TODO: 编辑删除按钮状态
|
|
114
|
+
// hasEdit,
|
|
115
|
+
// hasDel,
|
|
116
|
+
// onEditByTable,
|
|
117
|
+
getList,
|
|
118
|
+
tableConf: props.config,
|
|
119
|
+
colConf: config?.colConf?._$actions,
|
|
120
|
+
topProps,
|
|
121
|
+
};
|
|
122
|
+
return <TableActions {...cProps} />;
|
|
123
|
+
},
|
|
78
124
|
};
|
|
79
|
-
|
|
125
|
+
// HACK: 解决只读无法拖拽的问题
|
|
126
|
+
coms.ArrayTable.SortHandle = SortHandle;
|
|
127
|
+
return coms;
|
|
128
|
+
}, [slotComponents, props.query.pageNum, props.query.pageSize]);
|
|
80
129
|
|
|
81
130
|
useImperativeHandle(
|
|
82
131
|
parentRef,
|
|
@@ -92,6 +141,26 @@ export const EditArrayTable = forwardRef(function (props: IEditArrayTableProps,
|
|
|
92
141
|
}
|
|
93
142
|
}, [props.list]);
|
|
94
143
|
|
|
144
|
+
useEffect(() => {
|
|
145
|
+
// 动态设置 table props 值
|
|
146
|
+
formRef.current.formRender.setFieldState("arrayTable", (state) => {
|
|
147
|
+
let rowSelection;
|
|
148
|
+
if (config.rowSelection || tableProps?.rowSelection) {
|
|
149
|
+
rowSelection = {
|
|
150
|
+
...state.componentProps?.rowSelection,
|
|
151
|
+
...tableProps?.rowSelection,
|
|
152
|
+
...config.rowSelection,
|
|
153
|
+
selectedRowKeys: config.rowSelection?.selectedRowKeys || tableProps?.rowSelection?.selectedRowKeys,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
state.componentProps = {
|
|
157
|
+
...state.componentProps,
|
|
158
|
+
...tableProps,
|
|
159
|
+
rowSelection,
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
}, [config.rowSelection?.selectedRowKeys, tableProps]);
|
|
163
|
+
|
|
95
164
|
function getVal() {
|
|
96
165
|
return cloneDeep(formRef.current.formRender.values.arrayTable);
|
|
97
166
|
}
|
|
@@ -186,7 +255,12 @@ export const EditArrayTable = forwardRef(function (props: IEditArrayTableProps,
|
|
|
186
255
|
className="edit-array-table-form"
|
|
187
256
|
schema={schema}
|
|
188
257
|
components={components}
|
|
189
|
-
schemaScope={
|
|
258
|
+
schemaScope={{
|
|
259
|
+
...schemaScope,
|
|
260
|
+
_data: {
|
|
261
|
+
selectedRowKeys: config?.rowSelection?.selectedRowKeys,
|
|
262
|
+
},
|
|
263
|
+
}}
|
|
190
264
|
initialValues={{}}
|
|
191
265
|
emptyValue={" "}
|
|
192
266
|
formOptions={{ readPretty: editMode !== "table-edit-show" }}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useMemo } from "react";
|
|
2
2
|
import { Form } from "antd";
|
|
3
3
|
import { createForm, onFormValuesChange, onFieldValueChange, Field } from "@formily/core";
|
|
4
4
|
import { FormProvider, FormConsumer } from "@formily/react";
|
|
@@ -55,6 +55,10 @@ export const EditTableRow: React.FC<EditableRowProps> = (props: EditableRowProps
|
|
|
55
55
|
if (rowFormMapRef) {
|
|
56
56
|
rowFormMapRef.current.set(rowId, form);
|
|
57
57
|
}
|
|
58
|
+
|
|
59
|
+
if (record) {
|
|
60
|
+
form.setValues(record);
|
|
61
|
+
}
|
|
58
62
|
return form;
|
|
59
63
|
}, [record]);
|
|
60
64
|
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import React, { useState, useCallback, useRef
|
|
2
|
-
import {
|
|
1
|
+
import React, { useState, useCallback, useRef } from "react";
|
|
2
|
+
import { Button } from "antd";
|
|
3
3
|
import { createSchemaField } from "@formily/react";
|
|
4
4
|
import { cloneDeep } from "lodash";
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import { getFormilyGlobalComponents } from "@hzab/utils/src/formily/global-components";
|
|
6
|
+
import { useSlotsComponents } from "../useComponents";
|
|
8
7
|
|
|
9
|
-
import { Item
|
|
8
|
+
import { Item } from "./type";
|
|
10
9
|
|
|
11
10
|
export const useEditTable = (props) => {
|
|
12
11
|
const { rowFormMapRef, editingInofRef, topProps, idKey, columns, onEditSubmit } = props;
|
|
13
|
-
const { editMode = "modal" } = topProps || {};
|
|
12
|
+
const { editMode = "modal", Slots } = topProps || {};
|
|
14
13
|
const preIdRef = useRef("");
|
|
15
14
|
const preIdxRef = useRef(null);
|
|
16
15
|
const preRecordRef = useRef({});
|
|
@@ -27,16 +26,7 @@ export const useEditTable = (props) => {
|
|
|
27
26
|
schemaScopeRef.current._$tempData = {};
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
const components =
|
|
31
|
-
// Upload,
|
|
32
|
-
Card,
|
|
33
|
-
Slider,
|
|
34
|
-
Rate,
|
|
35
|
-
...antdComponents,
|
|
36
|
-
...customComponents,
|
|
37
|
-
...getFormilyGlobalComponents(),
|
|
38
|
-
...props.components,
|
|
39
|
-
};
|
|
29
|
+
const components = useSlotsComponents(topProps);
|
|
40
30
|
|
|
41
31
|
const SchemaField = useCallback(
|
|
42
32
|
createSchemaField({
|
|
@@ -166,9 +156,7 @@ export const useEditTable = (props) => {
|
|
|
166
156
|
...col,
|
|
167
157
|
onCell: (record: Item, ...args) => {
|
|
168
158
|
let editing = false;
|
|
169
|
-
if (editMode === "
|
|
170
|
-
editing = true;
|
|
171
|
-
} else if (editMode === "cell") {
|
|
159
|
+
if (editMode === "cell") {
|
|
172
160
|
editing = isEditing(record) && isEditingCell(col.dataIndex);
|
|
173
161
|
} else {
|
|
174
162
|
editing = isEditing(record);
|
|
@@ -11,19 +11,21 @@ export class SchemaToArrayTable {
|
|
|
11
11
|
form: {};
|
|
12
12
|
schema: Schema;
|
|
13
13
|
};
|
|
14
|
-
|
|
14
|
+
config = {};
|
|
15
|
+
topProps = {};
|
|
15
16
|
constructor(params) {
|
|
16
|
-
const { schema,
|
|
17
|
+
const { schema, config, topProps } = params || {};
|
|
17
18
|
this._schema = cloneDeep(schema);
|
|
18
|
-
this.
|
|
19
|
+
this.config = config || {};
|
|
20
|
+
this.topProps = topProps || {};
|
|
19
21
|
}
|
|
20
22
|
/**
|
|
21
23
|
* 处理 schema,把普通的 schema 表单字段转为自增表格的列
|
|
22
24
|
* @returns
|
|
23
25
|
*/
|
|
24
26
|
handleSchema(schema = this._schema, opt?) {
|
|
25
|
-
const { isDargTable, hasAction } = opt || this.
|
|
26
|
-
const schemaTpl = this.getSchemaTpl();
|
|
27
|
+
const { isDargTable, hasAction, hasIndex } = opt || this.config;
|
|
28
|
+
const schemaTpl = this.getSchemaTpl(this.config);
|
|
27
29
|
const properties: Record<string, any> = {};
|
|
28
30
|
// schema 布局信息
|
|
29
31
|
schemaTpl.form = {
|
|
@@ -33,7 +35,7 @@ export class SchemaToArrayTable {
|
|
|
33
35
|
// 添加拖拽排序列
|
|
34
36
|
isDargTable && this.pushItem(properties, this.getSortTpl());
|
|
35
37
|
// 添加序号
|
|
36
|
-
|
|
38
|
+
hasIndex && this.pushItem(properties, this.getIndexTpl());
|
|
37
39
|
// 处理表单数据列
|
|
38
40
|
Object.keys(schema.schema?.properties).forEach((key, i) => {
|
|
39
41
|
const it = schema.schema?.properties[key];
|
|
@@ -46,10 +48,9 @@ export class SchemaToArrayTable {
|
|
|
46
48
|
// 添加操作列
|
|
47
49
|
hasAction !== false && this.pushItem(properties, this.getActionsTpl());
|
|
48
50
|
// 添加移动排序操作列
|
|
49
|
-
isDargTable && this.pushItem(properties, this.getMoveActionsTpl());
|
|
51
|
+
// isDargTable && this.pushItem(properties, this.getMoveActionsTpl());
|
|
50
52
|
|
|
51
53
|
schemaTpl.schema.properties.arrayTable.items.properties = properties;
|
|
52
|
-
console.log("schemaTpl", schemaTpl);
|
|
53
54
|
|
|
54
55
|
return schemaTpl;
|
|
55
56
|
}
|
|
@@ -109,12 +110,12 @@ export class SchemaToArrayTable {
|
|
|
109
110
|
properties[item.name]["x-index"] = Object.keys(properties).length - 1;
|
|
110
111
|
return properties;
|
|
111
112
|
}
|
|
112
|
-
sortItems() {}
|
|
113
113
|
/**
|
|
114
114
|
* 获取 schema 模板字符串
|
|
115
115
|
* @returns
|
|
116
116
|
*/
|
|
117
|
-
getSchemaTpl() {
|
|
117
|
+
getSchemaTpl(config) {
|
|
118
|
+
const { onSortStart, onSortEnd } = config || {};
|
|
118
119
|
return {
|
|
119
120
|
form: {},
|
|
120
121
|
schema: {
|
|
@@ -126,12 +127,15 @@ export class SchemaToArrayTable {
|
|
|
126
127
|
"x-component": "ArrayTable",
|
|
127
128
|
"x-validator": [],
|
|
128
129
|
"x-component-props": {
|
|
130
|
+
// TODO: ts
|
|
131
|
+
// @ts-ignore
|
|
132
|
+
...this.topProps.tableProps,
|
|
129
133
|
pagination: false,
|
|
130
|
-
onSortStart() {
|
|
131
|
-
|
|
134
|
+
onSortStart(...args) {
|
|
135
|
+
onSortStart && onSortStart(...args);
|
|
132
136
|
},
|
|
133
|
-
onSortEnd() {
|
|
134
|
-
|
|
137
|
+
onSortEnd(...args) {
|
|
138
|
+
onSortEnd && onSortEnd(...args);
|
|
135
139
|
},
|
|
136
140
|
},
|
|
137
141
|
"x-decorator-props": {},
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { Card, Slider, Rate } from "antd";
|
|
3
|
+
import { useField, useFieldSchema } from "@formily/react";
|
|
4
|
+
|
|
5
|
+
import { antdComponents, customComponents } from "@hzab/form-render";
|
|
6
|
+
import { getFormilyGlobalComponents } from "@hzab/utils/src/formily/global-components";
|
|
7
|
+
import { useIndex, useRecord } from "@hzab/form-render/src/components/ArrayBase";
|
|
8
|
+
|
|
9
|
+
export const useComponents = (props) => {
|
|
10
|
+
const components = useMemo(
|
|
11
|
+
() => ({
|
|
12
|
+
// Upload,
|
|
13
|
+
Card,
|
|
14
|
+
Slider,
|
|
15
|
+
Rate,
|
|
16
|
+
...antdComponents,
|
|
17
|
+
...customComponents,
|
|
18
|
+
...getFormilyGlobalComponents(),
|
|
19
|
+
...props.components,
|
|
20
|
+
}),
|
|
21
|
+
[props.components],
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
return components;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const useSlotsComponents = (props) => {
|
|
28
|
+
const { Slots = {} } = props;
|
|
29
|
+
|
|
30
|
+
const components = useComponents(props);
|
|
31
|
+
|
|
32
|
+
const slotsComponents = useMemo(() => {
|
|
33
|
+
const formilyComponents = {
|
|
34
|
+
...components,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const tComs = {
|
|
38
|
+
...formilyComponents,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
Object.keys(formilyComponents || {}).forEach((key) => {
|
|
42
|
+
formilyComponents[key] = function (cProps) {
|
|
43
|
+
const field = useField();
|
|
44
|
+
const index = useIndex();
|
|
45
|
+
const record = useRecord();
|
|
46
|
+
|
|
47
|
+
const fieldSchema = useFieldSchema();
|
|
48
|
+
const name = fieldSchema.name;
|
|
49
|
+
const comName = fieldSchema["x-component"];
|
|
50
|
+
const OrigCom = tComs[key];
|
|
51
|
+
|
|
52
|
+
// HACK: ArrayTable.SortHandle 类似写法问题修复
|
|
53
|
+
Object.setPrototypeOf(formilyComponents[key], OrigCom);
|
|
54
|
+
|
|
55
|
+
// 插槽
|
|
56
|
+
const SCom = Slots[name];
|
|
57
|
+
if (key === comName && SCom) {
|
|
58
|
+
const slotProps = {
|
|
59
|
+
...cProps,
|
|
60
|
+
index,
|
|
61
|
+
record,
|
|
62
|
+
text: cProps.value,
|
|
63
|
+
field: field,
|
|
64
|
+
fieldSchema: fieldSchema,
|
|
65
|
+
/** 原始组件 */
|
|
66
|
+
OrigCom,
|
|
67
|
+
};
|
|
68
|
+
return <SCom {...slotProps} />;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return <OrigCom {...cProps} />;
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
return formilyComponents;
|
|
75
|
+
}, [components]);
|
|
76
|
+
|
|
77
|
+
return slotsComponents;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export default useComponents;
|
|
@@ -1,11 +1,54 @@
|
|
|
1
|
-
.pagination-render-wrap {
|
|
2
|
-
display: flex;
|
|
3
|
-
justify-content: flex-end;
|
|
4
|
-
align-items: center;
|
|
5
|
-
padding-top: 20px;
|
|
6
|
-
.pagination-render {
|
|
7
|
-
li {
|
|
8
|
-
margin-bottom: 8px;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
1
|
+
.pagination-render-wrap {
|
|
2
|
+
display: flex;
|
|
3
|
+
justify-content: flex-end;
|
|
4
|
+
align-items: center;
|
|
5
|
+
padding-top: 20px;
|
|
6
|
+
.pagination-render {
|
|
7
|
+
li {
|
|
8
|
+
margin-bottom: 8px;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
.pagination-infinity {
|
|
12
|
+
.ant-pagination-options {
|
|
13
|
+
.rc-virtual-list-holder-inner {
|
|
14
|
+
.ant-select-item {
|
|
15
|
+
&:last-child {
|
|
16
|
+
.ant-select-item-option-content {
|
|
17
|
+
position: relative;
|
|
18
|
+
color: transparent;
|
|
19
|
+
&::after {
|
|
20
|
+
color: rgba(0, 0, 0, 0.85);
|
|
21
|
+
cursor: pointer;
|
|
22
|
+
transition: background 0.3s ease;
|
|
23
|
+
content: "全部";
|
|
24
|
+
position: absolute;
|
|
25
|
+
left: 0;
|
|
26
|
+
top: 0;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
.pagination-infinity-checked {
|
|
35
|
+
.ant-pagination-options {
|
|
36
|
+
.ant-select-selector {
|
|
37
|
+
.ant-select-selection-item {
|
|
38
|
+
position: relative;
|
|
39
|
+
color: transparent;
|
|
40
|
+
&::after {
|
|
41
|
+
color: rgba(0, 0, 0, 0.85);
|
|
42
|
+
cursor: pointer;
|
|
43
|
+
transition: background 0.3s ease;
|
|
44
|
+
content: "全部";
|
|
45
|
+
position: absolute;
|
|
46
|
+
left: 0;
|
|
47
|
+
top: 0;
|
|
48
|
+
visibility: visible;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Form, Table, Button, Popconfirm, Tooltip, Checkbox, Popover } from "antd";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 编辑按钮隐藏
|
|
5
|
+
*/
|
|
6
|
+
export const editModeHideList = ["cell", "line-cell"];
|
|
7
|
+
|
|
8
|
+
export function TableActions(props) {
|
|
9
|
+
const {
|
|
10
|
+
text,
|
|
11
|
+
record,
|
|
12
|
+
index,
|
|
13
|
+
topProps,
|
|
14
|
+
tableConf,
|
|
15
|
+
colConf,
|
|
16
|
+
onEditByTable,
|
|
17
|
+
onDetail,
|
|
18
|
+
onEdit,
|
|
19
|
+
onDel,
|
|
20
|
+
onSearch,
|
|
21
|
+
getList,
|
|
22
|
+
} = props;
|
|
23
|
+
const { idKey = "id", i18n, Slots, editMode = "modal" } = topProps || {};
|
|
24
|
+
const { tableDel = "删除", tableEdit = "编辑", tableDelTip = "确认删除该项?", tableDetail = "详情" } = i18n || {};
|
|
25
|
+
|
|
26
|
+
const slotProps = { text, record, index, onEdit: onEdit, onDel: onDel, onSearch, getList };
|
|
27
|
+
|
|
28
|
+
if (Slots?.tableActionsSlot) {
|
|
29
|
+
return <Slots.tableActionsSlot {...slotProps} />;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const { hasEdit, hasDel, hasDelTips, hasDetail = false } = tableConf || {};
|
|
33
|
+
|
|
34
|
+
// 编辑按钮权限
|
|
35
|
+
const _hasEdit =
|
|
36
|
+
!editModeHideList.includes(editMode) &&
|
|
37
|
+
(hasEdit && typeof hasEdit === "function" ? hasEdit(record, index) : hasEdit !== false);
|
|
38
|
+
|
|
39
|
+
// 详情按钮权限
|
|
40
|
+
const _hasDetail = hasDetail && typeof hasDetail === "function" ? hasDetail(record, index) : hasDetail !== false;
|
|
41
|
+
|
|
42
|
+
// 删除按钮权限
|
|
43
|
+
const _hasDel = hasDel && typeof hasDel === "function" ? hasDel(record, index) : hasDel !== false;
|
|
44
|
+
|
|
45
|
+
// 删除按钮提示
|
|
46
|
+
const delTips =
|
|
47
|
+
hasDelTips && typeof hasDelTips === "function" ? hasDelTips(record, index) : hasDelTips || tableDelTip;
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<div style={{ width: colConf?.width, maxWidth: "100%" }}>
|
|
51
|
+
{Slots?.actionPrefixSlot && <Slots.actionPrefixSlot {...slotProps} />}
|
|
52
|
+
{_hasDetail ? (
|
|
53
|
+
<Button
|
|
54
|
+
type="link"
|
|
55
|
+
onClick={() => {
|
|
56
|
+
onDetail && onDetail(record, index);
|
|
57
|
+
}}
|
|
58
|
+
>
|
|
59
|
+
{tableDetail}
|
|
60
|
+
</Button>
|
|
61
|
+
) : null}
|
|
62
|
+
{_hasEdit ? (
|
|
63
|
+
<Button
|
|
64
|
+
type="link"
|
|
65
|
+
onClick={() => {
|
|
66
|
+
onEdit && onEdit(record, index);
|
|
67
|
+
if (editMode == "line") {
|
|
68
|
+
// 整行编辑,编辑按钮在操作列的模式下表单数据回填
|
|
69
|
+
return onEditByTable(record, record[idKey]);
|
|
70
|
+
}
|
|
71
|
+
}}
|
|
72
|
+
>
|
|
73
|
+
{tableEdit}
|
|
74
|
+
</Button>
|
|
75
|
+
) : null}
|
|
76
|
+
{Slots?.actionCenterSlot && <Slots.actionCenterSlot {...slotProps} />}
|
|
77
|
+
{_hasDel ? (
|
|
78
|
+
<Popconfirm
|
|
79
|
+
placement="topRight"
|
|
80
|
+
title={delTips}
|
|
81
|
+
onConfirm={() => {
|
|
82
|
+
onDel && onDel(record, index);
|
|
83
|
+
}}
|
|
84
|
+
>
|
|
85
|
+
<Button type="link" danger>
|
|
86
|
+
{tableDel}
|
|
87
|
+
</Button>
|
|
88
|
+
</Popconfirm>
|
|
89
|
+
) : null}
|
|
90
|
+
{Slots?.actionSuffixSlot && <Slots.actionSuffixSlot {...slotProps} />}
|
|
91
|
+
</div>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export default TableActions;
|
|
@@ -17,16 +17,12 @@ import { useEditTable } from "../components/Formily/FormilyEditTable";
|
|
|
17
17
|
import { EditTableRow } from "../components/Formily/FormilyEditTable/EditTableRow";
|
|
18
18
|
import { EditableCell } from "../components/Formily/FormilyEditTable/EditTableCell";
|
|
19
19
|
import { TableFormilyContext } from "../components/Formily/FormilyEditTable/useTableFormilyContext";
|
|
20
|
+
import TableActions from "./TableActions";
|
|
20
21
|
|
|
21
22
|
import "./index.less";
|
|
22
23
|
|
|
23
24
|
const scenario = "table-render";
|
|
24
25
|
|
|
25
|
-
/**
|
|
26
|
-
* 编辑按钮隐藏
|
|
27
|
-
*/
|
|
28
|
-
const editModeHideList = ["cell", "line-cell", "table-line-show"];
|
|
29
|
-
|
|
30
26
|
const TableRender = forwardRef(function (props, tableRef) {
|
|
31
27
|
const { topProps, config = {}, query = {}, i18n, setList, schema } = props;
|
|
32
28
|
const propsSchema = schema?.schema;
|
|
@@ -35,7 +31,7 @@ const TableRender = forwardRef(function (props, tableRef) {
|
|
|
35
31
|
dragColConf = {},
|
|
36
32
|
isDargTable,
|
|
37
33
|
dargEndBack,
|
|
38
|
-
orderColType
|
|
34
|
+
orderColType,
|
|
39
35
|
orderColWidth,
|
|
40
36
|
tableEmptyValue,
|
|
41
37
|
isShowTableFilter = false,
|
|
@@ -133,10 +129,7 @@ const TableRender = forwardRef(function (props, tableRef) {
|
|
|
133
129
|
}
|
|
134
130
|
|
|
135
131
|
const { Slots = {} } = props;
|
|
136
|
-
const _fieldList =
|
|
137
|
-
scope: props.schemaScope,
|
|
138
|
-
formilyRef,
|
|
139
|
-
});
|
|
132
|
+
const _fieldList = fieldList;
|
|
140
133
|
_fieldList.forEach((field, colIndex) => {
|
|
141
134
|
const fieldSchemas = formilyRef.current?.fields;
|
|
142
135
|
if (!field["x-decorator-props"]) {
|
|
@@ -256,74 +249,23 @@ const TableRender = forwardRef(function (props, tableRef) {
|
|
|
256
249
|
title: "操作",
|
|
257
250
|
key: "_$actions",
|
|
258
251
|
render: getColRender(function (text, record, index) {
|
|
259
|
-
const { onEdit, onDel, onSearch, getList } = props;
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
//删除按钮权限
|
|
277
|
-
const _hasDel = hasDel && typeof hasDel === "function" ? hasDel(record, index) : hasDel !== false;
|
|
278
|
-
|
|
279
|
-
//删除按钮提示
|
|
280
|
-
const delTips =
|
|
281
|
-
hasDelTips && typeof hasDelTips === "function" ? hasDelTips(record, index) : hasDelTips || tableDelTip;
|
|
282
|
-
|
|
283
|
-
return (
|
|
284
|
-
<div style={{ width: _colConf?.width, maxWidth: "100%" }}>
|
|
285
|
-
{Slots?.actionPrefixSlot && <Slots.actionPrefixSlot {...slotProps} />}
|
|
286
|
-
{_hasDetail ? (
|
|
287
|
-
<Button
|
|
288
|
-
type="link"
|
|
289
|
-
onClick={() => {
|
|
290
|
-
props.onDetail && props.onDetail(record, index);
|
|
291
|
-
}}
|
|
292
|
-
>
|
|
293
|
-
{tableDetail}
|
|
294
|
-
</Button>
|
|
295
|
-
) : null}
|
|
296
|
-
{_hasEdit ? (
|
|
297
|
-
<Button
|
|
298
|
-
type="link"
|
|
299
|
-
onClick={() => {
|
|
300
|
-
props.onEdit && props.onEdit(record, index);
|
|
301
|
-
if (editMode == "line") {
|
|
302
|
-
// 整行编辑,编辑按钮在操作列的模式下表单数据回填
|
|
303
|
-
return onEditByTable(record, record[props.idKey]);
|
|
304
|
-
}
|
|
305
|
-
}}
|
|
306
|
-
>
|
|
307
|
-
{tableEdit}
|
|
308
|
-
</Button>
|
|
309
|
-
) : null}
|
|
310
|
-
{Slots?.actionCenterSlot && <Slots.actionCenterSlot {...slotProps} />}
|
|
311
|
-
{_hasDel ? (
|
|
312
|
-
<Popconfirm
|
|
313
|
-
placement="topRight"
|
|
314
|
-
title={delTips}
|
|
315
|
-
onConfirm={() => {
|
|
316
|
-
props.onDel && props.onDel(record, index);
|
|
317
|
-
}}
|
|
318
|
-
>
|
|
319
|
-
<Button type="link" danger>
|
|
320
|
-
{tableDel}
|
|
321
|
-
</Button>
|
|
322
|
-
</Popconfirm>
|
|
323
|
-
) : null}
|
|
324
|
-
{Slots?.actionSuffixSlot && <Slots.actionSuffixSlot {...slotProps} />}
|
|
325
|
-
</div>
|
|
326
|
-
);
|
|
252
|
+
const { onDetail, onEdit, onDel, onSearch, getList } = props;
|
|
253
|
+
const cProps = {
|
|
254
|
+
text,
|
|
255
|
+
record,
|
|
256
|
+
index,
|
|
257
|
+
Slots,
|
|
258
|
+
onEdit,
|
|
259
|
+
onDel,
|
|
260
|
+
onDetail,
|
|
261
|
+
onSearch,
|
|
262
|
+
onEditByTable,
|
|
263
|
+
getList,
|
|
264
|
+
tableConf: props.config,
|
|
265
|
+
colConf: _colConf,
|
|
266
|
+
topProps,
|
|
267
|
+
};
|
|
268
|
+
return <TableActions {...cProps} />;
|
|
327
269
|
}),
|
|
328
270
|
});
|
|
329
271
|
}
|
|
@@ -364,8 +306,10 @@ const TableRender = forwardRef(function (props, tableRef) {
|
|
|
364
306
|
scroll: config.scroll,
|
|
365
307
|
expandable: config.expandable,
|
|
366
308
|
loading: props.loading,
|
|
309
|
+
...props.tableProps,
|
|
367
310
|
onRow: (record, index) => {
|
|
368
|
-
const
|
|
311
|
+
const _onRow = config?.onRow ?? props.tableProps?.onRow;
|
|
312
|
+
const _onRowRes = _onRow && _onRow(record, index);
|
|
369
313
|
return {
|
|
370
314
|
..._onRowRes,
|
|
371
315
|
record,
|
|
@@ -378,7 +322,6 @@ const TableRender = forwardRef(function (props, tableRef) {
|
|
|
378
322
|
};
|
|
379
323
|
},
|
|
380
324
|
topProps: props.topProps,
|
|
381
|
-
...props.tableProps,
|
|
382
325
|
};
|
|
383
326
|
|
|
384
327
|
tableProps.columns = mergedColumns;
|