@fe-free/core 1.4.10 → 1.4.12
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 +20 -15
- package/src/crud/crud.tsx +64 -32
- package/src/crud/crud_delete.tsx +6 -1
- package/src/crud/crud_of_simple.stories.tsx +2 -4
- package/src/crud/types.tsx +8 -3
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.12",
|
|
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.12"
|
|
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
|
|
@@ -187,11 +186,16 @@ export const MoreCustom: Story = {
|
|
|
187
186
|
requestDeleteByRecord={fakeDeleteByRecord}
|
|
188
187
|
deleteProps={{
|
|
189
188
|
nameIndex: 'name',
|
|
189
|
+
operateIsDisabled: (record) => {
|
|
190
|
+
if (record.id % 3) {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
return true;
|
|
194
|
+
},
|
|
190
195
|
}}
|
|
191
|
-
detailForm={(
|
|
196
|
+
detailForm={() => (
|
|
192
197
|
<>
|
|
193
198
|
<ProFormText
|
|
194
|
-
{...formProps}
|
|
195
199
|
name="name"
|
|
196
200
|
label="名字"
|
|
197
201
|
required
|
|
@@ -203,6 +207,14 @@ export const MoreCustom: Story = {
|
|
|
203
207
|
requestGetByRecord={fakeGetByRecord}
|
|
204
208
|
requestCreateByValues={fakeCreate}
|
|
205
209
|
requestUpdateById={fakeUpdateById}
|
|
210
|
+
updateProps={{
|
|
211
|
+
operateIsDisabled: (record) => {
|
|
212
|
+
if (record.id % 3) {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
return true;
|
|
216
|
+
},
|
|
217
|
+
}}
|
|
206
218
|
/>
|
|
207
219
|
);
|
|
208
220
|
},
|
|
@@ -235,17 +247,16 @@ const FormRefComponent = () => {
|
|
|
235
247
|
request: fakeRequest,
|
|
236
248
|
}}
|
|
237
249
|
detailFormInstance={detailFormInstance}
|
|
238
|
-
detailForm={(
|
|
250
|
+
detailForm={() => (
|
|
239
251
|
<>
|
|
240
252
|
<ProFormText
|
|
241
|
-
{...formProps}
|
|
242
253
|
name="name"
|
|
243
254
|
label="名字"
|
|
244
255
|
required
|
|
245
256
|
rules={[{ required: true }]}
|
|
246
257
|
initialValue={'default'}
|
|
247
258
|
/>
|
|
248
|
-
<ProFormSwitch
|
|
259
|
+
<ProFormSwitch name="status" label="开启" initialValue={false} />
|
|
249
260
|
</>
|
|
250
261
|
)}
|
|
251
262
|
requestGetByRecord={fakeGetByRecord}
|
|
@@ -437,15 +448,9 @@ export const CustomText: Story = {
|
|
|
437
448
|
successText: '编辑成功',
|
|
438
449
|
}}
|
|
439
450
|
requestDeleteByRecord={fakeDeleteByRecord}
|
|
440
|
-
detailForm={(
|
|
451
|
+
detailForm={() => (
|
|
441
452
|
<>
|
|
442
|
-
<ProFormText
|
|
443
|
-
{...formProps}
|
|
444
|
-
name="name"
|
|
445
|
-
label="名字"
|
|
446
|
-
required
|
|
447
|
-
rules={[{ required: true }]}
|
|
448
|
-
/>
|
|
453
|
+
<ProFormText name="name" label="名字" required rules={[{ required: true }]} />
|
|
449
454
|
</>
|
|
450
455
|
)}
|
|
451
456
|
requestGetByRecord={fakeGetByRecord}
|
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';
|
|
@@ -108,45 +109,76 @@ function CRUDComponent<
|
|
|
108
109
|
fixed: 'right',
|
|
109
110
|
width: operateColumnProps?.width || 120,
|
|
110
111
|
render: function (_, record) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
112
|
+
const btns: React.ReactNode[] = [];
|
|
113
|
+
|
|
114
|
+
if (actions.includes('read')) {
|
|
115
|
+
btns.push(
|
|
116
|
+
<CRUDDetail
|
|
117
|
+
key="read"
|
|
118
|
+
id={record[idField]}
|
|
119
|
+
record={record}
|
|
120
|
+
onSuccess={handleReload}
|
|
121
|
+
trigger={<a>{readProps?.operateText || '查看'}</a>}
|
|
122
|
+
action="read"
|
|
123
|
+
{...detailProps}
|
|
124
|
+
/>,
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (actions.includes('read_detail')) {
|
|
129
|
+
btns.push(
|
|
130
|
+
<Link
|
|
131
|
+
key="read_detail"
|
|
132
|
+
to={`./detail/${record[detailIdIndex || 'id']}`}
|
|
133
|
+
target={readProps?.target}
|
|
134
|
+
>
|
|
135
|
+
{readProps?.operateText || '查看'}
|
|
136
|
+
</Link>,
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (actions.includes('update')) {
|
|
141
|
+
const disabled = updateProps?.operateIsDisabled?.(record) || false;
|
|
142
|
+
|
|
143
|
+
if (disabled) {
|
|
144
|
+
btns.push(
|
|
145
|
+
<a key="update" disabled>
|
|
146
|
+
{updateProps?.operateText || '编辑'}
|
|
147
|
+
</a>,
|
|
148
|
+
);
|
|
149
|
+
} else {
|
|
150
|
+
btns.push(
|
|
133
151
|
<CRUDDetail
|
|
152
|
+
key="update"
|
|
134
153
|
id={record[idField]}
|
|
135
154
|
record={record}
|
|
136
155
|
onSuccess={handleReload}
|
|
137
156
|
trigger={<a>{updateProps?.operateText || '编辑'}</a>}
|
|
138
157
|
action="update"
|
|
139
158
|
{...detailProps}
|
|
140
|
-
|
|
141
|
-
)
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
159
|
+
/>,
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (actions.includes('delete') && deleteProps) {
|
|
165
|
+
const disabled = deleteProps?.operateIsDisabled?.(record) || false;
|
|
166
|
+
btns.push(
|
|
167
|
+
<OperateDelete
|
|
168
|
+
key="delete"
|
|
169
|
+
name={record[deleteProps.nameIndex]}
|
|
170
|
+
desc={deleteProps.desc}
|
|
171
|
+
operateText={deleteProps.operateText}
|
|
172
|
+
disabled={disabled}
|
|
173
|
+
onDelete={getHandleDelete(record)}
|
|
174
|
+
/>,
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return (
|
|
179
|
+
<Space>
|
|
180
|
+
{operateColumnProps?.moreOperator && operateColumnProps.moreOperator(record)}
|
|
181
|
+
{btns}
|
|
150
182
|
{operateColumnProps?.moreOperatorAfter && operateColumnProps.moreOperatorAfter(record)}
|
|
151
183
|
</Space>
|
|
152
184
|
);
|
package/src/crud/crud_delete.tsx
CHANGED
|
@@ -6,6 +6,7 @@ interface Params {
|
|
|
6
6
|
desc?: string;
|
|
7
7
|
operateText?: string;
|
|
8
8
|
onDelete: () => Promise<any>;
|
|
9
|
+
disabled?: boolean;
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
function useDelete(params: Params) {
|
|
@@ -34,9 +35,13 @@ function useDelete(params: Params) {
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
function OperateDelete(props: Params) {
|
|
37
|
-
const { name, desc, onDelete, operateText } = props;
|
|
38
|
+
const { name, desc, onDelete, operateText, disabled } = props;
|
|
38
39
|
const { doDelete } = useDelete({ name, desc, onDelete, operateText });
|
|
39
40
|
|
|
41
|
+
if (disabled) {
|
|
42
|
+
return <a disabled>{operateText || '删除'}</a>;
|
|
43
|
+
}
|
|
44
|
+
|
|
40
45
|
return (
|
|
41
46
|
<a style={{ color: 'red' }} onClick={doDelete}>
|
|
42
47
|
{operateText || '删除'}
|
|
@@ -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
|
@@ -77,8 +77,10 @@ interface CRUDProps<DataSource = any, Key = string> {
|
|
|
77
77
|
/** @deprecated 请使用 requestUpdateByValues 替代 */
|
|
78
78
|
requestUpdateById?: (values: Partial<DataSource>) => Promise<false | void>;
|
|
79
79
|
updateProps?: {
|
|
80
|
-
/**
|
|
80
|
+
/** 文本“编辑” */
|
|
81
81
|
operateText?: string;
|
|
82
|
+
/** ”编辑”是否禁用 */
|
|
83
|
+
operateIsDisabled?: (record: DataSource) => boolean;
|
|
82
84
|
/** 保存按钮文本 */
|
|
83
85
|
submitText?: string;
|
|
84
86
|
/** 重置按钮文本 */
|
|
@@ -93,12 +95,15 @@ interface CRUDProps<DataSource = any, Key = string> {
|
|
|
93
95
|
requestDeleteByRecord?: (record: DataSource) => Promise<void>;
|
|
94
96
|
/** 删除相关 */
|
|
95
97
|
deleteProps?: {
|
|
98
|
+
/** 文本“删除” */
|
|
99
|
+
operateText?: string;
|
|
100
|
+
/** “删除”是否禁用 */
|
|
101
|
+
operateIsDisabled?: (record: DataSource) => boolean;
|
|
96
102
|
/** 显示名称索引 */
|
|
97
103
|
nameIndex: keyof DataSource;
|
|
98
104
|
/** 删除确认描述 */
|
|
99
105
|
desc?: string;
|
|
100
|
-
|
|
101
|
-
operateText?: string;
|
|
106
|
+
|
|
102
107
|
/** 成功文案 */
|
|
103
108
|
successText?: string | (() => string);
|
|
104
109
|
};
|