@fe-free/core 1.4.9 → 1.4.11
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 +14 -0
- package/package.json +2 -2
- package/src/crud/crud.stories.tsx +42 -16
- package/src/crud/crud.tsx +22 -6
- package/src/crud/crud_of_simple.stories.tsx +2 -4
- 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.11",
|
|
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.11"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@ant-design/pro-components": "^2.8.7",
|
|
@@ -61,10 +61,9 @@ export const Normal: Story = {
|
|
|
61
61
|
deleteProps={{
|
|
62
62
|
nameIndex: 'name',
|
|
63
63
|
}}
|
|
64
|
-
detailForm={(
|
|
64
|
+
detailForm={() => (
|
|
65
65
|
<>
|
|
66
66
|
<ProFormText
|
|
67
|
-
{...formProps}
|
|
68
67
|
name="name"
|
|
69
68
|
label="名字"
|
|
70
69
|
required
|
|
@@ -109,6 +108,34 @@ export const ReadDetail: Story = {
|
|
|
109
108
|
},
|
|
110
109
|
};
|
|
111
110
|
|
|
111
|
+
export const BatchDelete: Story = {
|
|
112
|
+
render: () => {
|
|
113
|
+
return (
|
|
114
|
+
<CRUD
|
|
115
|
+
actions={['batch_delete']}
|
|
116
|
+
tableProps={{
|
|
117
|
+
columns: [
|
|
118
|
+
{
|
|
119
|
+
title: 'id',
|
|
120
|
+
dataIndex: 'id',
|
|
121
|
+
search: true,
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
title: '名字',
|
|
125
|
+
dataIndex: 'name',
|
|
126
|
+
search: true,
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
request: fakeRequest,
|
|
130
|
+
}}
|
|
131
|
+
requestDeleteByRecords={async (records) => {
|
|
132
|
+
console.log(records);
|
|
133
|
+
}}
|
|
134
|
+
/>
|
|
135
|
+
);
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
|
|
112
139
|
export const MoreCustom: Story = {
|
|
113
140
|
render: () => {
|
|
114
141
|
const columns = [
|
|
@@ -155,14 +182,14 @@ export const MoreCustom: Story = {
|
|
|
155
182
|
return <div>自定义</div>;
|
|
156
183
|
},
|
|
157
184
|
}}
|
|
185
|
+
createButton={<Button type="primary">自定义新建文本</Button>}
|
|
158
186
|
requestDeleteByRecord={fakeDeleteByRecord}
|
|
159
187
|
deleteProps={{
|
|
160
188
|
nameIndex: 'name',
|
|
161
189
|
}}
|
|
162
|
-
detailForm={(
|
|
190
|
+
detailForm={() => (
|
|
163
191
|
<>
|
|
164
192
|
<ProFormText
|
|
165
|
-
{...formProps}
|
|
166
193
|
name="name"
|
|
167
194
|
label="名字"
|
|
168
195
|
required
|
|
@@ -206,17 +233,16 @@ const FormRefComponent = () => {
|
|
|
206
233
|
request: fakeRequest,
|
|
207
234
|
}}
|
|
208
235
|
detailFormInstance={detailFormInstance}
|
|
209
|
-
detailForm={(
|
|
236
|
+
detailForm={() => (
|
|
210
237
|
<>
|
|
211
238
|
<ProFormText
|
|
212
|
-
{...formProps}
|
|
213
239
|
name="name"
|
|
214
240
|
label="名字"
|
|
215
241
|
required
|
|
216
242
|
rules={[{ required: true }]}
|
|
217
243
|
initialValue={'default'}
|
|
218
244
|
/>
|
|
219
|
-
<ProFormSwitch
|
|
245
|
+
<ProFormSwitch name="status" label="开启" initialValue={false} />
|
|
220
246
|
</>
|
|
221
247
|
)}
|
|
222
248
|
requestGetByRecord={fakeGetByRecord}
|
|
@@ -408,15 +434,9 @@ export const CustomText: Story = {
|
|
|
408
434
|
successText: '编辑成功',
|
|
409
435
|
}}
|
|
410
436
|
requestDeleteByRecord={fakeDeleteByRecord}
|
|
411
|
-
detailForm={(
|
|
437
|
+
detailForm={() => (
|
|
412
438
|
<>
|
|
413
|
-
<ProFormText
|
|
414
|
-
{...formProps}
|
|
415
|
-
name="name"
|
|
416
|
-
label="名字"
|
|
417
|
-
required
|
|
418
|
-
rules={[{ required: true }]}
|
|
419
|
-
/>
|
|
439
|
+
<ProFormText name="name" label="名字" required rules={[{ required: true }]} />
|
|
420
440
|
</>
|
|
421
441
|
)}
|
|
422
442
|
requestGetByRecord={fakeGetByRecord}
|
|
@@ -449,7 +469,13 @@ export const RowSelection: Story = {
|
|
|
449
469
|
}}
|
|
450
470
|
batchActions={[
|
|
451
471
|
{
|
|
452
|
-
btnText: '
|
|
472
|
+
btnText: '批量xxx',
|
|
473
|
+
onClick: async (_, { selectedRowKeys }) => {
|
|
474
|
+
console.log(selectedRowKeys);
|
|
475
|
+
},
|
|
476
|
+
},
|
|
477
|
+
{
|
|
478
|
+
btnText: '批量danger',
|
|
453
479
|
danger: true,
|
|
454
480
|
onClick: async (_, { selectedRowKeys }) => {
|
|
455
481
|
console.log(selectedRowKeys);
|
package/src/crud/crud.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import type { ActionType } from '@ant-design/pro-components';
|
|
|
2
2
|
import { Button, message, Space } from 'antd';
|
|
3
3
|
import { isString } from 'lodash-es';
|
|
4
4
|
import { forwardRef, useCallback, useImperativeHandle, useMemo, useRef } from 'react';
|
|
5
|
+
import { Link } from 'react-router-dom';
|
|
5
6
|
import type { TableProps } from '../table';
|
|
6
7
|
import { Table } from '../table';
|
|
7
8
|
import { OperateDelete } from './crud_delete';
|
|
@@ -32,7 +33,8 @@ function CRUDComponent<
|
|
|
32
33
|
requestUpdateById,
|
|
33
34
|
requestUpdateByValues,
|
|
34
35
|
detailFormInstance,
|
|
35
|
-
|
|
36
|
+
requestDeleteByRecords,
|
|
37
|
+
batchActions: originBatchActions,
|
|
36
38
|
} = props;
|
|
37
39
|
|
|
38
40
|
useTips(props);
|
|
@@ -121,12 +123,9 @@ function CRUDComponent<
|
|
|
121
123
|
/>
|
|
122
124
|
)}
|
|
123
125
|
{actions.includes('read_detail') && (
|
|
124
|
-
<
|
|
125
|
-
href={`${window.location.pathname}/detail/${record[detailIdIndex || 'id']}`}
|
|
126
|
-
target={readProps?.target}
|
|
127
|
-
>
|
|
126
|
+
<Link to={`./detail/${record[detailIdIndex || 'id']}`} target={readProps?.target}>
|
|
128
127
|
{readProps?.operateText || '查看'}
|
|
129
|
-
</
|
|
128
|
+
</Link>
|
|
130
129
|
)}
|
|
131
130
|
{actions.includes('update') && (
|
|
132
131
|
<CRUDDetail
|
|
@@ -200,6 +199,23 @@ function CRUDComponent<
|
|
|
200
199
|
[actions, createButton, detailProps, handleReload, tableProps],
|
|
201
200
|
);
|
|
202
201
|
|
|
202
|
+
const batchActions = useMemo(() => {
|
|
203
|
+
const bas = [...(originBatchActions || [])];
|
|
204
|
+
|
|
205
|
+
if (actions.includes('batch_delete') && requestDeleteByRecords) {
|
|
206
|
+
const batchDeleteAction = {
|
|
207
|
+
btnText: '批量删除',
|
|
208
|
+
danger: true,
|
|
209
|
+
onClick: async (_, { selectedRows }) => {
|
|
210
|
+
await requestDeleteByRecords(selectedRows);
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
bas.push(batchDeleteAction);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return bas;
|
|
217
|
+
}, [actions, originBatchActions, requestDeleteByRecords]);
|
|
218
|
+
|
|
203
219
|
const { rowSelection, tableAlertRender, tableAlertOptionRender } = useRowSelection<
|
|
204
220
|
DataSource,
|
|
205
221
|
Key
|
|
@@ -41,10 +41,9 @@ export const Normal: Story = {
|
|
|
41
41
|
deleteProps={{
|
|
42
42
|
nameIndex: 'name',
|
|
43
43
|
}}
|
|
44
|
-
detailForm={(
|
|
44
|
+
detailForm={() => (
|
|
45
45
|
<>
|
|
46
46
|
<ProFormText
|
|
47
|
-
{...formProps}
|
|
48
47
|
name="name"
|
|
49
48
|
label="名字"
|
|
50
49
|
required
|
|
@@ -87,10 +86,9 @@ export const WithSearch: Story = {
|
|
|
87
86
|
deleteProps={{
|
|
88
87
|
nameIndex: 'name',
|
|
89
88
|
}}
|
|
90
|
-
detailForm={(
|
|
89
|
+
detailForm={() => (
|
|
91
90
|
<>
|
|
92
91
|
<ProFormText
|
|
93
|
-
{...formProps}
|
|
94
92
|
name="name"
|
|
95
93
|
label="名字"
|
|
96
94
|
required
|
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
|
|