@magicbe/antd-crud 0.0.16 → 0.0.18

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.
@@ -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,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
- 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) {
181
183
  var total = _a.total, sources = _a.sources, page = _a.page, size = _a.size;
182
184
  setSources(sources);
183
185
  setTotal(total);
@@ -15,15 +15,12 @@ import Filter from "./Filter";
15
15
  import Action from "./Action";
16
16
  import Table from "./Table";
17
17
  import { TableContextProvider, useTableContext } from "./Context";
18
- import { ConfigProvider } from "antd";
19
- import Config from "../config";
20
18
  var Content = function () {
21
19
  var _a = useTableContext(), filter_ref = _a.filter_ref, action_ref = _a.action_ref, table_ref = _a.table_ref, content_ref = _a.content_ref;
22
20
  return (_jsxs("div", __assign({ ref: content_ref }, { children: [_jsx(Filter, { ref: filter_ref }), _jsx(Action, { ref: action_ref }), _jsx(Table, { ref: table_ref })] })));
23
21
  };
24
22
  var ContentPrev = function (props, ref) {
25
23
  useImperativeHandle(ref, function () { return ({}); });
26
- var _a = Config.getConfig(), theme = _a.theme, locale = _a.locale;
27
- return (_jsx(ConfigProvider, __assign({}, { theme: theme, locale: locale }, { children: _jsx(TableContextProvider, __assign({}, props, { children: _jsx(Content, {}) })) })));
24
+ return (_jsx(TableContextProvider, __assign({}, props, { children: _jsx(Content, {}) })));
28
25
  };
29
26
  export default React.forwardRef(ContentPrev);
package/dist/config.d.ts CHANGED
@@ -1,16 +1,4 @@
1
- import { ThemeConfig } from "antd";
2
- import { Locale } from "antd/es/locale";
3
- export interface DefinConfigOptions {
4
- locale?: Locale;
5
- theme?: ThemeConfig;
6
- }
7
- declare class Config {
8
- private static locale?;
9
- private static theme?;
10
- static definConfig({ locale, theme }?: DefinConfigOptions): void;
11
- static getConfig(): {
12
- locale: Locale;
13
- theme: ThemeConfig;
14
- };
15
- }
16
- export default Config;
1
+ import { ConfigProviderProps } from "antd";
2
+ import React, { PropsWithChildren } from "react";
3
+ declare const CrudConfigProvider: React.FC<PropsWithChildren & ConfigProviderProps>;
4
+ export default CrudConfigProvider;
package/dist/config.js CHANGED
@@ -1,17 +1,29 @@
1
- var Config = /** @class */ (function () {
2
- function Config() {
3
- }
4
- Config.definConfig = function (_a) {
5
- var _b = _a === void 0 ? {} : _a, locale = _b.locale, theme = _b.theme;
6
- Config.locale = locale;
7
- Config.theme = theme;
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
8
9
  };
9
- Config.getConfig = function () {
10
- return ({
11
- locale: Config.locale,
12
- theme: Config.theme,
13
- });
14
- };
15
- return Config;
16
- }());
17
- export default Config;
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ import { jsx as _jsx } from "react/jsx-runtime";
24
+ import { ConfigProvider } from "antd";
25
+ var CrudConfigProvider = function (_a) {
26
+ var children = _a.children, props = __rest(_a, ["children"]);
27
+ return (_jsx(ConfigProvider, __assign({}, props, { children: children })));
28
+ };
29
+ export default CrudConfigProvider;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
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";
5
5
  export { default as Action, AppendAction as MastAppend, DeleteAction as MastDelete, EditAction as MastEdit, type ActionProps, type ActionRef, } from "./components/Action";
6
6
  export { default as Table, AppendAction as RowAppend, DeleteAction as RowDelete, EditAction as RowEdit, type TableProps, type TableRef, } from "./components/Table";
7
- export { default as Config, type DefinConfigOptions, } from "./config";
7
+ export { default as CrudConfigProvider, } 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 Config, } from "./config";
6
+ export { default as CrudConfigProvider, } from "./config";
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magicbe/antd-crud",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "description": "antd crud table",
5
5
  "author": "wang quan",
6
6
  "private": false,