@fe-free/core 1.4.11 → 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 +7 -0
- package/package.json +2 -2
- package/src/crud/crud.stories.tsx +14 -0
- package/src/crud/crud.tsx +63 -29
- package/src/crud/crud_delete.tsx +6 -1
- 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",
|
|
@@ -186,6 +186,12 @@ export const MoreCustom: Story = {
|
|
|
186
186
|
requestDeleteByRecord={fakeDeleteByRecord}
|
|
187
187
|
deleteProps={{
|
|
188
188
|
nameIndex: 'name',
|
|
189
|
+
operateIsDisabled: (record) => {
|
|
190
|
+
if (record.id % 3) {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
return true;
|
|
194
|
+
},
|
|
189
195
|
}}
|
|
190
196
|
detailForm={() => (
|
|
191
197
|
<>
|
|
@@ -201,6 +207,14 @@ export const MoreCustom: Story = {
|
|
|
201
207
|
requestGetByRecord={fakeGetByRecord}
|
|
202
208
|
requestCreateByValues={fakeCreate}
|
|
203
209
|
requestUpdateById={fakeUpdateById}
|
|
210
|
+
updateProps={{
|
|
211
|
+
operateIsDisabled: (record) => {
|
|
212
|
+
if (record.id % 3) {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
return true;
|
|
216
|
+
},
|
|
217
|
+
}}
|
|
204
218
|
/>
|
|
205
219
|
);
|
|
206
220
|
},
|
package/src/crud/crud.tsx
CHANGED
|
@@ -109,42 +109,76 @@ function CRUDComponent<
|
|
|
109
109
|
fixed: 'right',
|
|
110
110
|
width: operateColumnProps?.width || 120,
|
|
111
111
|
render: function (_, record) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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(
|
|
131
151
|
<CRUDDetail
|
|
152
|
+
key="update"
|
|
132
153
|
id={record[idField]}
|
|
133
154
|
record={record}
|
|
134
155
|
onSuccess={handleReload}
|
|
135
156
|
trigger={<a>{updateProps?.operateText || '编辑'}</a>}
|
|
136
157
|
action="update"
|
|
137
158
|
{...detailProps}
|
|
138
|
-
|
|
139
|
-
)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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}
|
|
148
182
|
{operateColumnProps?.moreOperatorAfter && operateColumnProps.moreOperatorAfter(record)}
|
|
149
183
|
</Space>
|
|
150
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 || '删除'}
|
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
|
};
|