@hw-component/form 0.0.3-beta-v1 → 0.0.3-beta-v2
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/DialogForm/DrawerForm/Footer.d.ts +6 -2
- package/es/DialogForm/DrawerForm/index.d.ts +1 -1
- package/es/DialogForm/DrawerForm/index.js +26 -13
- package/es/DialogForm/ModalForm.d.ts +1 -1
- package/es/DialogForm/ModalForm.js +24 -10
- package/es/DialogForm/hooks.d.ts +5 -4
- package/es/DialogForm/hooks.js +23 -10
- package/es/DialogForm/modal.d.ts +12 -6
- package/es/Form/hooks/index.d.ts +5 -3
- package/es/Form/hooks/index.js +65 -8
- package/es/Form/hooks/useHForm.js +4 -1
- package/es/Form/index.d.ts +1 -1
- package/es/Form/index.js +17 -42
- package/es/Form/modal.d.ts +6 -3
- package/lib/DialogForm/DrawerForm/Footer.d.ts +6 -2
- package/lib/DialogForm/DrawerForm/index.d.ts +1 -1
- package/lib/DialogForm/DrawerForm/index.js +26 -13
- package/lib/DialogForm/ModalForm.d.ts +1 -1
- package/lib/DialogForm/ModalForm.js +24 -10
- package/lib/DialogForm/hooks.d.ts +5 -4
- package/lib/DialogForm/hooks.js +23 -10
- package/lib/DialogForm/modal.d.ts +12 -6
- package/lib/Form/hooks/index.d.ts +5 -3
- package/lib/Form/hooks/index.js +65 -8
- package/lib/Form/hooks/useHForm.js +4 -1
- package/lib/Form/index.d.ts +1 -1
- package/lib/Form/index.js +16 -41
- package/lib/Form/modal.d.ts +6 -3
- package/package.json +1 -1
- package/src/components/DialogForm/DrawerForm/Footer.tsx +7 -2
- package/src/components/DialogForm/DrawerForm/index.tsx +13 -5
- package/src/components/DialogForm/ModalForm.tsx +14 -6
- package/src/components/DialogForm/hooks.ts +19 -6
- package/src/components/DialogForm/modal.ts +13 -6
- package/src/components/Form/FormItem/UpFormItem.tsx +1 -1
- package/src/components/Form/hooks/index.ts +46 -7
- package/src/components/Form/hooks/useHForm.ts +6 -3
- package/src/components/Form/index.tsx +10 -14
- package/src/components/Form/modal.ts +6 -3
- package/src/components/Input/ButtonInput.tsx +7 -1
- package/src/components/Input/modal.ts +1 -1
- package/src/components/Upload/index.tsx +3 -2
- package/src/pages/Form/index.tsx +2 -1
- package/src/pages/ModalForm/index.tsx +20 -8
|
@@ -13,7 +13,7 @@ var index = require('../../Form/index.js');
|
|
|
13
13
|
var Title = require('./Title.js');
|
|
14
14
|
var Footer = require('./Footer.js');
|
|
15
15
|
|
|
16
|
-
var _excluded = ["visible", "title", "onCancel", "configData", "infoRequest", "request", "afterClose", "dialogForm", "closable", "initialValues", "labelWidth", "onOk", "onFinish", "size", "form", "footer"];
|
|
16
|
+
var _excluded = ["visible", "title", "onCancel", "configData", "infoRequest", "request", "afterClose", "dialogForm", "closable", "initialValues", "labelWidth", "onOk", "onFinish", "size", "form", "footer", "params"];
|
|
17
17
|
var DrawerForm = (function (_ref) {
|
|
18
18
|
var visible = _ref.visible,
|
|
19
19
|
title = _ref.title,
|
|
@@ -27,29 +27,32 @@ var DrawerForm = (function (_ref) {
|
|
|
27
27
|
closable = _ref$closable === void 0 ? true : _ref$closable,
|
|
28
28
|
_ref$initialValues = _ref.initialValues,
|
|
29
29
|
initialValues = _ref$initialValues === void 0 ? {} : _ref$initialValues,
|
|
30
|
-
labelWidth = _ref.labelWidth
|
|
31
|
-
_ref.onOk
|
|
32
|
-
|
|
30
|
+
labelWidth = _ref.labelWidth,
|
|
31
|
+
onOk = _ref.onOk,
|
|
32
|
+
onFinish = _ref.onFinish;
|
|
33
33
|
_ref.size;
|
|
34
34
|
_ref.form;
|
|
35
35
|
var footer = _ref.footer,
|
|
36
|
+
params = _ref.params,
|
|
36
37
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
37
38
|
var currentForm = hooks.useCurrentForm(dialogForm);
|
|
38
39
|
var _useModifyProps = hooks.useModifyProps({
|
|
39
40
|
configData: configData,
|
|
40
41
|
visible: visible,
|
|
41
42
|
initialValues: initialValues,
|
|
42
|
-
dialogForm: currentForm
|
|
43
|
+
dialogForm: currentForm,
|
|
44
|
+
params: params
|
|
43
45
|
}),
|
|
44
46
|
modalVisible = _useModifyProps.modalVisible,
|
|
45
47
|
modalFormData = _useModifyProps.modalFormData,
|
|
46
48
|
setModalVisible = _useModifyProps.setModalVisible,
|
|
47
49
|
initValue = _useModifyProps.initValue,
|
|
48
|
-
onAfterClose = _useModifyProps.onAfterClose
|
|
49
|
-
|
|
50
|
+
onAfterClose = _useModifyProps.onAfterClose,
|
|
51
|
+
formParams = _useModifyProps.formParams;
|
|
52
|
+
var cancel = function cancel() {
|
|
50
53
|
onAfterClose();
|
|
51
54
|
if (onCancel) {
|
|
52
|
-
return onCancel === null || onCancel === void 0 ? void 0 : onCancel(
|
|
55
|
+
return onCancel === null || onCancel === void 0 ? void 0 : onCancel();
|
|
53
56
|
}
|
|
54
57
|
setModalVisible(false);
|
|
55
58
|
};
|
|
@@ -86,22 +89,32 @@ var DrawerForm = (function (_ref) {
|
|
|
86
89
|
initialValues: initValue
|
|
87
90
|
}, props, {
|
|
88
91
|
form: currentForm,
|
|
92
|
+
params: formParams,
|
|
89
93
|
onFinish: /*#__PURE__*/function () {
|
|
90
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(values) {
|
|
94
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(values, subParams) {
|
|
95
|
+
var result, close;
|
|
91
96
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
92
97
|
while (1) switch (_context.prev = _context.next) {
|
|
93
98
|
case 0:
|
|
94
99
|
_context.next = 2;
|
|
95
|
-
return run(values);
|
|
100
|
+
return run(values, subParams);
|
|
96
101
|
case 2:
|
|
97
|
-
|
|
98
|
-
|
|
102
|
+
result = _context.sent;
|
|
103
|
+
close = onOk === null || onOk === void 0 ? void 0 : onOk(result, subParams);
|
|
104
|
+
if (!(close === false)) {
|
|
105
|
+
_context.next = 6;
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
return _context.abrupt("return");
|
|
109
|
+
case 6:
|
|
110
|
+
cancel();
|
|
111
|
+
case 7:
|
|
99
112
|
case "end":
|
|
100
113
|
return _context.stop();
|
|
101
114
|
}
|
|
102
115
|
}, _callee);
|
|
103
116
|
}));
|
|
104
|
-
return function (_x) {
|
|
117
|
+
return function (_x, _x2) {
|
|
105
118
|
return _ref2.apply(this, arguments);
|
|
106
119
|
};
|
|
107
120
|
}(),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { DialogFormProps } from "./modal";
|
|
3
|
-
declare const _default: ({ visible, title, onCancel, configData, infoRequest, request, afterClose, dialogForm, initialValues, onFinish, ...props }: DialogFormProps) => JSX.Element;
|
|
3
|
+
declare const _default: ({ visible, title, onCancel, configData, infoRequest, request, afterClose, dialogForm, initialValues, onFinish, params, onOk, ...props }: DialogFormProps) => JSX.Element;
|
|
4
4
|
export default _default;
|
|
@@ -11,7 +11,7 @@ var antd = require('antd');
|
|
|
11
11
|
var index = require('../Form/index.js');
|
|
12
12
|
var hooks = require('./hooks.js');
|
|
13
13
|
|
|
14
|
-
var _excluded = ["visible", "title", "onCancel", "configData", "infoRequest", "request", "afterClose", "dialogForm", "initialValues", "onFinish"];
|
|
14
|
+
var _excluded = ["visible", "title", "onCancel", "configData", "infoRequest", "request", "afterClose", "dialogForm", "initialValues", "onFinish", "params", "onOk"];
|
|
15
15
|
var ModalForm = (function (_ref) {
|
|
16
16
|
var visible = _ref.visible,
|
|
17
17
|
title = _ref.title,
|
|
@@ -24,21 +24,25 @@ var ModalForm = (function (_ref) {
|
|
|
24
24
|
_ref$initialValues = _ref.initialValues,
|
|
25
25
|
initialValues = _ref$initialValues === void 0 ? {} : _ref$initialValues,
|
|
26
26
|
onFinish = _ref.onFinish,
|
|
27
|
+
params = _ref.params,
|
|
28
|
+
onOk = _ref.onOk,
|
|
27
29
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
28
30
|
var currentForm = hooks.useCurrentForm(dialogForm);
|
|
29
31
|
var _useModifyProps = hooks.useModifyProps({
|
|
30
32
|
configData: configData,
|
|
31
33
|
visible: visible,
|
|
32
34
|
initialValues: initialValues,
|
|
33
|
-
dialogForm: currentForm
|
|
35
|
+
dialogForm: currentForm,
|
|
36
|
+
params: params
|
|
34
37
|
}),
|
|
35
38
|
modalVisible = _useModifyProps.modalVisible,
|
|
36
39
|
modalFormData = _useModifyProps.modalFormData,
|
|
37
40
|
setModalVisible = _useModifyProps.setModalVisible,
|
|
38
|
-
initValue = _useModifyProps.initValue
|
|
39
|
-
|
|
41
|
+
initValue = _useModifyProps.initValue,
|
|
42
|
+
formParams = _useModifyProps.formParams;
|
|
43
|
+
var cancel = function cancel() {
|
|
40
44
|
if (onCancel) {
|
|
41
|
-
return onCancel === null || onCancel === void 0 ? void 0 : onCancel(
|
|
45
|
+
return onCancel === null || onCancel === void 0 ? void 0 : onCancel();
|
|
42
46
|
}
|
|
43
47
|
setModalVisible(false);
|
|
44
48
|
};
|
|
@@ -64,25 +68,35 @@ var ModalForm = (function (_ref) {
|
|
|
64
68
|
configData: modalFormData,
|
|
65
69
|
initialValues: initValue,
|
|
66
70
|
onFinish: /*#__PURE__*/function () {
|
|
67
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(values) {
|
|
71
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(values, params) {
|
|
72
|
+
var result, close;
|
|
68
73
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
69
74
|
while (1) switch (_context.prev = _context.next) {
|
|
70
75
|
case 0:
|
|
71
76
|
_context.next = 2;
|
|
72
|
-
return run(values);
|
|
77
|
+
return run(values, params);
|
|
73
78
|
case 2:
|
|
74
|
-
|
|
75
|
-
|
|
79
|
+
result = _context.sent;
|
|
80
|
+
close = onOk === null || onOk === void 0 ? void 0 : onOk(result, params);
|
|
81
|
+
if (!(close === false)) {
|
|
82
|
+
_context.next = 6;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
return _context.abrupt("return");
|
|
86
|
+
case 6:
|
|
87
|
+
cancel();
|
|
88
|
+
case 7:
|
|
76
89
|
case "end":
|
|
77
90
|
return _context.stop();
|
|
78
91
|
}
|
|
79
92
|
}, _callee);
|
|
80
93
|
}));
|
|
81
|
-
return function (_x) {
|
|
94
|
+
return function (_x, _x2) {
|
|
82
95
|
return _ref2.apply(this, arguments);
|
|
83
96
|
};
|
|
84
97
|
}()
|
|
85
98
|
}, props, {
|
|
99
|
+
params: formParams,
|
|
86
100
|
form: currentForm,
|
|
87
101
|
infoRequest: infoRequest
|
|
88
102
|
})));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { DialogFormProps, HDialogFormInstance, ModifyPropsModal } from "./modal";
|
|
3
|
-
export declare const useModifyProps: ({ visible, configData, initialValues, dialogForm, afterClose, }: ModifyPropsModal) => {
|
|
3
|
+
export declare const useModifyProps: ({ visible, configData, initialValues, dialogForm, afterClose, params }: ModifyPropsModal) => {
|
|
4
4
|
modalFormData: import("../Form/modal").HItemProps[];
|
|
5
5
|
modalVisible: boolean | undefined;
|
|
6
6
|
setModalVisible: import("react").Dispatch<import("react").SetStateAction<boolean | undefined>>;
|
|
@@ -8,7 +8,8 @@ export declare const useModifyProps: ({ visible, configData, initialValues, dial
|
|
|
8
8
|
initValue: Record<string, any> | undefined;
|
|
9
9
|
setInitValue: import("react").Dispatch<import("react").SetStateAction<Record<string, any> | undefined>>;
|
|
10
10
|
onAfterClose: () => void;
|
|
11
|
+
formParams: any;
|
|
11
12
|
};
|
|
12
|
-
export declare const useHDialogForm: () => HDialogFormInstance
|
|
13
|
-
export declare const useCurrentForm: (hDialogForm?: HDialogFormInstance) => HDialogFormInstance
|
|
14
|
-
export declare const useSub: ({ request, onFinish }: Partial<DialogFormProps>) => import("@ahooksjs/use-request/lib/types").BaseResult<any, [values: any]>;
|
|
13
|
+
export declare const useHDialogForm: () => HDialogFormInstance<any, any>;
|
|
14
|
+
export declare const useCurrentForm: (hDialogForm?: HDialogFormInstance) => HDialogFormInstance<any, any>;
|
|
15
|
+
export declare const useSub: ({ request, onFinish }: Partial<DialogFormProps>) => import("@ahooksjs/use-request/lib/types").BaseResult<any, [values: any, params: any]>;
|
package/lib/DialogForm/hooks.js
CHANGED
|
@@ -24,7 +24,8 @@ var useModifyProps = function useModifyProps(_ref) {
|
|
|
24
24
|
configData = _ref.configData,
|
|
25
25
|
initialValues = _ref.initialValues,
|
|
26
26
|
dialogForm = _ref.dialogForm,
|
|
27
|
-
afterClose = _ref.afterClose
|
|
27
|
+
afterClose = _ref.afterClose,
|
|
28
|
+
params = _ref.params;
|
|
28
29
|
var _useState = React.useState(visible),
|
|
29
30
|
_useState2 = _slicedToArray(_useState, 2),
|
|
30
31
|
modalVisible = _useState2[0],
|
|
@@ -37,11 +38,15 @@ var useModifyProps = function useModifyProps(_ref) {
|
|
|
37
38
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
38
39
|
initValue = _useState6[0],
|
|
39
40
|
setInitValue = _useState6[1];
|
|
41
|
+
var _useState7 = React.useState(params),
|
|
42
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
43
|
+
formParams = _useState8[0],
|
|
44
|
+
setFormParams = _useState8[1];
|
|
40
45
|
var onAfterClose = function onAfterClose() {
|
|
41
46
|
_setTimeout(function () {
|
|
42
47
|
dialogForm.resetFields();
|
|
43
48
|
afterClose === null || afterClose === void 0 ? void 0 : afterClose();
|
|
44
|
-
},
|
|
49
|
+
}, 100);
|
|
45
50
|
};
|
|
46
51
|
React.useEffect(function () {
|
|
47
52
|
setModalVisible(visible);
|
|
@@ -49,14 +54,21 @@ var useModifyProps = function useModifyProps(_ref) {
|
|
|
49
54
|
React.useEffect(function () {
|
|
50
55
|
setModalFormData(configData);
|
|
51
56
|
}, [configData]);
|
|
57
|
+
React.useEffect(function () {
|
|
58
|
+
setFormParams(params);
|
|
59
|
+
}, [params]);
|
|
52
60
|
React.useEffect(function () {
|
|
53
61
|
dialogForm.show = function () {
|
|
54
|
-
var
|
|
55
|
-
var changeConfigData =
|
|
56
|
-
changeInitialValues =
|
|
62
|
+
var showParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
63
|
+
var changeConfigData = showParams.configData,
|
|
64
|
+
changeInitialValues = showParams.initialValues,
|
|
65
|
+
params = showParams.params;
|
|
57
66
|
if (!!changeConfigData) {
|
|
58
67
|
setModalFormData(changeConfigData);
|
|
59
68
|
}
|
|
69
|
+
if (!!params) {
|
|
70
|
+
setFormParams(params);
|
|
71
|
+
}
|
|
60
72
|
setInitValue(changeInitialValues);
|
|
61
73
|
setModalVisible(true);
|
|
62
74
|
};
|
|
@@ -72,7 +84,8 @@ var useModifyProps = function useModifyProps(_ref) {
|
|
|
72
84
|
setModalFormData: setModalFormData,
|
|
73
85
|
initValue: initValue,
|
|
74
86
|
setInitValue: setInitValue,
|
|
75
|
-
onAfterClose: onAfterClose
|
|
87
|
+
onAfterClose: onAfterClose,
|
|
88
|
+
formParams: formParams
|
|
76
89
|
};
|
|
77
90
|
};
|
|
78
91
|
var useHDialogForm = function useHDialogForm() {
|
|
@@ -92,7 +105,7 @@ var useSub = function useSub(_ref2) {
|
|
|
92
105
|
var request = _ref2.request,
|
|
93
106
|
onFinish = _ref2.onFinish;
|
|
94
107
|
return ahooks.useRequest( /*#__PURE__*/function () {
|
|
95
|
-
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(values) {
|
|
108
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(values, params) {
|
|
96
109
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
97
110
|
while (1) switch (_context.prev = _context.next) {
|
|
98
111
|
case 0:
|
|
@@ -100,20 +113,20 @@ var useSub = function useSub(_ref2) {
|
|
|
100
113
|
_context.next = 2;
|
|
101
114
|
break;
|
|
102
115
|
}
|
|
103
|
-
return _context.abrupt("return", onFinish(values));
|
|
116
|
+
return _context.abrupt("return", onFinish(values, params));
|
|
104
117
|
case 2:
|
|
105
118
|
if (!request) {
|
|
106
119
|
_context.next = 4;
|
|
107
120
|
break;
|
|
108
121
|
}
|
|
109
|
-
return _context.abrupt("return", request(values));
|
|
122
|
+
return _context.abrupt("return", request(values, params));
|
|
110
123
|
case 4:
|
|
111
124
|
case "end":
|
|
112
125
|
return _context.stop();
|
|
113
126
|
}
|
|
114
127
|
}, _callee);
|
|
115
128
|
}));
|
|
116
|
-
return function (_x) {
|
|
129
|
+
return function (_x, _x2) {
|
|
117
130
|
return _ref3.apply(this, arguments);
|
|
118
131
|
};
|
|
119
132
|
}(), {
|
|
@@ -2,24 +2,30 @@ import type { ModalProps } from "antd";
|
|
|
2
2
|
import type { HFormInstance, HItemProps, HFormProps } from "../Form/modal";
|
|
3
3
|
import type { PromiseFnResult } from "../modal";
|
|
4
4
|
type RootProps = HFormProps & ModalProps;
|
|
5
|
-
export interface ModifyPropsModal {
|
|
5
|
+
export interface ModifyPropsModal<P = any> {
|
|
6
6
|
configData: HItemProps[];
|
|
7
7
|
visible?: boolean;
|
|
8
8
|
initialValues?: Record<string, any>;
|
|
9
9
|
dialogForm: HDialogFormInstance;
|
|
10
10
|
afterClose?: VoidFunction;
|
|
11
|
+
params?: P;
|
|
11
12
|
}
|
|
12
|
-
export interface ShowParamsModal {
|
|
13
|
+
export interface ShowParamsModal<P = any, T = any> {
|
|
13
14
|
configData?: HItemProps[];
|
|
14
15
|
visible?: boolean;
|
|
15
16
|
initialValues?: Record<string, any>;
|
|
17
|
+
infoRequest?: PromiseFnResult<P, T>;
|
|
18
|
+
params?: P;
|
|
16
19
|
}
|
|
17
|
-
export interface HDialogFormInstance extends HFormInstance {
|
|
18
|
-
show: (data?: ShowParamsModal) => void;
|
|
20
|
+
export interface HDialogFormInstance<P = any, T = any> extends HFormInstance {
|
|
21
|
+
show: (data?: ShowParamsModal<P, T>) => void;
|
|
19
22
|
hide: VoidFunction;
|
|
20
23
|
}
|
|
21
|
-
export interface DialogFormProps extends Omit<RootProps, "onFinish"> {
|
|
24
|
+
export interface DialogFormProps<P = any, T = any> extends Omit<RootProps, "onFinish" | "onCancel" | "onOk" | "infoRequest"> {
|
|
22
25
|
dialogForm?: HDialogFormInstance;
|
|
23
|
-
onFinish?:
|
|
26
|
+
onFinish?: (values: T, params: P) => Promise<any>;
|
|
27
|
+
onCancel?: VoidFunction;
|
|
28
|
+
onOk?: (data: T, params: P) => boolean | undefined;
|
|
29
|
+
infoRequest?: (params: P) => Promise<T>;
|
|
24
30
|
}
|
|
25
31
|
export {};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type { HFormProps } from "
|
|
2
|
-
import type { HFormInstance } from "@/components/Form/modal";
|
|
1
|
+
import type { HFormProps, HFormInstance } from "../modal";
|
|
3
2
|
export declare const useCurrentForm: (form?: HFormInstance) => HFormInstance;
|
|
4
3
|
type ParamsModal = Omit<HFormProps, "configData">;
|
|
5
|
-
export declare const
|
|
4
|
+
export declare const useInfoReq: ({ initialValues, infoRequest, form, params, request, onFinish, }: ParamsModal) => {
|
|
5
|
+
subControl: import("@ahooksjs/use-request/lib/types").BaseResult<void, [value: any]>;
|
|
6
|
+
infoControl: import("@ahooksjs/use-request/lib/types").BaseResult<import("rc-field-form/lib/interface").Store, [reqParams?: any]>;
|
|
7
|
+
};
|
|
6
8
|
export {};
|
package/lib/Form/hooks/index.js
CHANGED
|
@@ -4,16 +4,26 @@ var _asyncToGenerator = require('@babel/runtime-corejs3/helpers/asyncToGenerator
|
|
|
4
4
|
var _regeneratorRuntime = require('@babel/runtime-corejs3/regenerator');
|
|
5
5
|
var ahooks = require('ahooks');
|
|
6
6
|
var useHForm = require('./useHForm.js');
|
|
7
|
+
var React = require('react');
|
|
7
8
|
|
|
8
9
|
var useCurrentForm = function useCurrentForm(form) {
|
|
9
10
|
var selfForm = useHForm.default();
|
|
10
11
|
return form || selfForm;
|
|
11
12
|
};
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
form = _ref.form
|
|
16
|
-
|
|
13
|
+
var useInfoReq = function useInfoReq(_ref) {
|
|
14
|
+
var initialValues = _ref.initialValues,
|
|
15
|
+
infoRequest = _ref.infoRequest,
|
|
16
|
+
form = _ref.form,
|
|
17
|
+
params = _ref.params,
|
|
18
|
+
request = _ref.request,
|
|
19
|
+
onFinish = _ref.onFinish;
|
|
20
|
+
var reqData = React.useMemo(function () {
|
|
21
|
+
var saveParams = params || {};
|
|
22
|
+
return {
|
|
23
|
+
params: saveParams
|
|
24
|
+
};
|
|
25
|
+
}, [params]);
|
|
26
|
+
var subControl = ahooks.useRequest( /*#__PURE__*/function () {
|
|
17
27
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(value) {
|
|
18
28
|
var subVal;
|
|
19
29
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
@@ -25,9 +35,9 @@ var useSub = function useSub(_ref) {
|
|
|
25
35
|
break;
|
|
26
36
|
}
|
|
27
37
|
_context.next = 4;
|
|
28
|
-
return request(subVal);
|
|
38
|
+
return request(subVal, reqData.params);
|
|
29
39
|
case 4:
|
|
30
|
-
onFinish === null || onFinish === void 0 ? void 0 : onFinish(subVal);
|
|
40
|
+
onFinish === null || onFinish === void 0 ? void 0 : onFinish(subVal, reqData.params);
|
|
31
41
|
case 5:
|
|
32
42
|
case "end":
|
|
33
43
|
return _context.stop();
|
|
@@ -40,8 +50,55 @@ var useSub = function useSub(_ref) {
|
|
|
40
50
|
}(), {
|
|
41
51
|
manual: true
|
|
42
52
|
});
|
|
53
|
+
var infoControl = ahooks.useRequest( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
54
|
+
var reqParams,
|
|
55
|
+
setValue,
|
|
56
|
+
_args2 = arguments;
|
|
57
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
58
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
59
|
+
case 0:
|
|
60
|
+
reqParams = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : reqData.params;
|
|
61
|
+
setValue = initialValues;
|
|
62
|
+
reqData.params = reqParams;
|
|
63
|
+
if (!(!initialValues && !infoRequest)) {
|
|
64
|
+
_context2.next = 5;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
return _context2.abrupt("return", {});
|
|
68
|
+
case 5:
|
|
69
|
+
if (!infoRequest) {
|
|
70
|
+
_context2.next = 9;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
_context2.next = 8;
|
|
74
|
+
return infoRequest(reqParams);
|
|
75
|
+
case 8:
|
|
76
|
+
setValue = _context2.sent;
|
|
77
|
+
case 9:
|
|
78
|
+
form === null || form === void 0 ? void 0 : form.setFieldsValue(setValue);
|
|
79
|
+
return _context2.abrupt("return", setValue || {});
|
|
80
|
+
case 11:
|
|
81
|
+
case "end":
|
|
82
|
+
return _context2.stop();
|
|
83
|
+
}
|
|
84
|
+
}, _callee2);
|
|
85
|
+
})));
|
|
86
|
+
var run = infoControl.run,
|
|
87
|
+
mutate = infoControl.mutate;
|
|
88
|
+
React.useEffect(function () {
|
|
89
|
+
if (form) {
|
|
90
|
+
form.reload = function (params) {
|
|
91
|
+
mutate(undefined);
|
|
92
|
+
return run(params);
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}, []);
|
|
96
|
+
return {
|
|
97
|
+
subControl: subControl,
|
|
98
|
+
infoControl: infoControl
|
|
99
|
+
};
|
|
43
100
|
};
|
|
44
101
|
|
|
45
102
|
exports.useCurrentForm = useCurrentForm;
|
|
46
|
-
exports.
|
|
103
|
+
exports.useInfoReq = useInfoReq;
|
|
47
104
|
// powered by h
|
|
@@ -11,12 +11,12 @@ var _Object$defineProperty = require('@babel/runtime-corejs3/core-js/object/defi
|
|
|
11
11
|
var _toConsumableArray = require('@babel/runtime-corejs3/helpers/toConsumableArray');
|
|
12
12
|
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
13
13
|
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
14
|
+
var _Promise = require('@babel/runtime-corejs3/core-js/promise');
|
|
14
15
|
var _Object$keys = require('@babel/runtime-corejs3/core-js/object/keys');
|
|
15
16
|
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/for-each');
|
|
16
17
|
var _Reflect$deleteProperty = require('@babel/runtime-corejs3/core-js/reflect/delete-property');
|
|
17
18
|
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/concat');
|
|
18
19
|
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/map');
|
|
19
|
-
var _Promise = require('@babel/runtime-corejs3/core-js/promise');
|
|
20
20
|
var React = require('react');
|
|
21
21
|
var antd = require('antd');
|
|
22
22
|
|
|
@@ -44,6 +44,9 @@ var useHForm = (function () {
|
|
|
44
44
|
};
|
|
45
45
|
};
|
|
46
46
|
return _objectSpread(_objectSpread({
|
|
47
|
+
reload: function reload(params) {
|
|
48
|
+
return _Promise.resolve(params);
|
|
49
|
+
},
|
|
47
50
|
initValues: function initValues() {
|
|
48
51
|
if (cacheValues) {
|
|
49
52
|
var newValue = this.formatValues(cacheValues);
|
package/lib/Form/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { HFormProps } from "./modal";
|
|
3
|
-
declare const _default: ({ configData, labelWidth, form, request, onFinish, infoRequest, valueType, initialValues, ...props }: HFormProps) => JSX.Element;
|
|
3
|
+
declare const _default: ({ configData, labelWidth, form, request, onFinish, infoRequest, valueType, initialValues, params, ...props }: HFormProps) => JSX.Element;
|
|
4
4
|
export default _default;
|
package/lib/Form/index.js
CHANGED
|
@@ -4,20 +4,17 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var _extends = require('@babel/runtime-corejs3/helpers/extends');
|
|
7
|
-
var _asyncToGenerator = require('@babel/runtime-corejs3/helpers/asyncToGenerator');
|
|
8
7
|
var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWithoutProperties');
|
|
9
8
|
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/map');
|
|
10
|
-
var _regeneratorRuntime = require('@babel/runtime-corejs3/regenerator');
|
|
11
9
|
var antd = require('antd');
|
|
12
10
|
var index$3 = require('./FormItem/index.js');
|
|
13
11
|
var index = require('./hooks/index.js');
|
|
14
12
|
var index$2 = require('./Context/index.js');
|
|
15
13
|
var index$1 = require('../PageHandler/index.js');
|
|
16
14
|
var useInitConfigData = require('./hooks/useInitConfigData.js');
|
|
17
|
-
var ahooks = require('ahooks');
|
|
18
15
|
var InitSet = require('./InitSet.js');
|
|
19
16
|
|
|
20
|
-
var _excluded = ["configData", "labelWidth", "form", "request", "onFinish", "infoRequest", "valueType", "initialValues"];
|
|
17
|
+
var _excluded = ["configData", "labelWidth", "form", "request", "onFinish", "infoRequest", "valueType", "initialValues", "params"];
|
|
21
18
|
var HForm = (function (_ref) {
|
|
22
19
|
var configData = _ref.configData,
|
|
23
20
|
labelWidth = _ref.labelWidth,
|
|
@@ -28,53 +25,31 @@ var HForm = (function (_ref) {
|
|
|
28
25
|
_ref$valueType = _ref.valueType,
|
|
29
26
|
valueType = _ref$valueType === void 0 ? "float" : _ref$valueType,
|
|
30
27
|
initialValues = _ref.initialValues,
|
|
28
|
+
_ref$params = _ref.params,
|
|
29
|
+
params = _ref$params === void 0 ? {} : _ref$params,
|
|
31
30
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
32
31
|
var hForm = index.useCurrentForm(form);
|
|
33
32
|
var newConfigData = useInitConfigData.default({
|
|
34
33
|
configData: configData,
|
|
35
34
|
form: hForm
|
|
36
35
|
});
|
|
37
|
-
var
|
|
36
|
+
var _useInfoReq = index.useInfoReq({
|
|
37
|
+
initialValues: initialValues,
|
|
38
38
|
request: request,
|
|
39
39
|
onFinish: onFinish,
|
|
40
40
|
valueType: valueType,
|
|
41
|
-
form: hForm
|
|
41
|
+
form: hForm,
|
|
42
|
+
infoRequest: infoRequest,
|
|
43
|
+
params: params
|
|
42
44
|
}),
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
var
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (!(!initialValues && !infoRequest)) {
|
|
52
|
-
_context.next = 3;
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
return _context.abrupt("return", {});
|
|
56
|
-
case 3:
|
|
57
|
-
if (!infoRequest) {
|
|
58
|
-
_context.next = 7;
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
_context.next = 6;
|
|
62
|
-
return infoRequest();
|
|
63
|
-
case 6:
|
|
64
|
-
setValue = _context.sent;
|
|
65
|
-
case 7:
|
|
66
|
-
hForm.setFieldsValue(setValue);
|
|
67
|
-
return _context.abrupt("return", setValue || {});
|
|
68
|
-
case 9:
|
|
69
|
-
case "end":
|
|
70
|
-
return _context.stop();
|
|
71
|
-
}
|
|
72
|
-
}, _callee);
|
|
73
|
-
}))),
|
|
74
|
-
infoRun = _useRequest.run,
|
|
75
|
-
infoLoading = _useRequest.loading,
|
|
76
|
-
infoErr = _useRequest.error,
|
|
77
|
-
infoData = _useRequest.data;
|
|
45
|
+
subControl = _useInfoReq.subControl,
|
|
46
|
+
infoControl = _useInfoReq.infoControl;
|
|
47
|
+
var run = subControl.run,
|
|
48
|
+
loading = subControl.loading;
|
|
49
|
+
var infoRun = infoControl.run,
|
|
50
|
+
infoLoading = infoControl.loading,
|
|
51
|
+
infoErr = infoControl.error,
|
|
52
|
+
infoData = infoControl.data;
|
|
78
53
|
React.useEffect(function () {
|
|
79
54
|
return function () {
|
|
80
55
|
hForm.removeDispatchListener();
|
package/lib/Form/modal.d.ts
CHANGED
|
@@ -33,13 +33,15 @@ export interface HItemProps extends Omit<FormItemProps, "name"> {
|
|
|
33
33
|
placeholder?: string | string[];
|
|
34
34
|
name?: string;
|
|
35
35
|
}
|
|
36
|
-
export interface HFormProps<T = any, R = any> extends Omit<FormProps, "form"> {
|
|
36
|
+
export interface HFormProps<T = any, R = any> extends Omit<FormProps, "form" | "onFinish"> {
|
|
37
37
|
configData: HItemProps[];
|
|
38
38
|
labelWidth?: number;
|
|
39
|
-
request?:
|
|
40
|
-
infoRequest?:
|
|
39
|
+
request?: (values: T, params?: any) => Promise<R>;
|
|
40
|
+
infoRequest?: PromiseFnResult;
|
|
41
41
|
valueType?: string;
|
|
42
42
|
form?: HFormInstance;
|
|
43
|
+
params?: any;
|
|
44
|
+
onFinish?: (values: T, params?: any) => void;
|
|
43
45
|
}
|
|
44
46
|
export interface HFormItemProps extends HItemProps {
|
|
45
47
|
required?: boolean;
|
|
@@ -80,6 +82,7 @@ export interface HFormInstance extends FormInstance {
|
|
|
80
82
|
outputValues: (values?: Record<string, any>) => Record<string, any>;
|
|
81
83
|
addDispatchListener: AddDispatchListenerFn;
|
|
82
84
|
removeDispatchListener: (action?: ActionModal, fn?: argsFn) => void;
|
|
85
|
+
reload: PromiseFnResult;
|
|
83
86
|
}
|
|
84
87
|
export interface ConnectConfigModal {
|
|
85
88
|
format?: Record<string, addFormatItemModal>;
|
package/package.json
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { Row, Space, Button } from "antd";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
interface IProps{
|
|
4
|
+
onOk?:VoidFunction;
|
|
5
|
+
onCancel?:VoidFunction;
|
|
6
|
+
confirmLoading?:boolean;
|
|
7
|
+
}
|
|
3
8
|
|
|
4
9
|
export default ({
|
|
5
10
|
onCancel,
|
|
6
11
|
onOk,
|
|
7
12
|
confirmLoading,
|
|
8
|
-
}:
|
|
13
|
+
}: IProps) => {
|
|
9
14
|
return (
|
|
10
15
|
<Row justify={"end"}>
|
|
11
16
|
<Space size={"middle"}>
|
|
@@ -21,6 +21,7 @@ export default ({
|
|
|
21
21
|
size,
|
|
22
22
|
form,
|
|
23
23
|
footer,
|
|
24
|
+
params,
|
|
24
25
|
...props
|
|
25
26
|
}: DialogFormProps) => {
|
|
26
27
|
const currentForm = useCurrentForm(dialogForm);
|
|
@@ -30,16 +31,18 @@ export default ({
|
|
|
30
31
|
setModalVisible,
|
|
31
32
|
initValue,
|
|
32
33
|
onAfterClose,
|
|
34
|
+
formParams
|
|
33
35
|
} = useModifyProps({
|
|
34
36
|
configData,
|
|
35
37
|
visible,
|
|
36
38
|
initialValues,
|
|
37
39
|
dialogForm: currentForm,
|
|
40
|
+
params
|
|
38
41
|
});
|
|
39
|
-
const cancel = (
|
|
42
|
+
const cancel = () => {
|
|
40
43
|
onAfterClose();
|
|
41
44
|
if (onCancel) {
|
|
42
|
-
return onCancel?.(
|
|
45
|
+
return onCancel?.();
|
|
43
46
|
}
|
|
44
47
|
setModalVisible(false);
|
|
45
48
|
};
|
|
@@ -73,9 +76,14 @@ export default ({
|
|
|
73
76
|
initialValues={initValue}
|
|
74
77
|
{...props}
|
|
75
78
|
form={currentForm}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
params={formParams}
|
|
80
|
+
onFinish={async (values,subParams) => {
|
|
81
|
+
const result = await run(values,subParams);
|
|
82
|
+
const close = onOk?.(result,subParams);
|
|
83
|
+
if (close === false) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
cancel();
|
|
79
87
|
}}
|
|
80
88
|
infoRequest={infoRequest}
|
|
81
89
|
labelWidth={labelWidth}
|