@magicbe/antd-crud 0.0.16 → 0.0.17
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/dist/components/Filter.js +18 -3
- package/dist/components/Table.js +4 -2
- package/dist/index.d.ts +1 -1
- package/dist/interface.d.ts +15 -1
- package/package.json +1 -1
|
@@ -32,12 +32,12 @@ import Field from "./Field";
|
|
|
32
32
|
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
|
-
import { isObject, isString } from "lodash";
|
|
35
|
+
import { isFunction, isObject, isString } from "lodash";
|
|
36
36
|
var _a = createEmotion({ key: "filter" }), css = _a.css, cx = _a.cx;
|
|
37
37
|
var wrapper_css = css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n margin-bottom: 25px;\n"], ["\n margin-bottom: 25px;\n"])));
|
|
38
38
|
var Filter = function (_a, ref) {
|
|
39
39
|
var form = Form.useForm()[0];
|
|
40
|
-
var _b = useTableContext(), columns = _b.columns, table_ref = _b.table_ref;
|
|
40
|
+
var _b = useTableContext(), columns = _b.columns, table_ref = _b.table_ref, filter = _b.filter;
|
|
41
41
|
var filters = columns === null || columns === void 0 ? void 0 : columns.filter(function (_a) {
|
|
42
42
|
var filter = _a.filter;
|
|
43
43
|
return filter;
|
|
@@ -64,9 +64,24 @@ var Filter = function (_a, ref) {
|
|
|
64
64
|
useImperativeHandle(ref, function () { return ({
|
|
65
65
|
form: form,
|
|
66
66
|
}); });
|
|
67
|
+
var initialValues;
|
|
67
68
|
if (!(filters === null || filters === void 0 ? void 0 : filters.length))
|
|
68
69
|
return _jsx(Fragment, {});
|
|
69
|
-
|
|
70
|
+
if (filter === false)
|
|
71
|
+
return _jsx(Fragment, {});
|
|
72
|
+
if (isFunction(filter)) {
|
|
73
|
+
var Component = filter;
|
|
74
|
+
return _jsx(Component, { onFinish: onFinish, filters: filters, form: form });
|
|
75
|
+
}
|
|
76
|
+
if (isObject(filter)) {
|
|
77
|
+
var render = filter.render, _initialValues_ = filter.initialValues;
|
|
78
|
+
initialValues = _initialValues_;
|
|
79
|
+
if (!!render) {
|
|
80
|
+
var Component = render;
|
|
81
|
+
return _jsx(Component, { onFinish: onFinish, filters: filters, form: form, initialValues: _initialValues_ });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return (_jsxs(Form, __assign({ 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, { children: [_jsxs(Button, __assign({ htmlType: "submit", type: "primary" }, { children: [_jsx(SearchOutlined, {}), "\u67E5\u8BE2"] })), _jsxs(Button, __assign({ htmlType: "reset" }, { children: [_jsx(UndoOutlined, {}), "\u91CD\u7F6E"] }))] })] })));
|
|
70
85
|
};
|
|
71
86
|
export default React.forwardRef(Filter);
|
|
72
87
|
var templateObject_1;
|
package/dist/components/Table.js
CHANGED
|
@@ -65,7 +65,7 @@ import { useTableContext } from "./Context";
|
|
|
65
65
|
import AddForm from "./Add";
|
|
66
66
|
import EditForm from "./Edit";
|
|
67
67
|
var Table = function (_a, ref) {
|
|
68
|
-
var _b = useTableContext(), getSources = _b.getSources, selectionType = _b.rowSelection, action = _b.action, content_ref = _b.content_ref, props = __rest(_b, ["getSources", "rowSelection", "action", "content_ref"]);
|
|
68
|
+
var _b = useTableContext(), getSources = _b.getSources, selectionType = _b.rowSelection, action = _b.action, content_ref = _b.content_ref, filter_ref = _b.filter_ref, props = __rest(_b, ["getSources", "rowSelection", "action", "content_ref", "filter_ref"]);
|
|
69
69
|
var _c = useState([]), sources = _c[0], setSources = _c[1];
|
|
70
70
|
var _d = useState(), total = _d[0], setTotal = _d[1];
|
|
71
71
|
var _e = useState(), page = _e[0], setPage = _e[1];
|
|
@@ -175,9 +175,11 @@ var Table = function (_a, ref) {
|
|
|
175
175
|
type: selectionType,
|
|
176
176
|
} : undefined;
|
|
177
177
|
var loadRecords = function (params) {
|
|
178
|
+
var _a;
|
|
178
179
|
if (params === void 0) { params = {}; }
|
|
179
180
|
setLoading(true);
|
|
180
|
-
|
|
181
|
+
var filter_data = (_a = filter_ref === null || filter_ref === void 0 ? void 0 : filter_ref.current) === null || _a === void 0 ? void 0 : _a.form.getFieldsValue();
|
|
182
|
+
getSources(Object.assign({}, params, filter_data)).then(function (_a) {
|
|
181
183
|
var total = _a.total, sources = _a.sources, page = _a.page, size = _a.size;
|
|
182
184
|
setSources(sources);
|
|
183
185
|
setTotal(total);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { type AnyObject, type BaseColumnField, type ColumnInputField, type ColumnTextAreaField, type ColumnInputNumberField, type ColumnSelectField, type ColumnCascaderField, type ColumnCheckboxField, type ColumnCheckboxGroupField, type ColumnDatePickerField, type ColumnDatePickerYearPickerField, type ColumnDatePickerMonthPickerField, type ColumnDatePickerWeekPickerField, type ColumnDatePickerTimePickerField, type ColumnDatePickerRangePickerField, type ColumnDatePickerQuarterPickerField, type ColumnTimePickerField, type ColumnTimePickerRangePickerField, type ColumnRadioField, type ColumnRadioGroupField, type ColumnSwitchField, type ColumnField, type ColumnFieldKeys, type ColumnType, type Source, type getSourceFunction, type GetSourceFunctionParams, type add, type addHandleMap, type edit, type editHandleMap, type del, type MasterCustomActionGroup, type RecordCustomActionGroup, type CustomActionGroup, type CustomAction, type ContentProps, type ContentRef, } from "./interface";
|
|
1
|
+
export { type AnyObject, type BaseColumnField, type ColumnInputField, type ColumnTextAreaField, type ColumnInputNumberField, type ColumnSelectField, type ColumnCascaderField, type ColumnCheckboxField, type ColumnCheckboxGroupField, type ColumnDatePickerField, type ColumnDatePickerYearPickerField, type ColumnDatePickerMonthPickerField, type ColumnDatePickerWeekPickerField, type ColumnDatePickerTimePickerField, type ColumnDatePickerRangePickerField, type ColumnDatePickerQuarterPickerField, type ColumnTimePickerField, type ColumnTimePickerRangePickerField, type ColumnRadioField, type ColumnRadioGroupField, type ColumnSwitchField, type ColumnField, type ColumnFieldKeys, type ColumnType, type Source, type getSourceFunction, type GetSourceFunctionParams, type add, type addHandleMap, type edit, type editHandleMap, type del, type CustomFilter, type filter, type MasterCustomActionGroup, type RecordCustomActionGroup, type CustomActionGroup, type CustomAction, type ContentProps, type ContentRef, } from "./interface";
|
|
2
2
|
export { default as CrudTable, } from "./components";
|
|
3
3
|
export { TableContextProvider, useTableContext, } from "./components/Context";
|
|
4
4
|
export { default as Filter, type FilterProps, type FilterRef, } from "./components/Filter";
|
package/dist/interface.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type TableProps, type InputProps, type SelectProps, type CascaderProps, type DatePickerProps, type InputNumberProps, type CheckboxProps, type RadioProps, type SwitchProps, type TimePickerProps } from "antd";
|
|
2
2
|
import { type CheckboxGroupProps } from "antd/es/checkbox";
|
|
3
|
-
import { Rule } from "antd/es/form";
|
|
3
|
+
import { FormInstance, Rule } from "antd/es/form";
|
|
4
4
|
import { TextAreaProps } from "antd/es/input";
|
|
5
5
|
import { type RadioGroupProps } from "antd/es/radio";
|
|
6
6
|
import { RowSelectionType, type ColumnType as AntdColumnType } from "antd/es/table/interface";
|
|
@@ -126,6 +126,19 @@ export type editHandleMap = Partial<HandleMap<editHandle> & {
|
|
|
126
126
|
}>;
|
|
127
127
|
/**编辑方法 */
|
|
128
128
|
export type edit = editHandle | editHandleMap;
|
|
129
|
+
export interface CustomFilterProps {
|
|
130
|
+
onFinish: (values: any) => void;
|
|
131
|
+
filters: Omit<ColumnType<any>, "filter">[];
|
|
132
|
+
form: FormInstance<any>;
|
|
133
|
+
initialValues?: Record<string, any>;
|
|
134
|
+
}
|
|
135
|
+
export type CustomFilter = React.FC<CustomFilterProps>;
|
|
136
|
+
export type CustomFilterObject = {
|
|
137
|
+
render?: CustomFilter;
|
|
138
|
+
initialValues?: Record<string, any>;
|
|
139
|
+
};
|
|
140
|
+
/**自定义过滤 */
|
|
141
|
+
export type filter = false | CustomFilter | CustomFilterObject;
|
|
129
142
|
export interface CustomActionGroup {
|
|
130
143
|
add?: boolean | React.FC;
|
|
131
144
|
del?: boolean | React.FC;
|
|
@@ -148,6 +161,7 @@ export interface ContentProps<RecordType = AnyObject> extends Omit<TableProps<Re
|
|
|
148
161
|
add?: add;
|
|
149
162
|
del?: del;
|
|
150
163
|
edit?: edit;
|
|
164
|
+
filter?: filter;
|
|
151
165
|
action?: Action;
|
|
152
166
|
rowSelection?: RowSelectionType;
|
|
153
167
|
}
|