@hw-component/form 0.0.6-beta-v7 → 0.0.6-beta-v9

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,8 +32,7 @@ var DrawerForm = (function (_ref) {
32
32
  var dialogForm = _ref.dialogForm,
33
33
  _ref$closable = _ref.closable,
34
34
  closable = _ref$closable === void 0 ? true : _ref$closable,
35
- _ref$initialValues = _ref.initialValues,
36
- initialValues = _ref$initialValues === void 0 ? {} : _ref$initialValues,
35
+ initialValues = _ref.initialValues,
37
36
  labelWidth = _ref.labelWidth,
38
37
  onOk = _ref.onOk,
39
38
  onFinish = _ref.onFinish;
@@ -50,14 +49,17 @@ var DrawerForm = (function (_ref) {
50
49
  visible: visible,
51
50
  initialValues: initialValues,
52
51
  dialogForm: currentForm,
53
- params: params
52
+ params: params,
53
+ title: title,
54
+ onCancel: onCancel
54
55
  }),
55
56
  modalVisible = _useModifyProps.modalVisible,
56
57
  modalFormData = _useModifyProps.modalFormData,
57
58
  setModalVisible = _useModifyProps.setModalVisible,
58
59
  initValue = _useModifyProps.initValue,
59
60
  onAfterClose = _useModifyProps.onAfterClose,
60
- formParams = _useModifyProps.formParams;
61
+ formParams = _useModifyProps.formParams,
62
+ modalTitle = _useModifyProps.title;
61
63
  var cancel = function cancel() {
62
64
  onAfterClose();
63
65
  if (onCancel) {
@@ -84,7 +86,7 @@ var DrawerForm = (function (_ref) {
84
86
  return jsx(Drawer, _objectSpread(_objectSpread({
85
87
  visible: modalVisible,
86
88
  title: jsx(Title, {
87
- title: title,
89
+ title: modalTitle,
88
90
  closable: closable,
89
91
  onCancel: cancel
90
92
  })
@@ -28,8 +28,7 @@ var ModalForm = (function (_ref) {
28
28
  request = _ref.request,
29
29
  _afterClose = _ref.afterClose,
30
30
  dialogForm = _ref.dialogForm,
31
- _ref$initialValues = _ref.initialValues,
32
- initialValues = _ref$initialValues === void 0 ? {} : _ref$initialValues,
31
+ initialValues = _ref.initialValues,
33
32
  onFinish = _ref.onFinish,
34
33
  params = _ref.params,
35
34
  onOk = _ref.onOk,
@@ -43,7 +42,8 @@ var ModalForm = (function (_ref) {
43
42
  initialValues: initialValues,
44
43
  dialogForm: currentForm,
45
44
  params: params,
46
- title: title
45
+ title: title,
46
+ onCancel: onCancel
47
47
  }),
48
48
  modalVisible = _useModifyProps.modalVisible,
49
49
  modalFormData = _useModifyProps.modalFormData,
@@ -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, params, title, }: ModifyPropsModal) => {
3
+ export declare const useModifyProps: ({ visible, configData, initialValues, dialogForm, afterClose, params, title, onCancel }: ModifyPropsModal) => {
4
4
  modalFormData: import("../Form/modal").HItemProps[];
5
5
  modalVisible: boolean | undefined;
6
6
  setModalVisible: import("react").Dispatch<import("react").SetStateAction<boolean | undefined>>;
@@ -23,7 +23,8 @@ var useModifyProps = function useModifyProps(_ref) {
23
23
  dialogForm = _ref.dialogForm,
24
24
  afterClose = _ref.afterClose,
25
25
  params = _ref.params,
26
- title = _ref.title;
26
+ title = _ref.title,
27
+ onCancel = _ref.onCancel;
27
28
  var _useState = useState(visible),
28
29
  _useState2 = _slicedToArray(_useState, 2),
29
30
  modalVisible = _useState2[0],
@@ -45,6 +46,7 @@ var useModifyProps = function useModifyProps(_ref) {
45
46
  modalTitle = _useState10[0],
46
47
  setModalTitle = _useState10[1];
47
48
  var onAfterClose = function onAfterClose() {
49
+ onCancel === null || onCancel === void 0 || onCancel();
48
50
  setTimeout(function () {
49
51
  dialogForm.clear();
50
52
  afterClose === null || afterClose === void 0 || afterClose();
@@ -62,6 +64,9 @@ var useModifyProps = function useModifyProps(_ref) {
62
64
  useEffect(function () {
63
65
  setModalTitle(title);
64
66
  }, [title]);
67
+ useEffect(function () {
68
+ setInitValue(initialValues);
69
+ }, [initialValues]);
65
70
  useEffect(function () {
66
71
  dialogForm.show = function () {
67
72
  var showParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -10,6 +10,7 @@ export interface ModifyPropsModal<P = any> {
10
10
  afterClose?: VoidFunction;
11
11
  params?: P;
12
12
  title?: DialogFormProps["title"];
13
+ onCancel?: VoidFunction;
13
14
  }
14
15
  export interface ShowParamsModal<P = any, T = any> {
15
16
  configData?: HItemProps[];
@@ -9,7 +9,7 @@ export declare const useCurrentForm: (form?: HFormInstance) => HFormInstance;
9
9
  type ParamsModal = Omit<HFormProps, "configData">;
10
10
  export declare const useInfoReq: ({ initialValues, infoRequest, form, params, request, onFinish, }: ParamsModal) => {
11
11
  subControl: import("@ahooksjs/use-request/lib/types").BaseResult<void, [value: any]>;
12
- infoControl: import("@ahooksjs/use-request/lib/types").BaseResult<import("rc-field-form/lib/interface").Store, [reqParams?: any]>;
12
+ infoControl: import("@ahooksjs/use-request/lib/types").BaseResult<any, [reqParams?: any]>;
13
13
  };
14
14
  export declare const useDefaultComponents: () => any;
15
15
  export declare const useValuesChange: ({ onValuesChange, dispatch, form, }: UseValuesChangeModal) => (changedValues: any, values: any) => void;
@@ -63,33 +63,29 @@ var useInfoReq = function useInfoReq(_ref) {
63
63
  });
64
64
  var infoControl = useRequest( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
65
65
  var reqParams,
66
+ result,
66
67
  setValue,
67
68
  _args2 = arguments;
68
69
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
69
70
  while (1) switch (_context2.prev = _context2.next) {
70
71
  case 0:
71
72
  reqParams = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : reqData.params;
72
- setValue = initialValues;
73
73
  reqData.params = reqParams;
74
- if (!(!initialValues && !infoRequest)) {
75
- _context2.next = 6;
76
- break;
77
- }
78
- form === null || form === void 0 || form.setFieldsValue({});
79
- return _context2.abrupt("return", {});
80
- case 6:
81
74
  if (!infoRequest) {
82
- _context2.next = 10;
75
+ _context2.next = 8;
83
76
  break;
84
77
  }
85
- _context2.next = 9;
78
+ _context2.next = 5;
86
79
  return infoRequest(reqParams);
87
- case 9:
88
- setValue = _context2.sent;
89
- case 10:
80
+ case 5:
81
+ result = _context2.sent;
82
+ form === null || form === void 0 || form.setFieldsValue(result);
83
+ return _context2.abrupt("return", result || {});
84
+ case 8:
85
+ setValue = initialValues || {};
90
86
  form === null || form === void 0 || form.setFieldsValue(setValue);
91
- return _context2.abrupt("return", setValue || {});
92
- case 12:
87
+ return _context2.abrupt("return", setValue);
88
+ case 11:
93
89
  case "end":
94
90
  return _context2.stop();
95
91
  }
@@ -35,8 +35,7 @@ var DrawerForm = (function (_ref) {
35
35
  var dialogForm = _ref.dialogForm,
36
36
  _ref$closable = _ref.closable,
37
37
  closable = _ref$closable === void 0 ? true : _ref$closable,
38
- _ref$initialValues = _ref.initialValues,
39
- initialValues = _ref$initialValues === void 0 ? {} : _ref$initialValues,
38
+ initialValues = _ref.initialValues,
40
39
  labelWidth = _ref.labelWidth,
41
40
  onOk = _ref.onOk,
42
41
  onFinish = _ref.onFinish;
@@ -53,14 +52,17 @@ var DrawerForm = (function (_ref) {
53
52
  visible: visible,
54
53
  initialValues: initialValues,
55
54
  dialogForm: currentForm,
56
- params: params
55
+ params: params,
56
+ title: title,
57
+ onCancel: onCancel
57
58
  }),
58
59
  modalVisible = _useModifyProps.modalVisible,
59
60
  modalFormData = _useModifyProps.modalFormData,
60
61
  setModalVisible = _useModifyProps.setModalVisible,
61
62
  initValue = _useModifyProps.initValue,
62
63
  onAfterClose = _useModifyProps.onAfterClose,
63
- formParams = _useModifyProps.formParams;
64
+ formParams = _useModifyProps.formParams,
65
+ modalTitle = _useModifyProps.title;
64
66
  var cancel = function cancel() {
65
67
  onAfterClose();
66
68
  if (onCancel) {
@@ -87,7 +89,7 @@ var DrawerForm = (function (_ref) {
87
89
  return jsxRuntime.jsx(antd.Drawer, _objectSpread(_objectSpread({
88
90
  visible: modalVisible,
89
91
  title: jsxRuntime.jsx(Title.default, {
90
- title: title,
92
+ title: modalTitle,
91
93
  closable: closable,
92
94
  onCancel: cancel
93
95
  })
@@ -31,8 +31,7 @@ var ModalForm = (function (_ref) {
31
31
  request = _ref.request,
32
32
  _afterClose = _ref.afterClose,
33
33
  dialogForm = _ref.dialogForm,
34
- _ref$initialValues = _ref.initialValues,
35
- initialValues = _ref$initialValues === void 0 ? {} : _ref$initialValues,
34
+ initialValues = _ref.initialValues,
36
35
  onFinish = _ref.onFinish,
37
36
  params = _ref.params,
38
37
  onOk = _ref.onOk,
@@ -46,7 +45,8 @@ var ModalForm = (function (_ref) {
46
45
  initialValues: initialValues,
47
46
  dialogForm: currentForm,
48
47
  params: params,
49
- title: title
48
+ title: title,
49
+ onCancel: onCancel
50
50
  }),
51
51
  modalVisible = _useModifyProps.modalVisible,
52
52
  modalFormData = _useModifyProps.modalFormData,
@@ -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, params, title, }: ModifyPropsModal) => {
3
+ export declare const useModifyProps: ({ visible, configData, initialValues, dialogForm, afterClose, params, title, onCancel }: ModifyPropsModal) => {
4
4
  modalFormData: import("../Form/modal").HItemProps[];
5
5
  modalVisible: boolean | undefined;
6
6
  setModalVisible: import("react").Dispatch<import("react").SetStateAction<boolean | undefined>>;
@@ -24,7 +24,8 @@ var useModifyProps = function useModifyProps(_ref) {
24
24
  dialogForm = _ref.dialogForm,
25
25
  afterClose = _ref.afterClose,
26
26
  params = _ref.params,
27
- title = _ref.title;
27
+ title = _ref.title,
28
+ onCancel = _ref.onCancel;
28
29
  var _useState = React.useState(visible),
29
30
  _useState2 = _slicedToArray(_useState, 2),
30
31
  modalVisible = _useState2[0],
@@ -46,6 +47,7 @@ var useModifyProps = function useModifyProps(_ref) {
46
47
  modalTitle = _useState10[0],
47
48
  setModalTitle = _useState10[1];
48
49
  var onAfterClose = function onAfterClose() {
50
+ onCancel === null || onCancel === void 0 || onCancel();
49
51
  setTimeout(function () {
50
52
  dialogForm.clear();
51
53
  afterClose === null || afterClose === void 0 || afterClose();
@@ -63,6 +65,9 @@ var useModifyProps = function useModifyProps(_ref) {
63
65
  React.useEffect(function () {
64
66
  setModalTitle(title);
65
67
  }, [title]);
68
+ React.useEffect(function () {
69
+ setInitValue(initialValues);
70
+ }, [initialValues]);
66
71
  React.useEffect(function () {
67
72
  dialogForm.show = function () {
68
73
  var showParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -10,6 +10,7 @@ export interface ModifyPropsModal<P = any> {
10
10
  afterClose?: VoidFunction;
11
11
  params?: P;
12
12
  title?: DialogFormProps["title"];
13
+ onCancel?: VoidFunction;
13
14
  }
14
15
  export interface ShowParamsModal<P = any, T = any> {
15
16
  configData?: HItemProps[];
@@ -9,7 +9,7 @@ export declare const useCurrentForm: (form?: HFormInstance) => HFormInstance;
9
9
  type ParamsModal = Omit<HFormProps, "configData">;
10
10
  export declare const useInfoReq: ({ initialValues, infoRequest, form, params, request, onFinish, }: ParamsModal) => {
11
11
  subControl: import("@ahooksjs/use-request/lib/types").BaseResult<void, [value: any]>;
12
- infoControl: import("@ahooksjs/use-request/lib/types").BaseResult<import("rc-field-form/lib/interface").Store, [reqParams?: any]>;
12
+ infoControl: import("@ahooksjs/use-request/lib/types").BaseResult<any, [reqParams?: any]>;
13
13
  };
14
14
  export declare const useDefaultComponents: () => any;
15
15
  export declare const useValuesChange: ({ onValuesChange, dispatch, form, }: UseValuesChangeModal) => (changedValues: any, values: any) => void;
@@ -64,33 +64,29 @@ var useInfoReq = function useInfoReq(_ref) {
64
64
  });
65
65
  var infoControl = ahooks.useRequest( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
66
66
  var reqParams,
67
+ result,
67
68
  setValue,
68
69
  _args2 = arguments;
69
70
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
70
71
  while (1) switch (_context2.prev = _context2.next) {
71
72
  case 0:
72
73
  reqParams = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : reqData.params;
73
- setValue = initialValues;
74
74
  reqData.params = reqParams;
75
- if (!(!initialValues && !infoRequest)) {
76
- _context2.next = 6;
77
- break;
78
- }
79
- form === null || form === void 0 || form.setFieldsValue({});
80
- return _context2.abrupt("return", {});
81
- case 6:
82
75
  if (!infoRequest) {
83
- _context2.next = 10;
76
+ _context2.next = 8;
84
77
  break;
85
78
  }
86
- _context2.next = 9;
79
+ _context2.next = 5;
87
80
  return infoRequest(reqParams);
88
- case 9:
89
- setValue = _context2.sent;
90
- case 10:
81
+ case 5:
82
+ result = _context2.sent;
83
+ form === null || form === void 0 || form.setFieldsValue(result);
84
+ return _context2.abrupt("return", result || {});
85
+ case 8:
86
+ setValue = initialValues || {};
91
87
  form === null || form === void 0 || form.setFieldsValue(setValue);
92
- return _context2.abrupt("return", setValue || {});
93
- case 12:
88
+ return _context2.abrupt("return", setValue);
89
+ case 11:
94
90
  case "end":
95
91
  return _context2.stop();
96
92
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hw-component/form",
3
- "version": "0.0.6-beta-v7",
3
+ "version": "0.0.6-beta-v9",
4
4
  "description": "基于antd二次开发",
5
5
  "repository": {
6
6
  "type": "git",
@@ -15,7 +15,7 @@ export default ({
15
15
  afterClose,
16
16
  dialogForm,
17
17
  closable = true,
18
- initialValues = {},
18
+ initialValues,
19
19
  labelWidth,
20
20
  onOk,
21
21
  onFinish,
@@ -35,12 +35,15 @@ export default ({
35
35
  initValue,
36
36
  onAfterClose,
37
37
  formParams,
38
+ title:modalTitle
38
39
  } = useModifyProps({
39
40
  configData,
40
41
  visible,
41
42
  initialValues,
42
43
  dialogForm: currentForm,
43
44
  params,
45
+ title,
46
+ onCancel
44
47
  });
45
48
  const cancel = () => {
46
49
  onAfterClose();
@@ -67,7 +70,7 @@ export default ({
67
70
  return (
68
71
  <Drawer
69
72
  visible={modalVisible}
70
- title={<Title title={title} closable={closable} onCancel={cancel} />}
73
+ title={<Title title={modalTitle} closable={closable} onCancel={cancel} />}
71
74
  {...props}
72
75
  onClose={cancel}
73
76
  closable={false}
@@ -12,7 +12,7 @@ export default ({
12
12
  request,
13
13
  afterClose,
14
14
  dialogForm,
15
- initialValues = {},
15
+ initialValues,
16
16
  onFinish,
17
17
  params,
18
18
  onOk,
@@ -35,6 +35,7 @@ export default ({
35
35
  dialogForm: currentForm,
36
36
  params,
37
37
  title,
38
+ onCancel
38
39
  });
39
40
  const cancel = () => {
40
41
  if (onCancel) {
@@ -15,6 +15,7 @@ export const useModifyProps = ({
15
15
  afterClose,
16
16
  params,
17
17
  title,
18
+ onCancel
18
19
  }: ModifyPropsModal) => {
19
20
  const [modalVisible, setModalVisible] = useState(visible);
20
21
  const [modalFormData, setModalFormData] = useState(configData);
@@ -22,6 +23,7 @@ export const useModifyProps = ({
22
23
  const [formParams, setFormParams] = useState(params);
23
24
  const [modalTitle, setModalTitle] = useState(title);
24
25
  const onAfterClose = () => {
26
+ onCancel?.();
25
27
  setTimeout(() => {
26
28
  dialogForm.clear();
27
29
  afterClose?.();
@@ -41,6 +43,9 @@ export const useModifyProps = ({
41
43
  useEffect(() => {
42
44
  setModalTitle(title);
43
45
  }, [title]);
46
+ useEffect(() => {
47
+ setInitValue(initialValues);
48
+ }, [initialValues]);
44
49
  useEffect(() => {
45
50
  dialogForm.show = (showParams = {}) => {
46
51
  const {
@@ -12,6 +12,7 @@ export interface ModifyPropsModal<P = any> {
12
12
  afterClose?: VoidFunction;
13
13
  params?: P;
14
14
  title?: DialogFormProps["title"];
15
+ onCancel?: VoidFunction;
15
16
  }
16
17
  export interface ShowParamsModal<P = any, T = any> {
17
18
  configData?: HItemProps[];
@@ -44,17 +44,15 @@ export const useInfoReq = ({
44
44
  { manual: true }
45
45
  );
46
46
  const infoControl = useRequest(async (reqParams = reqData.params) => {
47
- let setValue = initialValues;
48
47
  reqData.params = reqParams;
49
- if (!initialValues && !infoRequest) {
50
- form?.setFieldsValue({});
51
- return {};
52
- }
53
48
  if (infoRequest) {
54
- setValue = await infoRequest(reqParams);
49
+ const result = await infoRequest(reqParams);
50
+ form?.setFieldsValue(result);
51
+ return result || {};
55
52
  }
53
+ const setValue = initialValues||{};
56
54
  form?.setFieldsValue(setValue);
57
- return setValue || {};
55
+ return setValue;
58
56
  });
59
57
  const { run, mutate } = infoControl;
60
58
  useEffect(() => {
@@ -1,5 +1,7 @@
1
1
  import { Button } from "antd";
2
2
  import { HModalForm, useHDialogForm ,HFormConfigProvider} from "../../components";
3
+ import {useState} from "react";
4
+ import {ShowParamsModal} from "@/components/DialogForm/modal";
3
5
  const data = [
4
6
  {
5
7
  label: "输入框",
@@ -118,6 +120,8 @@ const data = [
118
120
  let num = 0;
119
121
  export default () => {
120
122
  const modalForm = useHDialogForm();
123
+ const [testModal,setTestModal]=useState<ShowParamsModal>({});
124
+ const {visible,params}=testModal;
121
125
  return (
122
126
  <>
123
127
  <Button