@magicbe/antd-crud 0.0.14 → 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.
@@ -71,7 +71,7 @@ var Action = function (_a, ref) {
71
71
  /**自定义渲染 */
72
72
  if (isFunction(action)) {
73
73
  var Component = action;
74
- return (_jsx(Space, __assign({ className: cx(wrapper_css, className) }, { children: _jsx(CustormRender, { children: _jsx(Component, {}) }) })));
74
+ return (_jsx(CustormRender, { children: _jsx(Component, {}) }));
75
75
  }
76
76
  /**自定义渲染数组 */
77
77
  if (isArray(action)) {
@@ -90,7 +90,7 @@ var Action = function (_a, ref) {
90
90
  /**自定义渲染 */
91
91
  if (isFunction(master)) {
92
92
  var Component = master;
93
- return (_jsx(Space, __assign({ className: cx(wrapper_css, className) }, { children: _jsx(CustormRender, { children: _jsx(Component, {}) }) })));
93
+ return (_jsx(CustormRender, { children: _jsx(Component, {}) }));
94
94
  }
95
95
  /**自定义渲染数组 */
96
96
  if (isArray(master)) {
@@ -107,7 +107,7 @@ var Action = function (_a, ref) {
107
107
  {
108
108
  if (isFunction(add)) {
109
109
  var Component = add;
110
- add_element = _jsx(CustormRender, { children: _jsx(Component, {}) });
110
+ add_element = (_jsx(CustormRender, { children: _jsx(Component, {}) }));
111
111
  }
112
112
  if (add === true)
113
113
  add_element = _jsx(AppendAction, {});
@@ -116,7 +116,7 @@ var Action = function (_a, ref) {
116
116
  {
117
117
  if (isFunction(del)) {
118
118
  var Component = del;
119
- del_element = _jsx(CustormRender, { children: _jsx(Component, {}) });
119
+ del_element = (_jsx(CustormRender, { children: _jsx(Component, {}) }));
120
120
  }
121
121
  if (del === true)
122
122
  del_element = _jsx(DeleteAction, {});
@@ -125,7 +125,7 @@ var Action = function (_a, ref) {
125
125
  {
126
126
  if (isFunction(edit)) {
127
127
  var Component = edit;
128
- edit_element = _jsx(CustormRender, { children: _jsx(Component, {}) });
128
+ edit_element = (_jsx(CustormRender, { children: _jsx(Component, {}) }));
129
129
  }
130
130
  if (edit === true)
131
131
  edit_element = _jsx(EditAction, {});
@@ -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
- return (_jsxs(Form, __assign({ layout: "inline", onFinish: onFinish, className: wrapper_css, form: form }, { 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
+ 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;
@@ -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,8 +175,11 @@ var Table = function (_a, ref) {
175
175
  type: selectionType,
176
176
  } : undefined;
177
177
  var loadRecords = function (params) {
178
+ var _a;
179
+ if (params === void 0) { params = {}; }
178
180
  setLoading(true);
179
- getSources(params).then(function (_a) {
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) {
180
183
  var total = _a.total, sources = _a.sources, page = _a.page, size = _a.size;
181
184
  setSources(sources);
182
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 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";
@@ -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";
@@ -94,8 +94,12 @@ export type Source<RecordType = AnyObject> = {
94
94
  /**每页几条 */
95
95
  size: number;
96
96
  };
97
+ export interface GetSourceFunctionParams extends Record<string, any> {
98
+ current?: number;
99
+ pageSize?: number;
100
+ }
97
101
  /**获取数据的方法 */
98
- export type getSourceFunction = <RecordType = AnyObject>(params?: any) => Promise<Source<RecordType>>;
102
+ export type getSourceFunction = <RecordType = AnyObject>(params?: GetSourceFunctionParams) => Promise<Source<RecordType>>;
99
103
  export interface Selection<RecordType = AnyObject> {
100
104
  keys?: React.Key[];
101
105
  rows?: RecordType[];
@@ -122,6 +126,19 @@ export type editHandleMap = Partial<HandleMap<editHandle> & {
122
126
  }>;
123
127
  /**编辑方法 */
124
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;
125
142
  export interface CustomActionGroup {
126
143
  add?: boolean | React.FC;
127
144
  del?: boolean | React.FC;
@@ -144,6 +161,7 @@ export interface ContentProps<RecordType = AnyObject> extends Omit<TableProps<Re
144
161
  add?: add;
145
162
  del?: del;
146
163
  edit?: edit;
164
+ filter?: filter;
147
165
  action?: Action;
148
166
  rowSelection?: RowSelectionType;
149
167
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magicbe/antd-crud",
3
- "version": "0.0.14",
3
+ "version": "0.0.17",
4
4
  "description": "antd crud table",
5
5
  "author": "wang quan",
6
6
  "private": false,
@@ -58,4 +58,4 @@
58
58
  "pre-commit": "yarn lint"
59
59
  }
60
60
  }
61
- }
61
+ }