@fe-free/core 1.4.9 → 1.4.10
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 +7 -0
- package/package.json +2 -2
- package/src/crud/crud.stories.tsx +36 -1
- package/src/crud/crud.tsx +19 -1
- package/src/crud/types.tsx +21 -15
- package/src/crud/use_row_selection.tsx +1 -0
- package/src/crud/use_tips.tsx +6 -0
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fe-free/core",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"author": "",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"react-syntax-highlighter": "^15.5.0",
|
|
36
36
|
"vanilla-jsoneditor": "^0.23.1",
|
|
37
37
|
"zustand": "^4.5.4",
|
|
38
|
-
"@fe-free/tool": "1.4.
|
|
38
|
+
"@fe-free/tool": "1.4.10"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@ant-design/pro-components": "^2.8.7",
|
|
@@ -109,6 +109,34 @@ export const ReadDetail: Story = {
|
|
|
109
109
|
},
|
|
110
110
|
};
|
|
111
111
|
|
|
112
|
+
export const BatchDelete: Story = {
|
|
113
|
+
render: () => {
|
|
114
|
+
return (
|
|
115
|
+
<CRUD
|
|
116
|
+
actions={['batch_delete']}
|
|
117
|
+
tableProps={{
|
|
118
|
+
columns: [
|
|
119
|
+
{
|
|
120
|
+
title: 'id',
|
|
121
|
+
dataIndex: 'id',
|
|
122
|
+
search: true,
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
title: '名字',
|
|
126
|
+
dataIndex: 'name',
|
|
127
|
+
search: true,
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
request: fakeRequest,
|
|
131
|
+
}}
|
|
132
|
+
requestDeleteByRecords={async (records) => {
|
|
133
|
+
console.log(records);
|
|
134
|
+
}}
|
|
135
|
+
/>
|
|
136
|
+
);
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
|
|
112
140
|
export const MoreCustom: Story = {
|
|
113
141
|
render: () => {
|
|
114
142
|
const columns = [
|
|
@@ -155,6 +183,7 @@ export const MoreCustom: Story = {
|
|
|
155
183
|
return <div>自定义</div>;
|
|
156
184
|
},
|
|
157
185
|
}}
|
|
186
|
+
createButton={<Button type="primary">自定义新建文本</Button>}
|
|
158
187
|
requestDeleteByRecord={fakeDeleteByRecord}
|
|
159
188
|
deleteProps={{
|
|
160
189
|
nameIndex: 'name',
|
|
@@ -449,7 +478,13 @@ export const RowSelection: Story = {
|
|
|
449
478
|
}}
|
|
450
479
|
batchActions={[
|
|
451
480
|
{
|
|
452
|
-
btnText: '
|
|
481
|
+
btnText: '批量xxx',
|
|
482
|
+
onClick: async (_, { selectedRowKeys }) => {
|
|
483
|
+
console.log(selectedRowKeys);
|
|
484
|
+
},
|
|
485
|
+
},
|
|
486
|
+
{
|
|
487
|
+
btnText: '批量danger',
|
|
453
488
|
danger: true,
|
|
454
489
|
onClick: async (_, { selectedRowKeys }) => {
|
|
455
490
|
console.log(selectedRowKeys);
|
package/src/crud/crud.tsx
CHANGED
|
@@ -32,7 +32,8 @@ function CRUDComponent<
|
|
|
32
32
|
requestUpdateById,
|
|
33
33
|
requestUpdateByValues,
|
|
34
34
|
detailFormInstance,
|
|
35
|
-
|
|
35
|
+
requestDeleteByRecords,
|
|
36
|
+
batchActions: originBatchActions,
|
|
36
37
|
} = props;
|
|
37
38
|
|
|
38
39
|
useTips(props);
|
|
@@ -200,6 +201,23 @@ function CRUDComponent<
|
|
|
200
201
|
[actions, createButton, detailProps, handleReload, tableProps],
|
|
201
202
|
);
|
|
202
203
|
|
|
204
|
+
const batchActions = useMemo(() => {
|
|
205
|
+
const bas = [...(originBatchActions || [])];
|
|
206
|
+
|
|
207
|
+
if (actions.includes('batch_delete') && requestDeleteByRecords) {
|
|
208
|
+
const batchDeleteAction = {
|
|
209
|
+
btnText: '批量删除',
|
|
210
|
+
danger: true,
|
|
211
|
+
onClick: async (_, { selectedRows }) => {
|
|
212
|
+
await requestDeleteByRecords(selectedRows);
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
bas.push(batchDeleteAction);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return bas;
|
|
219
|
+
}, [actions, originBatchActions, requestDeleteByRecords]);
|
|
220
|
+
|
|
203
221
|
const { rowSelection, tableAlertRender, tableAlertOptionRender } = useRowSelection<
|
|
204
222
|
DataSource,
|
|
205
223
|
Key
|
package/src/crud/types.tsx
CHANGED
|
@@ -8,13 +8,27 @@ import type { TableProps } from '../table';
|
|
|
8
8
|
* read_detail 详情页查看
|
|
9
9
|
* update 编辑
|
|
10
10
|
* delete 删除
|
|
11
|
+
* batch_delete 批量删除
|
|
11
12
|
*/
|
|
12
|
-
type CRUDAction = 'create' | 'read' | 'read_detail' | 'update' | 'delete';
|
|
13
|
+
type CRUDAction = 'create' | 'read' | 'read_detail' | 'update' | 'delete' | 'batch_delete';
|
|
13
14
|
|
|
14
15
|
interface CRUDProps<DataSource = any, Key = string> {
|
|
15
16
|
/** 操作类型 */
|
|
16
17
|
actions: CRUDAction[];
|
|
17
18
|
|
|
19
|
+
// *** 表格相关 ***
|
|
20
|
+
|
|
21
|
+
/** 表格相关 */
|
|
22
|
+
tableProps: TableProps<DataSource>;
|
|
23
|
+
/** 表格操作列相关 */
|
|
24
|
+
operateColumnProps?: {
|
|
25
|
+
width?: number;
|
|
26
|
+
/** 扩展操作区域,再其他操作之前 */
|
|
27
|
+
moreOperator?: (record: DataSource) => ReactNode;
|
|
28
|
+
/** 扩展操作区域,在其他操作之后 */
|
|
29
|
+
moreOperatorAfter?: (record: DataSource) => ReactNode;
|
|
30
|
+
};
|
|
31
|
+
|
|
18
32
|
// *** 表单 ***
|
|
19
33
|
|
|
20
34
|
/** 弹窗表单,action 为 read update 时需要传递 */
|
|
@@ -38,20 +52,7 @@ interface CRUDProps<DataSource = any, Key = string> {
|
|
|
38
52
|
successText?: string | (() => string);
|
|
39
53
|
};
|
|
40
54
|
|
|
41
|
-
// *** Read
|
|
42
|
-
|
|
43
|
-
/** 表格相关 */
|
|
44
|
-
tableProps: TableProps<DataSource>;
|
|
45
|
-
/** 表格操作列相关 */
|
|
46
|
-
operateColumnProps?: {
|
|
47
|
-
width?: number;
|
|
48
|
-
/** 扩展操作区域,再其他操作之前 */
|
|
49
|
-
moreOperator?: (record: DataSource) => ReactNode;
|
|
50
|
-
/** 扩展操作区域,在其他操作之后 */
|
|
51
|
-
moreOperatorAfter?: (record: DataSource) => ReactNode;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
// *** Read 详情 ***
|
|
55
|
+
// *** Read 查看 ***
|
|
55
56
|
|
|
56
57
|
/** 获取详情接口 */
|
|
57
58
|
requestGetByRecord?: (record: DataSource) => Promise<DataSource>;
|
|
@@ -102,6 +103,11 @@ interface CRUDProps<DataSource = any, Key = string> {
|
|
|
102
103
|
successText?: string | (() => string);
|
|
103
104
|
};
|
|
104
105
|
|
|
106
|
+
// *** batch_delete 批量删除 ***
|
|
107
|
+
|
|
108
|
+
/** 批量删除接口 */
|
|
109
|
+
requestDeleteByRecords?: (records: DataSource[]) => Promise<void>;
|
|
110
|
+
|
|
105
111
|
// *** 批量操作 ***
|
|
106
112
|
|
|
107
113
|
/** 批量操作 */
|
package/src/crud/use_tips.tsx
CHANGED
|
@@ -37,6 +37,12 @@ function useTips<DataSource, Key>(props: CRUDProps<DataSource, Key>) {
|
|
|
37
37
|
console.warn('actions 包含 delete 时,需要传递 deleteProps 和 requestDeleteByRecord');
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
+
|
|
41
|
+
if (props.actions.includes('batch_delete')) {
|
|
42
|
+
if (!props.requestDeleteByRecords) {
|
|
43
|
+
console.warn('actions 包含 batch_delete 时,需要传递 requestDeleteByRecords');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
40
46
|
}, []);
|
|
41
47
|
}
|
|
42
48
|
|