@magicbe/antd-crud 0.0.43 → 0.0.45
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/README.md +301 -0
- package/dist/components/Action.d.ts +1 -2
- package/dist/components/Action.js +13 -7
- package/dist/components/Filter.d.ts +1 -3
- package/dist/components/Filter.js +7 -4
- package/dist/components/Table.d.ts +2 -2
- package/dist/components/Table.js +13 -7
- package/dist/components/index.js +4 -3
- package/dist/config.d.ts +7 -2
- package/dist/config.js +9 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
# @magicbe/antd-crud
|
|
2
|
+
|
|
3
|
+
一个基于 Ant Design 的 CRUD 表格组件库,简化开发中的增删改查操作。
|
|
4
|
+
|
|
5
|
+
## 特性
|
|
6
|
+
|
|
7
|
+
- 快速构建完整的 CRUD 表格界面
|
|
8
|
+
- 支持多种表单字段类型
|
|
9
|
+
- 内置筛选、新增、编辑、删除功能
|
|
10
|
+
- 可自定义操作按钮
|
|
11
|
+
- 基于 Ant Design,样式统一
|
|
12
|
+
|
|
13
|
+
## 安装
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# 使用 npm
|
|
17
|
+
npm install @magicbe/antd-crud
|
|
18
|
+
|
|
19
|
+
# 使用 yarn
|
|
20
|
+
yarn add @magicbe/antd-crud
|
|
21
|
+
|
|
22
|
+
# 使用 pnpm
|
|
23
|
+
pnpm add @magicbe/antd-crud
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 依赖
|
|
27
|
+
|
|
28
|
+
- antd: 5.22.5+
|
|
29
|
+
- react: 18.2.0+
|
|
30
|
+
- react-dom: 18.2.0+
|
|
31
|
+
|
|
32
|
+
## 基本使用
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import React from 'react';
|
|
36
|
+
import { CrudTable, type ContentProps, type ColumnType, type delHandle, type editHandle, type addHandle } from '@magicbe/antd-crud';
|
|
37
|
+
|
|
38
|
+
interface User {
|
|
39
|
+
id: number;
|
|
40
|
+
name: string;
|
|
41
|
+
age: number;
|
|
42
|
+
address: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const columns: ColumnType<User>['columns'] = [
|
|
46
|
+
{
|
|
47
|
+
title: '姓名',
|
|
48
|
+
dataIndex: 'name',
|
|
49
|
+
filter: 'Input',
|
|
50
|
+
field: {
|
|
51
|
+
type: 'Input',
|
|
52
|
+
rules: [{ required: true }],
|
|
53
|
+
...({})
|
|
54
|
+
},
|
|
55
|
+
add: true,
|
|
56
|
+
edit: true,
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
title: '年龄',
|
|
60
|
+
dataIndex: 'age',
|
|
61
|
+
field: 'InputNumber',
|
|
62
|
+
add: true,
|
|
63
|
+
edit: true,
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
title: '地址',
|
|
67
|
+
dataIndex: 'address',
|
|
68
|
+
field: 'TextArea',
|
|
69
|
+
add: true,
|
|
70
|
+
edit: true,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
title: "所属区域",
|
|
74
|
+
dataIndex: "region",
|
|
75
|
+
field: {
|
|
76
|
+
type: "Select",
|
|
77
|
+
option: {
|
|
78
|
+
options: [
|
|
79
|
+
{
|
|
80
|
+
label: "区域1",
|
|
81
|
+
value: "1",
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
label: "区域2",
|
|
85
|
+
value: "2",
|
|
86
|
+
},
|
|
87
|
+
]
|
|
88
|
+
},
|
|
89
|
+
rules: [{ required: true }]
|
|
90
|
+
},
|
|
91
|
+
edit: true,
|
|
92
|
+
},
|
|
93
|
+
];
|
|
94
|
+
|
|
95
|
+
const App: React.FC = () => {
|
|
96
|
+
const getSources: ContentProps<User>['getSources'] = async (params: any = {}) => {
|
|
97
|
+
const {
|
|
98
|
+
current: page = 1,
|
|
99
|
+
pageSize: size = 10,
|
|
100
|
+
} = params;
|
|
101
|
+
|
|
102
|
+
// 模拟API请求
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
sources: [
|
|
106
|
+
{ id: 1, name: '张三', age: 28, address: '北京市海淀区' },
|
|
107
|
+
{ id: 2, name: '李四', age: 32, address: '上海市浦东新区' },
|
|
108
|
+
],
|
|
109
|
+
total: 2,
|
|
110
|
+
page,
|
|
111
|
+
size,
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const add: addHandle = async (value) => {
|
|
116
|
+
// 模拟新增操作
|
|
117
|
+
console.log('add:', value);
|
|
118
|
+
return Promise.resolve();
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const edit: editHandle = async (value) => {
|
|
122
|
+
// 模拟编辑操作
|
|
123
|
+
console.log('edit:', value);
|
|
124
|
+
return Promise.resolve();
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const del: delHandle = async (value) => {
|
|
128
|
+
// 模拟删除操作
|
|
129
|
+
console.log('delete:', value);
|
|
130
|
+
return Promise.resolve();
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<CrudTable
|
|
135
|
+
columns={columns}
|
|
136
|
+
getSources={getSources}
|
|
137
|
+
add={add}
|
|
138
|
+
edit={edit}
|
|
139
|
+
del={del}
|
|
140
|
+
rowKey={"uuid"}
|
|
141
|
+
/>
|
|
142
|
+
);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
export default App;
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## API 文档
|
|
149
|
+
|
|
150
|
+
### CrudTable
|
|
151
|
+
|
|
152
|
+
主要组件,集成了筛选、操作按钮和表格功能。
|
|
153
|
+
|
|
154
|
+
#### 属性
|
|
155
|
+
|
|
156
|
+
| 属性名 | 类型 | 说明 |
|
|
157
|
+
|--------|------|------|
|
|
158
|
+
| columns | ColumnType[] | 表格列配置 |
|
|
159
|
+
| getSources | (params?: GetSourceFunctionParams) => Promise<Source> | 获取数据的方法 |
|
|
160
|
+
| add | addHandle \| addHandleMap | 新增操作方法 |
|
|
161
|
+
| edit | editHandle \| editHandleMap | 编辑操作方法 |
|
|
162
|
+
| del | delHandle \| Partial<HandleMap<delHandle>> | 删除操作方法 |
|
|
163
|
+
| action | Action | 自定义操作按钮 |
|
|
164
|
+
| rowSelection | RowSelectionType | 行选择类型 |
|
|
165
|
+
| pagination | false | 是否显示分页(暂仅支持false) |
|
|
166
|
+
| drawer | number \| DrawerProps | 抽屉配置 |
|
|
167
|
+
| pageSizeOptions | PaginationProps['pageSizeOptions'] | 每页条数选项 |
|
|
168
|
+
| actionColumn | ColumnType<any> | 操作列配置 |
|
|
169
|
+
|
|
170
|
+
### ColumnType
|
|
171
|
+
|
|
172
|
+
表格列配置,继承自 Ant Design 的 ColumnType,增加了以下属性:
|
|
173
|
+
|
|
174
|
+
| 属性名 | 类型 | 说明 |
|
|
175
|
+
|--------|------|------|
|
|
176
|
+
| field | ColumnFieldKeys \| ColumnField \| React.FC | 表单字段类型 |
|
|
177
|
+
| filter | boolean \| ColumnFieldKeys \| ColumnField \| React.FC | 筛选字段类型 |
|
|
178
|
+
| add | boolean \| ColumnFieldKeys \| ColumnField \| React.FC | 新增表单字段类型 |
|
|
179
|
+
| edit | boolean \| ColumnFieldKeys \| ColumnField \| React.FC | 编辑表单字段类型 |
|
|
180
|
+
|
|
181
|
+
### ColumnField 类型
|
|
182
|
+
|
|
183
|
+
支持的表单字段类型:
|
|
184
|
+
- Input
|
|
185
|
+
- Input.Password
|
|
186
|
+
- TextArea
|
|
187
|
+
- InputNumber
|
|
188
|
+
- Select
|
|
189
|
+
- Cascader
|
|
190
|
+
- TreeSelect
|
|
191
|
+
- Checkbox
|
|
192
|
+
- Checkbox.Group
|
|
193
|
+
- DatePicker
|
|
194
|
+
- DatePicker.YearPicker
|
|
195
|
+
- DatePicker.MonthPicker
|
|
196
|
+
- DatePicker.WeekPicker
|
|
197
|
+
- DatePicker.TimePicker
|
|
198
|
+
- DatePicker.RangePicker
|
|
199
|
+
- DatePicker.QuarterPicker
|
|
200
|
+
- TimePicker
|
|
201
|
+
- TimePicker.RangePicker
|
|
202
|
+
- Radio
|
|
203
|
+
- Radio.Group
|
|
204
|
+
- Switch
|
|
205
|
+
|
|
206
|
+
### TableContextProvider 和 useTableContext
|
|
207
|
+
|
|
208
|
+
提供表格上下文,可用于自定义组件中获取表格状态和方法。
|
|
209
|
+
|
|
210
|
+
### Filter
|
|
211
|
+
|
|
212
|
+
筛选组件,可单独使用。
|
|
213
|
+
|
|
214
|
+
### Action
|
|
215
|
+
|
|
216
|
+
操作按钮组件,提供了新增、编辑、删除等默认操作。
|
|
217
|
+
|
|
218
|
+
### Table
|
|
219
|
+
|
|
220
|
+
表格组件,继承自 Ant Design 的 Table。
|
|
221
|
+
|
|
222
|
+
### CrudConfigProvider
|
|
223
|
+
|
|
224
|
+
配置提供者,继承自 Ant Design 的 ConfigProvider。
|
|
225
|
+
|
|
226
|
+
## 高级用法
|
|
227
|
+
|
|
228
|
+
### 自定义操作按钮
|
|
229
|
+
|
|
230
|
+
```tsx
|
|
231
|
+
<CrudTable
|
|
232
|
+
columns={columns}
|
|
233
|
+
getSources={getSources}
|
|
234
|
+
action={{
|
|
235
|
+
master: {
|
|
236
|
+
add: true,
|
|
237
|
+
del: true,
|
|
238
|
+
// 自定义主操作按钮
|
|
239
|
+
},
|
|
240
|
+
record: {
|
|
241
|
+
edit: true,
|
|
242
|
+
del: true,
|
|
243
|
+
// 自定义行操作按钮
|
|
244
|
+
},
|
|
245
|
+
}}
|
|
246
|
+
/>
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### 使用 Context
|
|
250
|
+
|
|
251
|
+
```tsx
|
|
252
|
+
import { TableContextProvider, useTableContext } from '@magicbe/antd-crud';
|
|
253
|
+
|
|
254
|
+
const CustomComponent: React.FC = () => {
|
|
255
|
+
const { table_ref } = useTableContext();
|
|
256
|
+
|
|
257
|
+
const handleRefresh = () => {
|
|
258
|
+
table_ref.current?.loadRecords();
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
return (
|
|
262
|
+
<button onClick={handleRefresh}>刷新数据</button>
|
|
263
|
+
);
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
const App: React.FC = () => {
|
|
267
|
+
return (
|
|
268
|
+
<TableContextProvider {...props}>
|
|
269
|
+
<CustomComponent />
|
|
270
|
+
</TableContextProvider>
|
|
271
|
+
);
|
|
272
|
+
};
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### 配置主题
|
|
276
|
+
|
|
277
|
+
```tsx
|
|
278
|
+
import { CrudConfigProvider } from '@magicbe/antd-crud';
|
|
279
|
+
|
|
280
|
+
const App: React.FC = () => {
|
|
281
|
+
return (
|
|
282
|
+
<CrudConfigProvider theme={{
|
|
283
|
+
token: {
|
|
284
|
+
colorPrimary: '#1890ff',
|
|
285
|
+
},
|
|
286
|
+
}}>
|
|
287
|
+
<CrudTable {...props} />
|
|
288
|
+
</CrudConfigProvider>
|
|
289
|
+
);
|
|
290
|
+
};
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
## 注意事项
|
|
294
|
+
|
|
295
|
+
1. 组件依赖 antd 5.22.5 及以上版本,请确保项目中 antd 版本符合要求。
|
|
296
|
+
2. 目前 pagination 仅支持设置为 false,分页功能内置实现。
|
|
297
|
+
3. 自定义组件时,请使用 TableContextProvider 包裹以确保能正确获取上下文。
|
|
298
|
+
|
|
299
|
+
## License
|
|
300
|
+
|
|
301
|
+
MIT
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React, { PropsWithChildren } from "react";
|
|
2
|
-
|
|
3
|
-
declare const _default: React.ForwardRefExoticComponent<ActionProps & React.RefAttributes<ActionRef>>;
|
|
2
|
+
declare const _default: () => import("react/jsx-runtime").JSX.Element;
|
|
4
3
|
export default _default;
|
|
5
4
|
/**自定义渲染 */
|
|
6
5
|
export declare const CustormRender: React.FC<PropsWithChildren>;
|
|
@@ -47,10 +47,11 @@ import createEmotion from "@emotion/css/create-instance";
|
|
|
47
47
|
import { useTableContext } from "./Context";
|
|
48
48
|
import AddForm from "./Add";
|
|
49
49
|
import EditForm from "./Edit";
|
|
50
|
+
import { useCrudConfigContext } from "../config";
|
|
50
51
|
var _a = createEmotion({ key: "action" }), css = _a.css, cx = _a.cx;
|
|
51
52
|
var wrapper_css = css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n margin-bottom: 25px;\n"], ["\n margin-bottom: 25px;\n"])));
|
|
52
53
|
/**操作 */
|
|
53
|
-
var Action = function (_a, ref) {
|
|
54
|
+
var Action = React.forwardRef(function (_a, ref) {
|
|
54
55
|
var className = _a.className;
|
|
55
56
|
var action = useTableContext().action;
|
|
56
57
|
useImperativeHandle(ref, function () { return ({}); });
|
|
@@ -124,8 +125,11 @@ var Action = function (_a, ref) {
|
|
|
124
125
|
}
|
|
125
126
|
/**默认渲染 */
|
|
126
127
|
return (_jsxs(Space, { className: cx(wrapper_css, className), children: [_jsx(AppendAction, {}), _jsx(EditAction, {}), _jsx(DeleteAction, {})] }));
|
|
127
|
-
};
|
|
128
|
-
export default
|
|
128
|
+
});
|
|
129
|
+
export default (function () {
|
|
130
|
+
var action_ref = useTableContext().action_ref;
|
|
131
|
+
return _jsx(Action, { ref: action_ref });
|
|
132
|
+
});
|
|
129
133
|
/**自定义渲染 */
|
|
130
134
|
export var CustormRender = function (_a) {
|
|
131
135
|
var children = _a.children;
|
|
@@ -139,7 +143,8 @@ var append_action_default_children = (_jsxs(Button, { type: "primary", children:
|
|
|
139
143
|
export var AppendAction = function (_a) {
|
|
140
144
|
var _b = _a.children, children = _b === void 0 ? append_action_default_children : _b;
|
|
141
145
|
var _c = Modal.useModal(), modalInstance = _c[0], modalContextHolder = _c[1];
|
|
142
|
-
var
|
|
146
|
+
var showErrorModal = useCrudConfigContext().showErrorModal;
|
|
147
|
+
var _d = useTableContext(), table_ref = _d.table_ref, filter_ref = _d.filter_ref, form_ref = _d.form_ref, add = _d.add, drawer = _d.drawer;
|
|
143
148
|
/**添加表单抽屉 */
|
|
144
149
|
var _e = useState(false), add_drawer_open = _e[0], setAdd_drawer_open = _e[1];
|
|
145
150
|
var _f = useState(), init_data = _f[0], setInit_data = _f[1];
|
|
@@ -215,7 +220,7 @@ export var AppendAction = function (_a) {
|
|
|
215
220
|
case 10:
|
|
216
221
|
error_1 = _f.sent();
|
|
217
222
|
console.error(error_1);
|
|
218
|
-
modalInstance.error({
|
|
223
|
+
showErrorModal && modalInstance.error({
|
|
219
224
|
title: "错误",
|
|
220
225
|
content: String(error_1)
|
|
221
226
|
});
|
|
@@ -347,7 +352,8 @@ var edit_action_default_children = (_jsxs(Button, { children: [_jsx(EditFilled,
|
|
|
347
352
|
export var EditAction = function (_a) {
|
|
348
353
|
var _b = _a.children, children = _b === void 0 ? edit_action_default_children : _b;
|
|
349
354
|
var _c = Modal.useModal(), modalInstance = _c[0], modalContextHolder = _c[1];
|
|
350
|
-
var
|
|
355
|
+
var showErrorModal = useCrudConfigContext().showErrorModal;
|
|
356
|
+
var _d = useTableContext(), table_ref = _d.table_ref, filter_ref = _d.filter_ref, form_ref = _d.form_ref, edit = _d.edit, drawer = _d.drawer;
|
|
351
357
|
/**编辑 */
|
|
352
358
|
var _e = useState(false), edit_drawer_open = _e[0], setEdit_drawer_open = _e[1];
|
|
353
359
|
var _f = useState(false), loading = _f[0], setLoading = _f[1];
|
|
@@ -425,7 +431,7 @@ export var EditAction = function (_a) {
|
|
|
425
431
|
case 10:
|
|
426
432
|
error_4 = _f.sent();
|
|
427
433
|
console.error(error_4);
|
|
428
|
-
modalInstance.error({
|
|
434
|
+
showErrorModal && modalInstance.error({
|
|
429
435
|
title: "错误",
|
|
430
436
|
content: String(error_4)
|
|
431
437
|
});
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { FilterProps, FilterRef } from "../interface";
|
|
3
|
-
declare const _default: React.ForwardRefExoticComponent<FilterProps & React.RefAttributes<FilterRef>>;
|
|
1
|
+
declare const _default: () => import("react/jsx-runtime").JSX.Element;
|
|
4
2
|
export default _default;
|
|
@@ -33,9 +33,9 @@ import { Button, Form, Space } from "antd";
|
|
|
33
33
|
import createEmotion from "@emotion/css/create-instance";
|
|
34
34
|
import { SearchOutlined, UndoOutlined } from "@ant-design/icons";
|
|
35
35
|
import { get, isObject, isString } from "lodash";
|
|
36
|
-
var
|
|
36
|
+
var css = createEmotion({ key: "filter" }).css;
|
|
37
37
|
var wrapper_css = css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n margin-bottom: 25px;\n"], ["\n margin-bottom: 25px;\n"])));
|
|
38
|
-
var Filter = function (_a, ref) {
|
|
38
|
+
var Filter = React.forwardRef(function (_a, ref) {
|
|
39
39
|
var form = Form.useForm()[0];
|
|
40
40
|
var _b = useTableContext(), columns = _b.columns, table_ref = _b.table_ref;
|
|
41
41
|
var filters = columns === null || columns === void 0 ? void 0 : columns.filter(function (_a) {
|
|
@@ -72,6 +72,9 @@ var Filter = function (_a, ref) {
|
|
|
72
72
|
if (!(filters === null || filters === void 0 ? void 0 : filters.length))
|
|
73
73
|
return _jsx(Fragment, {});
|
|
74
74
|
return (_jsxs(Form, { layout: "inline", onFinish: onFinish, className: wrapper_css, form: form, initialValues: initialValues, children: [filters === null || filters === void 0 ? void 0 : filters.map(function (filter) { return _createElement(Field, __assign({}, filter, { key: String(filter.dataIndex) })); }), _jsxs(Space, { size: 14, children: [_jsxs(Button, { htmlType: "submit", type: "primary", children: [_jsx(SearchOutlined, {}), "\u67E5\u8BE2"] }), _jsxs(Button, { htmlType: "reset", children: [_jsx(UndoOutlined, {}), "\u91CD\u7F6E"] })] })] }));
|
|
75
|
-
};
|
|
76
|
-
export default
|
|
75
|
+
});
|
|
76
|
+
export default (function () {
|
|
77
|
+
var filter_ref = useTableContext().filter_ref;
|
|
78
|
+
return _jsx(Filter, { ref: filter_ref });
|
|
79
|
+
});
|
|
77
80
|
var templateObject_1;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { PropsWithChildren } from "react";
|
|
2
|
-
import {
|
|
3
|
-
declare const _default:
|
|
2
|
+
import { type AnyObject } from "../interface";
|
|
3
|
+
declare const _default: () => import("react/jsx-runtime").JSX.Element;
|
|
4
4
|
export default _default;
|
|
5
5
|
interface ActionProps {
|
|
6
6
|
row: AnyObject;
|
package/dist/components/Table.js
CHANGED
|
@@ -69,7 +69,8 @@ import { useTableContext } from "./Context";
|
|
|
69
69
|
import AddForm from "./Add";
|
|
70
70
|
import EditForm from "./Edit";
|
|
71
71
|
import { css } from "@emotion/css";
|
|
72
|
-
|
|
72
|
+
import { useCrudConfigContext } from "../config";
|
|
73
|
+
var Table = React.forwardRef(function (_a, ref) {
|
|
73
74
|
var _b = useTableContext(), getSources = _b.getSources, selectionType = _b.rowSelection, action = _b.action, content_ref = _b.content_ref, filter_ref = _b.filter_ref, pageSizeOptions = _b.pageSizeOptions, _c = _b.actionColumn, actionColumn = _c === void 0 ? {} : _c, _pagination_ = _b.pagination, props = __rest(_b, ["getSources", "rowSelection", "action", "content_ref", "filter_ref", "pageSizeOptions", "actionColumn", "pagination"]);
|
|
74
75
|
var _d = useState([]), sources = _d[0], setSources = _d[1];
|
|
75
76
|
var _e = useState(), total = _e[0], setTotal = _e[1];
|
|
@@ -200,13 +201,17 @@ var Table = function (_a, ref) {
|
|
|
200
201
|
}); });
|
|
201
202
|
useEffect(loadRecords, []);
|
|
202
203
|
return (_jsx(AntdTable, __assign({}, props, { rowSelection: rowSelection, columns: columns, loading: loading, onChange: loadRecords, dataSource: sources, pagination: pagination })));
|
|
203
|
-
};
|
|
204
|
-
export default
|
|
204
|
+
});
|
|
205
|
+
export default (function () {
|
|
206
|
+
var table_ref = useTableContext().table_ref;
|
|
207
|
+
return _jsx(Table, { ref: table_ref });
|
|
208
|
+
});
|
|
205
209
|
var action_cls = css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n padding-top: 0;\n padding-bottom: 0;\n"], ["\n padding-top: 0;\n padding-bottom: 0;\n"])));
|
|
206
210
|
var append_action_default_children = (_jsxs(Button, { type: "link", size: "small", className: action_cls, children: [_jsx(PlusOutlined, {}), "\u65B0\u589E"] }));
|
|
207
211
|
export var AppendAction = function (_a) {
|
|
208
212
|
var _b = _a.children, children = _b === void 0 ? append_action_default_children : _b, row = _a.row;
|
|
209
|
-
var
|
|
213
|
+
var showErrorModal = useCrudConfigContext().showErrorModal;
|
|
214
|
+
var _c = useTableContext(), rowKey = _c.rowKey, table_ref = _c.table_ref, filter_ref = _c.filter_ref, form_ref = _c.form_ref, add = _c.add, drawer = _c.drawer;
|
|
210
215
|
var _d = Modal.useModal(), modalInstance = _d[0], modalContextHolder = _d[1];
|
|
211
216
|
var _e = useState(false), add_drawer_open = _e[0], setAdd_drawer_open = _e[1];
|
|
212
217
|
var _f = useState(false), loading = _f[0], setLoading = _f[1];
|
|
@@ -279,7 +284,7 @@ export var AppendAction = function (_a) {
|
|
|
279
284
|
case 9:
|
|
280
285
|
error_1 = _d.sent();
|
|
281
286
|
console.error(error_1);
|
|
282
|
-
modalInstance.error({
|
|
287
|
+
showErrorModal && modalInstance.error({
|
|
283
288
|
title: "错误",
|
|
284
289
|
content: String(error_1)
|
|
285
290
|
});
|
|
@@ -329,7 +334,8 @@ export var AppendAction = function (_a) {
|
|
|
329
334
|
var edit_action_default_children = (_jsxs(Button, { type: "link", size: "small", className: action_cls, children: [_jsx(EditFilled, {}), "\u7F16\u8F91"] }));
|
|
330
335
|
export var EditAction = function (_a) {
|
|
331
336
|
var _b = _a.children, children = _b === void 0 ? edit_action_default_children : _b, row = _a.row;
|
|
332
|
-
var
|
|
337
|
+
var showErrorModal = useCrudConfigContext().showErrorModal;
|
|
338
|
+
var _c = useTableContext(), edit = _c.edit, rowKey = _c.rowKey, table_ref = _c.table_ref, filter_ref = _c.filter_ref, form_ref = _c.form_ref, drawer = _c.drawer;
|
|
333
339
|
var _d = Modal.useModal(), modalInstance = _d[0], modalContextHolder = _d[1];
|
|
334
340
|
var _e = useState(false), edit_drawer_open = _e[0], setEdit_drawer_open = _e[1];
|
|
335
341
|
var _f = useState(), init_data = _f[0], setInit_data = _f[1];
|
|
@@ -418,7 +424,7 @@ export var EditAction = function (_a) {
|
|
|
418
424
|
case 10:
|
|
419
425
|
error_3 = _d.sent();
|
|
420
426
|
console.error(error_3);
|
|
421
|
-
modalInstance.error({
|
|
427
|
+
showErrorModal && modalInstance.error({
|
|
422
428
|
title: "错误",
|
|
423
429
|
content: String(error_3)
|
|
424
430
|
});
|
package/dist/components/index.js
CHANGED
|
@@ -16,10 +16,11 @@ import Action from "./Action";
|
|
|
16
16
|
import Table from "./Table";
|
|
17
17
|
import { TableContextProvider, useTableContext } from "./Context";
|
|
18
18
|
var Content = function () {
|
|
19
|
-
var
|
|
20
|
-
return (_jsxs("div", { ref: content_ref, children: [_jsx(Filter, {
|
|
19
|
+
var content_ref = useTableContext().content_ref;
|
|
20
|
+
return (_jsxs("div", { ref: content_ref, children: [_jsx(Filter, {}), _jsx(Action, {}), _jsx(Table, {})] }));
|
|
21
21
|
};
|
|
22
22
|
var ContentPrev = function (props, ref) {
|
|
23
|
-
|
|
23
|
+
var _a = props.children, children = _a === void 0 ? _jsx(Content, {}) : _a;
|
|
24
|
+
return (_jsx(TableContextProvider, __assign({}, props, { ref: ref, children: children })));
|
|
24
25
|
};
|
|
25
26
|
export default React.forwardRef(ContentPrev);
|
package/dist/config.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { ConfigProviderProps } from "antd";
|
|
2
|
-
import React, { PropsWithChildren } from "react";
|
|
3
|
-
|
|
2
|
+
import React, { FC, PropsWithChildren } from "react";
|
|
3
|
+
export interface CustomConfigProviderProps {
|
|
4
|
+
showErrorModal?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare const CrudConfigContextProvider: FC<PropsWithChildren<CustomConfigProviderProps>>;
|
|
7
|
+
export declare const useCrudConfigContext: () => CustomConfigProviderProps;
|
|
8
|
+
declare const CrudConfigProvider: React.FC<PropsWithChildren<ConfigProviderProps & CustomConfigProviderProps>>;
|
|
4
9
|
export default CrudConfigProvider;
|
package/dist/config.js
CHANGED
|
@@ -22,8 +22,15 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
22
22
|
};
|
|
23
23
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
24
|
import { ConfigProvider } from "antd";
|
|
25
|
+
import React from "react";
|
|
26
|
+
var CrudConfigContext = React.createContext({});
|
|
27
|
+
export var CrudConfigContextProvider = function (_a) {
|
|
28
|
+
var children = _a.children, _b = _a.showErrorModal, showErrorModal = _b === void 0 ? true : _b;
|
|
29
|
+
return (_jsx(CrudConfigContext.Provider, { value: { showErrorModal: showErrorModal }, children: children }));
|
|
30
|
+
};
|
|
31
|
+
export var useCrudConfigContext = function () { return React.useContext(CrudConfigContext); };
|
|
25
32
|
var CrudConfigProvider = function (_a) {
|
|
26
|
-
var children = _a.children, props = __rest(_a, ["children"]);
|
|
27
|
-
return (_jsx(ConfigProvider, __assign({}, props, { children: children })));
|
|
33
|
+
var children = _a.children, _b = _a.showErrorModal, showErrorModal = _b === void 0 ? true : _b, props = __rest(_a, ["children", "showErrorModal"]);
|
|
34
|
+
return (_jsx(CrudConfigContextProvider, { showErrorModal: showErrorModal, children: _jsx(ConfigProvider, __assign({}, props, { children: children })) }));
|
|
28
35
|
};
|
|
29
36
|
export default CrudConfigProvider;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ export { TableContextProvider, useTableContext, } from "./components/Context";
|
|
|
4
4
|
export { default as Filter, } from "./components/Filter";
|
|
5
5
|
export { default as Action, AppendAction as MastAppend, DeleteAction as MastDelete, EditAction as MastEdit, } from "./components/Action";
|
|
6
6
|
export { default as Table, AppendAction as RowAppend, DeleteAction as RowDelete, EditAction as RowEdit, } from "./components/Table";
|
|
7
|
-
export { default as CrudConfigProvider, } from "./config";
|
|
7
|
+
export { default as CrudConfigProvider, type CustomConfigProviderProps, CrudConfigContextProvider, useCrudConfigContext, } from "./config";
|
package/dist/index.js
CHANGED
|
@@ -3,4 +3,4 @@ export { TableContextProvider, useTableContext, } from "./components/Context";
|
|
|
3
3
|
export { default as Filter, } from "./components/Filter";
|
|
4
4
|
export { default as Action, AppendAction as MastAppend, DeleteAction as MastDelete, EditAction as MastEdit, } from "./components/Action";
|
|
5
5
|
export { default as Table, AppendAction as RowAppend, DeleteAction as RowDelete, EditAction as RowEdit, } from "./components/Table";
|
|
6
|
-
export { default as CrudConfigProvider, } from "./config";
|
|
6
|
+
export { default as CrudConfigProvider, CrudConfigContextProvider, useCrudConfigContext, } from "./config";
|