@hw-component/form 0.0.4-beta-v5 → 0.0.4-beta-v7
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/es/Form/HFormConnect.js +4 -2
- package/es/Form/hooks/index.d.ts +7 -0
- package/es/Form/hooks/index.js +26 -3
- package/es/Form/hooks/useHForm.js +22 -4
- package/es/Form/hooks/useInitConfigData.d.ts +6 -2
- package/es/Form/hooks/useInitConfigData.js +59 -6
- package/es/Form/index.d.ts +1 -1
- package/es/Form/index.js +17 -7
- package/es/Form/modal.d.ts +8 -0
- package/es/Select/hooks/norHooks.d.ts +3 -3
- package/es/Select/hooks/norHooks.js +21 -9
- package/es/Select/index.js +5 -3
- package/es/Select/modal.d.ts +2 -0
- package/lib/Form/HFormConnect.js +4 -2
- package/lib/Form/hooks/index.d.ts +7 -0
- package/lib/Form/hooks/index.js +26 -2
- package/lib/Form/hooks/useHForm.js +22 -4
- package/lib/Form/hooks/useInitConfigData.d.ts +6 -2
- package/lib/Form/hooks/useInitConfigData.js +59 -6
- package/lib/Form/index.d.ts +1 -1
- package/lib/Form/index.js +16 -6
- package/lib/Form/modal.d.ts +8 -0
- package/lib/Select/hooks/norHooks.d.ts +3 -3
- package/lib/Select/hooks/norHooks.js +21 -9
- package/lib/Select/index.js +5 -3
- package/lib/Select/modal.d.ts +2 -0
- package/package.json +1 -1
- package/src/components/Form/HFormConnect.tsx +2 -2
- package/src/components/Form/hooks/index.ts +36 -0
- package/src/components/Form/hooks/useHForm.ts +17 -4
- package/src/components/Form/hooks/useInitConfigData.tsx +79 -2
- package/src/components/Form/index.tsx +17 -6
- package/src/components/Form/modal.ts +9 -2
- package/src/components/Select/hooks/norHooks.ts +9 -9
- package/src/components/Select/index.tsx +2 -0
- package/src/components/Select/modal.ts +2 -0
- package/src/pages/Form/index.tsx +8 -1
- package/src/pages/ModalForm/index.tsx +19 -11
|
@@ -6,7 +6,6 @@ var _Object$keys = require('@babel/runtime-corejs3/core-js/object/keys');
|
|
|
6
6
|
var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js/object/get-own-property-symbols');
|
|
7
7
|
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/filter');
|
|
8
8
|
var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js/object/get-own-property-descriptor');
|
|
9
|
-
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/for-each');
|
|
10
9
|
var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js/object/get-own-property-descriptors');
|
|
11
10
|
var _Object$defineProperties = require('@babel/runtime-corejs3/core-js/object/define-properties');
|
|
12
11
|
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js/object/define-property');
|
|
@@ -14,6 +13,8 @@ var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWit
|
|
|
14
13
|
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
15
14
|
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/map');
|
|
16
15
|
var _indexOfInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/index-of');
|
|
16
|
+
var _Array$isArray = require('@babel/runtime-corejs3/core-js/array/is-array');
|
|
17
|
+
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/for-each');
|
|
17
18
|
var React = require('react');
|
|
18
19
|
var config = require('../config.js');
|
|
19
20
|
var index = require('./index.js');
|
|
@@ -96,14 +97,66 @@ var itemControl = function itemControl(item, form, defaultComponents) {
|
|
|
96
97
|
render: render
|
|
97
98
|
});
|
|
98
99
|
};
|
|
99
|
-
var
|
|
100
|
-
var
|
|
101
|
-
|
|
100
|
+
var itemDispatchProvider = function itemDispatchProvider(name, config, dispatchSourceData) {
|
|
101
|
+
var dependencies = config.dependencies,
|
|
102
|
+
fnKey = config.fnKey;
|
|
103
|
+
var itemDispatch = dispatchSourceData[dependencies];
|
|
104
|
+
if (!itemDispatch) {
|
|
105
|
+
return _defineProperty({}, dependencies, _defineProperty({}, name, fnKey));
|
|
106
|
+
}
|
|
107
|
+
var itemNameDispatch = _defineProperty({}, name, fnKey);
|
|
108
|
+
return _defineProperty({}, dependencies, _objectSpread(_objectSpread({}, itemDispatch), itemNameDispatch));
|
|
109
|
+
};
|
|
110
|
+
var dispatchProvider = function dispatchProvider(item, dispatchSourceData) {
|
|
111
|
+
var _item$name = item.name,
|
|
112
|
+
name = _item$name === void 0 ? "" : _item$name,
|
|
113
|
+
_item$dispatch = item.dispatch,
|
|
114
|
+
dispatch = _item$dispatch === void 0 ? {} : _item$dispatch,
|
|
115
|
+
_item$dependencies = item.dependencies,
|
|
116
|
+
dependencies = _item$dependencies === void 0 ? "allDependencies" : _item$dependencies;
|
|
117
|
+
var fnKey = dispatch.fnKey,
|
|
118
|
+
_dispatch$dependencie = dispatch.dependencies,
|
|
119
|
+
dispatchDependencies = _dispatch$dependencie === void 0 ? dependencies : _dispatch$dependencie,
|
|
120
|
+
_dispatch$manual = dispatch.manual,
|
|
121
|
+
manual = _dispatch$manual === void 0 ? true : _dispatch$manual;
|
|
122
|
+
if (!fnKey) {
|
|
123
|
+
return {};
|
|
124
|
+
}
|
|
125
|
+
if (_Array$isArray(dispatchDependencies)) {
|
|
126
|
+
var allDispatch = _objectSpread({}, dispatchSourceData);
|
|
127
|
+
_forEachInstanceProperty(dispatchDependencies).call(dispatchDependencies, function (key) {
|
|
128
|
+
var itemDispatch = itemDispatchProvider(name, {
|
|
129
|
+
dependencies: key,
|
|
130
|
+
fnKey: fnKey,
|
|
131
|
+
manual: manual
|
|
132
|
+
}, dispatchSourceData);
|
|
133
|
+
allDispatch = _objectSpread(_objectSpread({}, allDispatch), itemDispatch);
|
|
134
|
+
});
|
|
135
|
+
return allDispatch;
|
|
136
|
+
}
|
|
137
|
+
var itemDispatch = itemDispatchProvider(name, {
|
|
138
|
+
dependencies: dispatchDependencies,
|
|
139
|
+
fnKey: fnKey,
|
|
140
|
+
manual: manual
|
|
141
|
+
}, dispatchSourceData);
|
|
142
|
+
return _objectSpread(_objectSpread({}, dispatchSourceData), itemDispatch);
|
|
143
|
+
};
|
|
144
|
+
var useInitConfigData = (function (_ref3) {
|
|
145
|
+
var configData = _ref3.configData,
|
|
146
|
+
form = _ref3.form;
|
|
102
147
|
var defaultComponents = index.useDefaultComponents();
|
|
103
148
|
return React.useMemo(function () {
|
|
104
|
-
|
|
105
|
-
|
|
149
|
+
var newConfigData = [];
|
|
150
|
+
var dispatchSourceData = {};
|
|
151
|
+
_forEachInstanceProperty(configData).call(configData, function (item) {
|
|
152
|
+
var itemDispatch = dispatchProvider(item, dispatchSourceData);
|
|
153
|
+
dispatchSourceData = _objectSpread(_objectSpread({}, dispatchSourceData), itemDispatch);
|
|
154
|
+
newConfigData.push(itemControl(item, form, defaultComponents));
|
|
106
155
|
});
|
|
156
|
+
return {
|
|
157
|
+
newConfigData: newConfigData,
|
|
158
|
+
dispatchSourceData: dispatchSourceData
|
|
159
|
+
};
|
|
107
160
|
}, [configData]);
|
|
108
161
|
});
|
|
109
162
|
|
package/lib/Form/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { HFormProps } from "./modal";
|
|
2
|
-
declare const _default: ({ configData, labelWidth, form, request, onFinish, infoRequest, valueType, initialValues, params, ...props }: HFormProps) => JSX.Element;
|
|
2
|
+
declare const _default: ({ configData, labelWidth, form, request, onFinish, infoRequest, valueType, initialValues, params, onValuesChange, ...props }: HFormProps) => JSX.Element;
|
|
3
3
|
export default _default;
|
package/lib/Form/index.js
CHANGED
|
@@ -23,7 +23,7 @@ var index$1 = require('../PageHandler/index.js');
|
|
|
23
23
|
var useInitConfigData = require('./hooks/useInitConfigData.js');
|
|
24
24
|
var InitSet = require('./InitSet.js');
|
|
25
25
|
|
|
26
|
-
var _excluded = ["configData", "labelWidth", "form", "request", "onFinish", "infoRequest", "valueType", "initialValues", "params"];
|
|
26
|
+
var _excluded = ["configData", "labelWidth", "form", "request", "onFinish", "infoRequest", "valueType", "initialValues", "params", "onValuesChange"];
|
|
27
27
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
28
28
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
29
29
|
var HForm = (function (_ref) {
|
|
@@ -38,12 +38,16 @@ var HForm = (function (_ref) {
|
|
|
38
38
|
initialValues = _ref.initialValues,
|
|
39
39
|
_ref$params = _ref.params,
|
|
40
40
|
params = _ref$params === void 0 ? {} : _ref$params,
|
|
41
|
+
onValuesChange = _ref.onValuesChange,
|
|
41
42
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
42
43
|
var hForm = index.useCurrentForm(form);
|
|
43
|
-
var
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
var _useInitConfigData = useInitConfigData.default({
|
|
45
|
+
configData: configData,
|
|
46
|
+
form: hForm
|
|
47
|
+
}),
|
|
48
|
+
newConfigData = _useInitConfigData.newConfigData,
|
|
49
|
+
dispatchSourceData = _useInitConfigData.dispatchSourceData;
|
|
50
|
+
console.log(dispatchSourceData, "dispatchSourceData");
|
|
47
51
|
var _useInfoReq = index.useInfoReq({
|
|
48
52
|
initialValues: initialValues,
|
|
49
53
|
request: request,
|
|
@@ -55,6 +59,11 @@ var HForm = (function (_ref) {
|
|
|
55
59
|
}),
|
|
56
60
|
subControl = _useInfoReq.subControl,
|
|
57
61
|
infoControl = _useInfoReq.infoControl;
|
|
62
|
+
var valuesChange = index.useValuesChange({
|
|
63
|
+
onValuesChange: onValuesChange,
|
|
64
|
+
dispatch: dispatchSourceData,
|
|
65
|
+
form: hForm
|
|
66
|
+
});
|
|
58
67
|
var run = subControl.run,
|
|
59
68
|
loading = subControl.loading;
|
|
60
69
|
var infoRun = infoControl.run,
|
|
@@ -79,7 +88,8 @@ var HForm = (function (_ref) {
|
|
|
79
88
|
},
|
|
80
89
|
children: jsxRuntime.jsxs(antd.Form, _objectSpread(_objectSpread({
|
|
81
90
|
form: hForm,
|
|
82
|
-
onFinish: run
|
|
91
|
+
onFinish: run,
|
|
92
|
+
onValuesChange: valuesChange
|
|
83
93
|
}, props), {}, {
|
|
84
94
|
children: [_mapInstanceProperty(newConfigData).call(newConfigData, function (itemData, index) {
|
|
85
95
|
var itemLabelWidth = itemData.labelWidth;
|
package/lib/Form/modal.d.ts
CHANGED
|
@@ -23,6 +23,12 @@ export interface HoverModal {
|
|
|
23
23
|
type HelperModal = (form: HFormInstance) => React.ReactNode | string;
|
|
24
24
|
export type HideModal = (form: HFormInstance) => boolean;
|
|
25
25
|
export type AddDispatchListenerFn = (action: ActionModal, fn: argsFn) => void;
|
|
26
|
+
export type DispatchSourceDataModal = Record<string, Record<string, string>>;
|
|
27
|
+
export interface DispatchModal<T = string | string[]> {
|
|
28
|
+
fnKey?: string;
|
|
29
|
+
dependencies?: T;
|
|
30
|
+
manual?: boolean;
|
|
31
|
+
}
|
|
26
32
|
export interface HItemProps extends Omit<FormItemProps, "name"> {
|
|
27
33
|
type?: string;
|
|
28
34
|
itemProps?: ItemPropsType;
|
|
@@ -33,6 +39,7 @@ export interface HItemProps extends Omit<FormItemProps, "name"> {
|
|
|
33
39
|
hide?: boolean | HideModal;
|
|
34
40
|
placeholder?: string | string[];
|
|
35
41
|
name?: string;
|
|
42
|
+
dispatch?: DispatchModal;
|
|
36
43
|
}
|
|
37
44
|
export interface HFormProps<T = any, R = any> extends Omit<FormProps, "form" | "onFinish"> {
|
|
38
45
|
configData: HItemProps[];
|
|
@@ -80,6 +87,7 @@ export interface IFormConfigContextProps {
|
|
|
80
87
|
interface ActionModal {
|
|
81
88
|
key: string;
|
|
82
89
|
name?: string;
|
|
90
|
+
dispatch?: DispatchModal;
|
|
83
91
|
}
|
|
84
92
|
export interface HFormInstance extends FormInstance {
|
|
85
93
|
addFormat: (name: string, formats?: FormatItemModal) => void;
|
|
@@ -3,14 +3,14 @@ interface ParamsModal {
|
|
|
3
3
|
options?: OptionType[];
|
|
4
4
|
params?: any;
|
|
5
5
|
}
|
|
6
|
-
export declare const useOptionReq: ({ manual, request, options, serviceSearch, showSearch, onSearch: propsOnSearch, }: PartialHSelectProps) => {
|
|
7
|
-
run: (
|
|
6
|
+
export declare const useOptionReq: ({ manual, request, options, serviceSearch, showSearch, onSearch: propsOnSearch, dispatch, }: PartialHSelectProps) => {
|
|
7
|
+
run: (requestParams?: any) => Promise<OptionType[] | undefined>;
|
|
8
8
|
loading: boolean;
|
|
9
9
|
error: Error | undefined;
|
|
10
10
|
data: OptionType[] | undefined;
|
|
11
11
|
onSearch: ((value: string) => void) | undefined;
|
|
12
12
|
mathShowSearch: boolean | undefined;
|
|
13
|
-
reload: ({ options: changeOpts, params
|
|
13
|
+
reload: ({ options: changeOpts, params }: ParamsModal) => void | Promise<OptionType[] | undefined>;
|
|
14
14
|
};
|
|
15
15
|
export declare const useFilterOption: ({ filterOption, serviceSearch, }: PartialHSelectProps) => boolean | import("rc-select/lib/Select").FilterFunc<import("rc-select/lib/Select").DefaultOptionType> | undefined;
|
|
16
16
|
export {};
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var _asyncToGenerator = require('@babel/runtime-corejs3/helpers/asyncToGenerator');
|
|
4
4
|
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
5
5
|
var _regeneratorRuntime = require('@babel/runtime-corejs3/regenerator');
|
|
6
|
+
var _valuesInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/values');
|
|
6
7
|
var _Promise = require('@babel/runtime-corejs3/core-js/promise');
|
|
7
8
|
var React = require('react');
|
|
8
9
|
var ahooks = require('ahooks');
|
|
@@ -14,7 +15,10 @@ var useOptionReq = function useOptionReq(_ref) {
|
|
|
14
15
|
options = _ref.options,
|
|
15
16
|
serviceSearch = _ref.serviceSearch,
|
|
16
17
|
showSearch = _ref.showSearch,
|
|
17
|
-
propsOnSearch = _ref.onSearch
|
|
18
|
+
propsOnSearch = _ref.onSearch,
|
|
19
|
+
_ref$dispatch = _ref.dispatch,
|
|
20
|
+
dispatch = _ref$dispatch === void 0 ? {} : _ref$dispatch;
|
|
21
|
+
var dispatchManual = dispatch.manual;
|
|
18
22
|
var _useFormContext = index.useFormContext(),
|
|
19
23
|
form = _useFormContext.form;
|
|
20
24
|
var _useState = React.useState(),
|
|
@@ -22,16 +26,20 @@ var useOptionReq = function useOptionReq(_ref) {
|
|
|
22
26
|
data = _useState2[0],
|
|
23
27
|
setData = _useState2[1];
|
|
24
28
|
var _useRequest = ahooks.useRequest( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
25
|
-
var
|
|
29
|
+
var requestParams,
|
|
30
|
+
_requestParams$params,
|
|
31
|
+
params,
|
|
32
|
+
values,
|
|
33
|
+
_requestParams$type,
|
|
26
34
|
type,
|
|
27
35
|
formData,
|
|
28
36
|
_args = arguments;
|
|
29
37
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
30
38
|
while (1) switch (_context.prev = _context.next) {
|
|
31
39
|
case 0:
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
formData = form === null || form === void 0 ? void 0 : form.getFieldsValue();
|
|
40
|
+
requestParams = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
|
|
41
|
+
_requestParams$params = requestParams.params, params = _requestParams$params === void 0 ? {} : _requestParams$params, values = _valuesInstanceProperty(requestParams), _requestParams$type = requestParams.type, type = _requestParams$type === void 0 ? "init" : _requestParams$type;
|
|
42
|
+
formData = values || (form === null || form === void 0 ? void 0 : form.getFieldsValue());
|
|
35
43
|
if (type === "init") {
|
|
36
44
|
setData(undefined);
|
|
37
45
|
}
|
|
@@ -48,7 +56,7 @@ var useOptionReq = function useOptionReq(_ref) {
|
|
|
48
56
|
}
|
|
49
57
|
}, _callee);
|
|
50
58
|
})), {
|
|
51
|
-
manual: manual,
|
|
59
|
+
manual: dispatchManual === false ? true : manual,
|
|
52
60
|
debounceInterval: 300,
|
|
53
61
|
onSuccess: function onSuccess(resultData) {
|
|
54
62
|
setData(resultData);
|
|
@@ -59,11 +67,13 @@ var useOptionReq = function useOptionReq(_ref) {
|
|
|
59
67
|
error = _useRequest.error;
|
|
60
68
|
var reload = function reload(_ref3) {
|
|
61
69
|
var changeOpts = _ref3.options,
|
|
62
|
-
|
|
70
|
+
params = _ref3.params;
|
|
63
71
|
if (changeOpts) {
|
|
64
72
|
return setData(changeOpts);
|
|
65
73
|
}
|
|
66
|
-
return run(
|
|
74
|
+
return run({
|
|
75
|
+
params: params
|
|
76
|
+
});
|
|
67
77
|
};
|
|
68
78
|
var onSearch = function onSearch(inputValue) {
|
|
69
79
|
if (!serviceSearch) {
|
|
@@ -71,7 +81,9 @@ var useOptionReq = function useOptionReq(_ref) {
|
|
|
71
81
|
return;
|
|
72
82
|
}
|
|
73
83
|
run({
|
|
74
|
-
|
|
84
|
+
params: {
|
|
85
|
+
inputValue: inputValue
|
|
86
|
+
}
|
|
75
87
|
});
|
|
76
88
|
};
|
|
77
89
|
React.useEffect(function () {
|
package/lib/Select/index.js
CHANGED
|
@@ -23,7 +23,7 @@ var AllSelect = require('./components/AllSelect.js');
|
|
|
23
23
|
var index = require('../hooks/index.js');
|
|
24
24
|
var HFormConnect = require('../Form/HFormConnect.js');
|
|
25
25
|
|
|
26
|
-
var _excluded = ["style", "mode", "options", "modeConfig", "value", "onChange", "fieldNames", "request", "manual", "optionLabelProp", "filterProvider", "optionFilterProp", "serviceSearch", "onSearch", "filterOption", "showSearch", "labelInValue", "noMatchItemRender", "allSelect", "addDispatchListener", "addFormat"];
|
|
26
|
+
var _excluded = ["style", "mode", "options", "modeConfig", "value", "onChange", "fieldNames", "request", "manual", "optionLabelProp", "filterProvider", "optionFilterProp", "serviceSearch", "onSearch", "filterOption", "showSearch", "labelInValue", "noMatchItemRender", "allSelect", "addDispatchListener", "addFormat", "dispatch"];
|
|
27
27
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
28
28
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
29
29
|
var Option = antd.Select.Option;
|
|
@@ -56,7 +56,8 @@ var Index = function Index(_ref) {
|
|
|
56
56
|
allSelect = _ref.allSelect,
|
|
57
57
|
addDispatchListener = _ref.addDispatchListener;
|
|
58
58
|
_ref.addFormat;
|
|
59
|
-
var
|
|
59
|
+
var dispatch = _ref.dispatch,
|
|
60
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
60
61
|
var _ref2 = (modeConfig === null || modeConfig === void 0 ? void 0 : modeConfig[mode || ""]) || {},
|
|
61
62
|
icon = _ref2.icon,
|
|
62
63
|
render = _ref2.render;
|
|
@@ -75,7 +76,8 @@ var Index = function Index(_ref) {
|
|
|
75
76
|
request: request,
|
|
76
77
|
serviceSearch: serviceSearch,
|
|
77
78
|
showSearch: showSearch,
|
|
78
|
-
onSearch: propsOnSearch
|
|
79
|
+
onSearch: propsOnSearch,
|
|
80
|
+
dispatch: dispatch
|
|
79
81
|
}),
|
|
80
82
|
run = _useOptionReq.run,
|
|
81
83
|
loading = _useOptionReq.loading,
|
package/lib/Select/modal.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type React from "react";
|
|
|
3
3
|
import type { PromiseFnResult } from "../modal";
|
|
4
4
|
import type { argsFn } from "@/components/Form/modal";
|
|
5
5
|
import type { addFormatItemModal } from "@/components/Form/modal";
|
|
6
|
+
import type { DispatchModal } from "@/components/Form/modal";
|
|
6
7
|
export type OptionType = Record<string, any>;
|
|
7
8
|
export type PartialHSelectProps = Partial<HSelectProps>;
|
|
8
9
|
export type RenderFn = (data: OptionType) => React.ReactNode;
|
|
@@ -27,6 +28,7 @@ export interface HSelectProps extends Omit<SelectProps, "options" | "placeholder
|
|
|
27
28
|
addDispatchListener?: (key: string, fn: argsFn) => void;
|
|
28
29
|
addFormat?: (format: Record<string, addFormatItemModal>) => void;
|
|
29
30
|
placeholder?: string;
|
|
31
|
+
dispatch?: DispatchModal;
|
|
30
32
|
}
|
|
31
33
|
export interface FilterDataModal {
|
|
32
34
|
value: any;
|
package/package.json
CHANGED
|
@@ -36,7 +36,7 @@ export default (
|
|
|
36
36
|
props: HFormItemProps,
|
|
37
37
|
ref
|
|
38
38
|
) => {
|
|
39
|
-
const { name = "" } = props;
|
|
39
|
+
const { name = "", dispatch } = props;
|
|
40
40
|
|
|
41
41
|
const { form, valueType = "float" } = useFormContext();
|
|
42
42
|
|
|
@@ -48,7 +48,7 @@ export default (
|
|
|
48
48
|
form?.addFormat(name, formatMaker(props, aFormat[valueType]));
|
|
49
49
|
};
|
|
50
50
|
const addDispatchListener = (key: string, fn: argsFn) => {
|
|
51
|
-
form?.addDispatchListener({ key, name }, fn);
|
|
51
|
+
form?.addDispatchListener({ key, name, dispatch }, fn);
|
|
52
52
|
};
|
|
53
53
|
const Component = component as React.ForwardRefRenderFunction<
|
|
54
54
|
any,
|
|
@@ -4,6 +4,14 @@ import useHForm from "./useHForm";
|
|
|
4
4
|
import { useEffect, useMemo } from "react";
|
|
5
5
|
import FormConfig from "../config";
|
|
6
6
|
import { useFormConfigContext } from "../Context/FormConfigProvider";
|
|
7
|
+
import type { DispatchModal } from "../modal";
|
|
8
|
+
|
|
9
|
+
interface UseValuesChangeModal {
|
|
10
|
+
onValuesChange: HFormProps["onValuesChange"];
|
|
11
|
+
dispatch: DispatchModal;
|
|
12
|
+
form: HFormInstance;
|
|
13
|
+
}
|
|
14
|
+
|
|
7
15
|
export const useCurrentForm = (form?: HFormInstance) => {
|
|
8
16
|
const selfForm = useHForm();
|
|
9
17
|
return form || selfForm;
|
|
@@ -66,3 +74,31 @@ export const useDefaultComponents = () => {
|
|
|
66
74
|
const defaultComponent = useFormConfigContext("defaultComponent");
|
|
67
75
|
return { ...FormConfig, ...defaultComponent };
|
|
68
76
|
};
|
|
77
|
+
|
|
78
|
+
export const useValuesChange = ({
|
|
79
|
+
onValuesChange,
|
|
80
|
+
dispatch,
|
|
81
|
+
form,
|
|
82
|
+
}: UseValuesChangeModal) => {
|
|
83
|
+
return (changedValues: any, values: any) => {
|
|
84
|
+
const changeKey = Object.keys(changedValues)[0];
|
|
85
|
+
const dispatchItem = dispatch[changeKey];
|
|
86
|
+
if (!!dispatchItem) {
|
|
87
|
+
const dispatchKey = Object.keys(dispatchItem);
|
|
88
|
+
dispatchKey.forEach((name) => {
|
|
89
|
+
const key = dispatchItem[name];
|
|
90
|
+
form.dispatch(
|
|
91
|
+
{
|
|
92
|
+
key,
|
|
93
|
+
name,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
changedValues,
|
|
97
|
+
oldValues: values,
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
onValuesChange?.(changedValues, values);
|
|
103
|
+
};
|
|
104
|
+
};
|
|
@@ -13,9 +13,13 @@ export default () => {
|
|
|
13
13
|
return useMemo<HFormInstance>(() => {
|
|
14
14
|
const formatSourceData: Record<string, FormatItemModal> = {};
|
|
15
15
|
let dispatchSourceData: Record<string, DispatchItemData> = {};
|
|
16
|
+
const initDispatch: Record<string, argsFn> = {};
|
|
16
17
|
let cacheValues: Record<string, any> = {};
|
|
17
18
|
let isLoading = false;
|
|
18
|
-
const norAddItemDispatch = (name, fn) => {
|
|
19
|
+
const norAddItemDispatch = (name, manual, fn) => {
|
|
20
|
+
if (manual === false&&name) {
|
|
21
|
+
initDispatch[name]=fn;
|
|
22
|
+
}
|
|
19
23
|
if (!name) {
|
|
20
24
|
return {
|
|
21
25
|
keysFn: {},
|
|
@@ -34,10 +38,15 @@ export default () => {
|
|
|
34
38
|
return Promise.resolve(params);
|
|
35
39
|
},
|
|
36
40
|
initValues() {
|
|
41
|
+
let newValue = {};
|
|
37
42
|
if (cacheValues) {
|
|
38
|
-
|
|
43
|
+
newValue = this.formatValues(cacheValues);
|
|
39
44
|
form.setFieldsValue(newValue);
|
|
40
45
|
}
|
|
46
|
+
const initKeys=Object.keys(initDispatch);
|
|
47
|
+
initKeys.forEach((key) => {
|
|
48
|
+
initDispatch[key]({ changedValues: newValue, oldValues: newValue });
|
|
49
|
+
});
|
|
41
50
|
isLoading = true;
|
|
42
51
|
},
|
|
43
52
|
addFormat(name: string, format?: FormatItemModal) {
|
|
@@ -89,10 +98,11 @@ export default () => {
|
|
|
89
98
|
});
|
|
90
99
|
},
|
|
91
100
|
addDispatchListener(action, fn) {
|
|
92
|
-
const { key, name } = action;
|
|
101
|
+
const { key, name, dispatch = {} } = action;
|
|
102
|
+
const { manual } = dispatch;
|
|
93
103
|
const items = dispatchSourceData[key];
|
|
94
104
|
if (!items) {
|
|
95
|
-
dispatchSourceData[key] = norAddItemDispatch(name, fn);
|
|
105
|
+
dispatchSourceData[key] = norAddItemDispatch(name, manual, fn);
|
|
96
106
|
return;
|
|
97
107
|
}
|
|
98
108
|
const { keysFn, defaultFn } = items;
|
|
@@ -101,6 +111,9 @@ export default () => {
|
|
|
101
111
|
} else {
|
|
102
112
|
defaultFn.push(fn);
|
|
103
113
|
}
|
|
114
|
+
if (manual===false&&name){
|
|
115
|
+
initDispatch[name]=fn;
|
|
116
|
+
}
|
|
104
117
|
dispatchSourceData[key] = {
|
|
105
118
|
keysFn,
|
|
106
119
|
defaultFn,
|
|
@@ -10,6 +10,8 @@ import type { Rule } from "rc-field-form/lib/interface";
|
|
|
10
10
|
import type { FormInstance } from "antd";
|
|
11
11
|
import { useDefaultComponents } from "../hooks";
|
|
12
12
|
import type { ConfigComponentModal } from "../modal";
|
|
13
|
+
import type { DispatchSourceDataModal } from "../modal";
|
|
14
|
+
import type { DispatchModal } from "../modal";
|
|
13
15
|
|
|
14
16
|
const mathRequired = (
|
|
15
17
|
configItem: HFormItemProps,
|
|
@@ -98,13 +100,88 @@ const itemControl = (
|
|
|
98
100
|
render,
|
|
99
101
|
};
|
|
100
102
|
};
|
|
103
|
+
const itemDispatchProvider = (
|
|
104
|
+
name: string,
|
|
105
|
+
config: Required<DispatchModal<string>>,
|
|
106
|
+
dispatchSourceData: DispatchSourceDataModal
|
|
107
|
+
) => {
|
|
108
|
+
const { dependencies, fnKey } = config;
|
|
109
|
+
const itemDispatch = dispatchSourceData[dependencies as string];
|
|
110
|
+
if (!itemDispatch) {
|
|
111
|
+
return {
|
|
112
|
+
[dependencies]: {
|
|
113
|
+
[name]: fnKey,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
const itemNameDispatch = {
|
|
118
|
+
[name]: fnKey,
|
|
119
|
+
};
|
|
120
|
+
return {
|
|
121
|
+
[dependencies]: {
|
|
122
|
+
...itemDispatch,
|
|
123
|
+
...itemNameDispatch,
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
const dispatchProvider = (
|
|
128
|
+
item: HItemProps,
|
|
129
|
+
dispatchSourceData: DispatchSourceDataModal
|
|
130
|
+
) => {
|
|
131
|
+
const { name = "", dispatch = {}, dependencies = "allDependencies" } = item;
|
|
132
|
+
const {
|
|
133
|
+
fnKey,
|
|
134
|
+
dependencies: dispatchDependencies = dependencies as string | string[],
|
|
135
|
+
manual = true,
|
|
136
|
+
} = dispatch;
|
|
137
|
+
if (!fnKey) {
|
|
138
|
+
return {};
|
|
139
|
+
}
|
|
140
|
+
if (Array.isArray(dispatchDependencies)) {
|
|
141
|
+
let allDispatch: DispatchSourceDataModal = {
|
|
142
|
+
...dispatchSourceData,
|
|
143
|
+
};
|
|
144
|
+
dispatchDependencies.forEach((key) => {
|
|
145
|
+
const itemDispatch = itemDispatchProvider(
|
|
146
|
+
name,
|
|
147
|
+
{ dependencies: key, fnKey, manual },
|
|
148
|
+
dispatchSourceData
|
|
149
|
+
);
|
|
150
|
+
allDispatch = {
|
|
151
|
+
...allDispatch,
|
|
152
|
+
...itemDispatch,
|
|
153
|
+
};
|
|
154
|
+
});
|
|
155
|
+
return allDispatch;
|
|
156
|
+
}
|
|
157
|
+
const itemDispatch = itemDispatchProvider(
|
|
158
|
+
name,
|
|
159
|
+
{ dependencies: dispatchDependencies, fnKey, manual },
|
|
160
|
+
dispatchSourceData
|
|
161
|
+
);
|
|
162
|
+
return {
|
|
163
|
+
...dispatchSourceData,
|
|
164
|
+
...itemDispatch,
|
|
165
|
+
};
|
|
166
|
+
};
|
|
101
167
|
type InitConfigModal = Required<Pick<HFormProps, "configData" | "form">>;
|
|
102
168
|
|
|
103
169
|
export default ({ configData, form }: InitConfigModal) => {
|
|
104
170
|
const defaultComponents = useDefaultComponents();
|
|
105
171
|
return useMemo(() => {
|
|
106
|
-
|
|
107
|
-
|
|
172
|
+
const newConfigData:HItemProps[] = [];
|
|
173
|
+
let dispatchSourceData: DispatchSourceDataModal = {};
|
|
174
|
+
configData.forEach((item) => {
|
|
175
|
+
const itemDispatch = dispatchProvider(item, dispatchSourceData);
|
|
176
|
+
dispatchSourceData = {
|
|
177
|
+
...dispatchSourceData,
|
|
178
|
+
...itemDispatch,
|
|
179
|
+
};
|
|
180
|
+
newConfigData.push(itemControl(item, form, defaultComponents));
|
|
108
181
|
});
|
|
182
|
+
return {
|
|
183
|
+
newConfigData,
|
|
184
|
+
dispatchSourceData,
|
|
185
|
+
};
|
|
109
186
|
}, [configData]);
|
|
110
187
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Form } from "antd";
|
|
2
|
-
import type { HFormProps } from "./modal";
|
|
2
|
+
import type { HFormProps, HItemProps } from "./modal";
|
|
3
3
|
import Item from "./FormItem";
|
|
4
|
-
import { useCurrentForm, useInfoReq } from "./hooks";
|
|
4
|
+
import { useCurrentForm, useInfoReq, useValuesChange } from "./hooks";
|
|
5
5
|
import { FormContext } from "./Context";
|
|
6
6
|
import PageHandler from "../PageHandler";
|
|
7
7
|
import useInitConfigData from "./hooks/useInitConfigData";
|
|
@@ -18,13 +18,15 @@ export default ({
|
|
|
18
18
|
valueType = "float",
|
|
19
19
|
initialValues,
|
|
20
20
|
params = {},
|
|
21
|
+
onValuesChange,
|
|
21
22
|
...props
|
|
22
23
|
}: HFormProps) => {
|
|
23
24
|
const hForm = useCurrentForm(form);
|
|
24
|
-
const newConfigData = useInitConfigData({
|
|
25
|
+
const { newConfigData, dispatchSourceData } = useInitConfigData({
|
|
25
26
|
configData,
|
|
26
27
|
form: hForm,
|
|
27
28
|
});
|
|
29
|
+
console.log(dispatchSourceData,"dispatchSourceData")
|
|
28
30
|
const { subControl, infoControl } = useInfoReq({
|
|
29
31
|
initialValues,
|
|
30
32
|
request,
|
|
@@ -34,7 +36,11 @@ export default ({
|
|
|
34
36
|
infoRequest,
|
|
35
37
|
params,
|
|
36
38
|
});
|
|
37
|
-
|
|
39
|
+
const valuesChange = useValuesChange({
|
|
40
|
+
onValuesChange,
|
|
41
|
+
dispatch: dispatchSourceData,
|
|
42
|
+
form: hForm,
|
|
43
|
+
});
|
|
38
44
|
const { run, loading } = subControl;
|
|
39
45
|
const {
|
|
40
46
|
run: infoRun,
|
|
@@ -56,8 +62,13 @@ export default ({
|
|
|
56
62
|
reload={infoRun}
|
|
57
63
|
>
|
|
58
64
|
<FormContext.Provider value={{ loading, form: hForm, valueType }}>
|
|
59
|
-
<Form
|
|
60
|
-
{
|
|
65
|
+
<Form
|
|
66
|
+
form={hForm}
|
|
67
|
+
onFinish={run}
|
|
68
|
+
onValuesChange={valuesChange}
|
|
69
|
+
{...props}
|
|
70
|
+
>
|
|
71
|
+
{newConfigData.map((itemData: HItemProps, index) => {
|
|
61
72
|
const { labelWidth: itemLabelWidth } = itemData;
|
|
62
73
|
return (
|
|
63
74
|
<Item
|
|
@@ -27,6 +27,7 @@ import type {
|
|
|
27
27
|
} from "../modal";
|
|
28
28
|
import type { ForwardedRef } from "react";
|
|
29
29
|
import type { DataFnProvider } from "../modal";
|
|
30
|
+
|
|
30
31
|
type RenderFun = (
|
|
31
32
|
props: HItemProps,
|
|
32
33
|
node: React.ReactNode,
|
|
@@ -56,7 +57,12 @@ type HelperModal = (form: HFormInstance) => React.ReactNode | string;
|
|
|
56
57
|
export type HideModal = (form: HFormInstance) => boolean;
|
|
57
58
|
|
|
58
59
|
export type AddDispatchListenerFn = (action: ActionModal, fn: argsFn) => void;
|
|
59
|
-
|
|
60
|
+
export type DispatchSourceDataModal = Record<string, Record<string, string>>;
|
|
61
|
+
export interface DispatchModal<T = string | string[]> {
|
|
62
|
+
fnKey?: string;
|
|
63
|
+
dependencies?: T;
|
|
64
|
+
manual?: boolean;
|
|
65
|
+
}
|
|
60
66
|
export interface HItemProps extends Omit<FormItemProps, "name"> {
|
|
61
67
|
type?: string;
|
|
62
68
|
itemProps?: ItemPropsType;
|
|
@@ -69,6 +75,7 @@ export interface HItemProps extends Omit<FormItemProps, "name"> {
|
|
|
69
75
|
placeholder?: string | string[];
|
|
70
76
|
// formatKeys?: string[];
|
|
71
77
|
name?: string;
|
|
78
|
+
dispatch?: DispatchModal;
|
|
72
79
|
}
|
|
73
80
|
|
|
74
81
|
export interface HFormProps<T = any, R = any>
|
|
@@ -82,7 +89,6 @@ export interface HFormProps<T = any, R = any>
|
|
|
82
89
|
params?: any;
|
|
83
90
|
onFinish?: (values: T, params?: any) => void;
|
|
84
91
|
}
|
|
85
|
-
|
|
86
92
|
export interface HFormItemProps extends HItemProps {
|
|
87
93
|
required?: boolean;
|
|
88
94
|
value?: any;
|
|
@@ -123,6 +129,7 @@ export interface IFormConfigContextProps {
|
|
|
123
129
|
interface ActionModal {
|
|
124
130
|
key: string;
|
|
125
131
|
name?: string;
|
|
132
|
+
dispatch?: DispatchModal;
|
|
126
133
|
}
|
|
127
134
|
export interface HFormInstance extends FormInstance {
|
|
128
135
|
addFormat: (name: string, formats?: FormatItemModal) => void;
|