@hw-component/form 0.0.1-beta-v6 → 0.0.1-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.
Files changed (72) hide show
  1. package/es/CheckboxGroup/index.d.ts +1 -1
  2. package/es/DiaLogForm/DrawerForm/Footer.d.ts +4 -0
  3. package/es/DiaLogForm/DrawerForm/Footer.js +23 -0
  4. package/es/DiaLogForm/DrawerForm/Title.d.ts +4 -0
  5. package/es/DiaLogForm/DrawerForm/Title.js +18 -0
  6. package/es/DiaLogForm/DrawerForm/index.d.ts +4 -0
  7. package/es/DiaLogForm/DrawerForm/index.js +111 -0
  8. package/es/DiaLogForm/ModalForm.d.ts +4 -0
  9. package/es/{ModalForm/index.js → DiaLogForm/ModalForm.js} +36 -6
  10. package/es/{ModalForm → DiaLogForm}/hooks.d.ts +5 -2
  11. package/es/{ModalForm → DiaLogForm}/hooks.js +52 -7
  12. package/es/{ModalForm → DiaLogForm}/modal.d.ts +4 -1
  13. package/es/Form/HFormConnect.d.ts +1 -2
  14. package/es/Form/HFormConnect.js +8 -15
  15. package/es/Form/config.d.ts +4 -4
  16. package/es/Form/config.js +4 -4
  17. package/es/Form/modal.d.ts +7 -1
  18. package/es/Input/SelectInput.d.ts +1 -1
  19. package/es/TDPicker/RangePicker.d.ts +1 -1
  20. package/es/Upload/UrlUpload/index.d.ts +2 -2
  21. package/es/Upload/UrlUpload/index.js +3 -3
  22. package/es/Upload/index.d.ts +1 -2
  23. package/es/Upload/index.js +39 -5
  24. package/es/Upload/modal.d.ts +2 -0
  25. package/es/index.d.ts +7 -6
  26. package/es/index.js +5 -3
  27. package/lib/CheckboxGroup/index.d.ts +1 -1
  28. package/lib/DiaLogForm/DrawerForm/Footer.d.ts +4 -0
  29. package/lib/DiaLogForm/DrawerForm/Footer.js +26 -0
  30. package/lib/DiaLogForm/DrawerForm/Title.d.ts +4 -0
  31. package/lib/DiaLogForm/DrawerForm/Title.js +21 -0
  32. package/lib/DiaLogForm/DrawerForm/index.d.ts +4 -0
  33. package/lib/DiaLogForm/DrawerForm/index.js +114 -0
  34. package/lib/DiaLogForm/ModalForm.d.ts +4 -0
  35. package/lib/{ModalForm/index.js → DiaLogForm/ModalForm.js} +35 -5
  36. package/lib/{ModalForm → DiaLogForm}/hooks.d.ts +5 -2
  37. package/lib/{ModalForm → DiaLogForm}/hooks.js +52 -6
  38. package/lib/{ModalForm → DiaLogForm}/modal.d.ts +4 -1
  39. package/lib/Form/HFormConnect.d.ts +1 -2
  40. package/lib/Form/HFormConnect.js +8 -15
  41. package/lib/Form/config.d.ts +4 -4
  42. package/lib/Form/modal.d.ts +7 -1
  43. package/lib/Input/SelectInput.d.ts +1 -1
  44. package/lib/TDPicker/RangePicker.d.ts +1 -1
  45. package/lib/Upload/UrlUpload/index.d.ts +2 -2
  46. package/lib/Upload/UrlUpload/index.js +3 -3
  47. package/lib/Upload/index.d.ts +1 -2
  48. package/lib/Upload/index.js +39 -5
  49. package/lib/Upload/modal.d.ts +2 -0
  50. package/lib/index.d.ts +7 -6
  51. package/lib/index.js +6 -3
  52. package/package.json +1 -1
  53. package/src/components/DiaLogForm/DrawerForm/Footer.tsx +19 -0
  54. package/src/components/DiaLogForm/DrawerForm/Title.tsx +12 -0
  55. package/src/components/DiaLogForm/DrawerForm/index.tsx +85 -0
  56. package/src/components/{ModalForm/index.tsx → DiaLogForm/ModalForm.tsx} +10 -2
  57. package/src/components/{ModalForm → DiaLogForm}/hooks.ts +27 -2
  58. package/src/components/{ModalForm → DiaLogForm}/modal.ts +4 -1
  59. package/src/components/Form/HFormConnect.tsx +21 -7
  60. package/src/components/Form/config.ts +2 -2
  61. package/src/components/Form/modal.ts +7 -1
  62. package/src/components/Input/SelectInput.tsx +1 -0
  63. package/src/components/TDPicker/modal.ts +0 -1
  64. package/src/components/Upload/UrlUpload/index.tsx +2 -2
  65. package/src/components/Upload/index.tsx +39 -7
  66. package/src/components/Upload/modal.ts +2 -0
  67. package/src/components/index.tsx +5 -4
  68. package/src/pages/DrawerForm/index.tsx +127 -0
  69. package/src/pages/Form/index.tsx +3 -0
  70. package/src/routes.tsx +7 -0
  71. package/es/ModalForm/index.d.ts +0 -4
  72. package/lib/ModalForm/index.d.ts +0 -4
@@ -6,21 +6,21 @@ export declare const placeholderConfig: {
6
6
  declare const _default: {
7
7
  select: ({ style, mode, options, modeConfig, value, onChange, fieldNames: propsFieldNames, request, manual, optionLabelProp, filterProvider, optionFilterProp, serviceSearch, onSearch: propsOnSearch, filterOption, showSearch, labelInValue, noMatchItemRender, allSelect, ...props }: import("../Select/modal").HSelectProps) => JSX.Element;
8
8
  inputNumber: ({ style, ...props }: import("antd").InputNumberProps<string | number>) => JSX.Element;
9
- selectInput: (props: import("./modal").HFormItemProps) => import("react").ReactElement<import("./modal").ConnectResultProps, string | import("react").JSXElementConstructor<any>>;
9
+ selectInput: import("react").ForwardRefExoticComponent<import("./modal").HFormItemProps & import("react").RefAttributes<unknown>>;
10
10
  buttonInput: import("react").FC<import("../Input/modal").HButtonInputProps>;
11
- checkboxGroup: (props: import("./modal").HFormItemProps) => import("react").ReactElement<import("./modal").ConnectResultProps, string | import("react").JSXElementConstructor<any>>;
11
+ checkboxGroup: import("react").ForwardRefExoticComponent<import("./modal").HFormItemProps & import("react").RefAttributes<unknown>>;
12
12
  checkBox: import("react").FC<import("../CheckboxGroup/modal").HCheckboxProps>;
13
13
  radioGroup: ({ value, options, onChange, fieldNames: propsFieldNames, ...props }: import("../RadioGroup").HRadioGroupProps) => JSX.Element;
14
14
  switch: import("react").FC<import("../Switch").HSwitchProps>;
15
15
  datePicker: ({ value, onChange, showTime, format, ...props }: import("../TDPicker/modal").HDatePickerProps) => JSX.Element;
16
16
  rangePicker: {
17
- Component: (props: import("./modal").HFormItemProps) => import("react").ReactElement<import("./modal").ConnectResultProps, string | import("react").JSXElementConstructor<any>>;
17
+ Component: import("react").ForwardRefExoticComponent<import("./modal").HFormItemProps & import("react").RefAttributes<unknown>>;
18
18
  placeholder: ({ label }: import("./modal").HItemProps) => string[];
19
19
  requiredErrMsg: ({ label }: import("./modal").HItemProps) => string;
20
20
  };
21
21
  timePicker: ({ value, format, onChange, ...props }: import("../TDPicker/modal").HTimePickerProps) => JSX.Element;
22
22
  input: ({ ...props }: import("antd").InputProps) => JSX.Element;
23
- upload: import("react").ForwardRefExoticComponent<import("../Upload/modal").IUpLoadProps & import("react").RefAttributes<import("../Upload/modal").IUploadRefModal>>;
23
+ upload: import("react").ForwardRefExoticComponent<import("./modal").HFormItemProps & import("react").RefAttributes<unknown>>;
24
24
  urlUpload: ({ placeholder, value, onChange, mediaType, ...props }: import("../Upload/modal").IUrlUploadProps) => JSX.Element;
25
25
  submit: ({ text, type, form, loading, ...props }: import("../Submit").ISubmitProps) => JSX.Element;
26
26
  formConfigProvider: import("react").FC<import("./modal").IFormConfigContextProps>;
@@ -12,6 +12,7 @@ import type { IUpLoadProps } from "@/components/Upload/modal";
12
12
  import type { SelectProps } from "antd";
13
13
  import type { RangePickerProps } from "antd/es/date-picker";
14
14
  import type { PromiseFnResult, ValueCheckMapModal, ValueSwitchMapModal, DateRangePickerValueMapModal } from "../modal";
15
+ import type { ForwardedRef } from "react";
15
16
  type RenderFun = (props: HItemProps, node: React.ReactNode, form: FormInstance) => void;
16
17
  type ItemPropsType = HCheckboxProps | HInputProps | HSelectInputProps | HButtonProps | HRadioGroupProps | HSelectProps | ButtonProps | HSwitchProps | HDatePickerProps | HRangePickerProps | HTimePickerProps | TextAreaProps | IUpLoadProps;
17
18
  export interface HoverModal {
@@ -42,6 +43,8 @@ export interface HFormProps<T = any, R = any> extends Omit<FormProps, "form"> {
42
43
  }
43
44
  export interface HFormItemProps extends HItemProps {
44
45
  required?: boolean;
46
+ value?: any;
47
+ onChange?: (val: any, item: any) => void;
45
48
  }
46
49
  export interface FormItemWithRender extends Omit<HFormItemProps, "render"> {
47
50
  render: (form: HFormInstance) => React.ReactNode;
@@ -91,8 +94,11 @@ export interface addFormatItemModal {
91
94
  inputValue: addValueFormat;
92
95
  outputValue: addValueFormat;
93
96
  }
94
- export interface ConnectResultProps {
97
+ export interface ConnectResultProps extends HFormItemProps {
95
98
  addFormat?: (format: Record<string, addFormatItemModal>) => void;
96
99
  addDispatchListener?: (key: string, fn: argsFn) => void;
100
+ ref?: ForwardedRef<any>;
101
+ value?: any;
102
+ onChange?: (value: any, item?: any) => void;
97
103
  }
98
104
  export {};
@@ -5,5 +5,5 @@ export declare enum SelectInputType {
5
5
  select = 1
6
6
  }
7
7
  export declare const Index: ({ selectProps, value, onChange, valueName, addFormat, addDispatchListener, ...props }: HSelectInputProps) => JSX.Element;
8
- declare const _default: (props: import("../Form/modal").HFormItemProps) => import("react").ReactElement<import("../Form/modal").ConnectResultProps, string | import("react").JSXElementConstructor<any>>;
8
+ declare const _default: import("react").ForwardRefExoticComponent<import("@/components/Form/modal").HFormItemProps & import("react").RefAttributes<any>>;
9
9
  export default _default;
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import type { HItemProps } from "../Form/modal";
3
3
  declare const _default: {
4
- Component: (props: import("../Form/modal").HFormItemProps) => React.ReactElement<import("../Form/modal").ConnectResultProps, string | React.JSXElementConstructor<any>>;
4
+ Component: React.ForwardRefExoticComponent<import("../Form/modal").HFormItemProps & React.RefAttributes<any>>;
5
5
  placeholder: ({ label }: HItemProps) => string[];
6
6
  requiredErrMsg: ({ label }: HItemProps) => string;
7
7
  };
@@ -1,4 +1,4 @@
1
1
  /// <reference types="react" />
2
2
  import type { IUrlUploadProps } from "../modal";
3
- declare const _default: ({ placeholder, value, onChange, mediaType, ...props }: IUrlUploadProps) => JSX.Element;
4
- export default _default;
3
+ declare const Index: ({ placeholder, value, onChange, mediaType, ...props }: IUrlUploadProps) => JSX.Element;
4
+ export default Index;
@@ -16,7 +16,7 @@ var index = require('../index.js');
16
16
  var TypeEle = require('../MediaTypeEle/TypeEle.js');
17
17
 
18
18
  var _excluded = ["placeholder", "value", "onChange", "mediaType"];
19
- var HUrlUpload = (function (_ref) {
19
+ var Index = function Index(_ref) {
20
20
  var _ref$placeholder = _ref.placeholder,
21
21
  placeholder = _ref$placeholder === void 0 ? "请输入文件地址" : _ref$placeholder,
22
22
  _ref$value = _ref.value,
@@ -116,7 +116,7 @@ var HUrlUpload = (function (_ref) {
116
116
  onReady: onReady,
117
117
  onError: onError
118
118
  })));
119
- });
119
+ };
120
120
 
121
- exports.default = HUrlUpload;
121
+ exports.default = Index;
122
122
  // powered by h
@@ -1,4 +1,3 @@
1
1
  import React from "react";
2
- import type { IUpLoadProps, IUploadRefModal } from "./modal";
3
- declare const _default: React.ForwardRefExoticComponent<IUpLoadProps & React.RefAttributes<IUploadRefModal>>;
2
+ declare const _default: React.ForwardRefExoticComponent<import("../Form/modal").HFormItemProps & React.RefAttributes<any>>;
4
3
  export default _default;
@@ -14,14 +14,16 @@ var _extends = require('@babel/runtime-corejs3/helpers/extends');
14
14
  var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
15
15
  var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
16
16
  var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWithoutProperties');
17
- var antd = require('antd');
18
- var Btn = require('./Btn.js');
17
+ var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/map');
19
18
  var React = require('react');
19
+ var propsMaker = require('./hooks/propsMaker.js');
20
20
  var index = require('./Preview/index.js');
21
21
  var change = require('./hooks/change.js');
22
- var propsMaker = require('./hooks/propsMaker.js');
22
+ var antd = require('antd');
23
+ var Btn = require('./Btn.js');
24
+ var HFormConnect = require('../Form/HFormConnect.js');
23
25
 
24
- var _excluded = ["value", "onChange", "listType", "exFiles", "maxCount", "maxRowNum", "onPreview", "request", "maxSize"];
26
+ var _excluded = ["value", "onChange", "listType", "exFiles", "maxCount", "maxRowNum", "onPreview", "request", "maxSize", "addFormat"];
25
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; }
26
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; }
27
29
  var Index = function Index(_ref, ref) {
@@ -38,6 +40,7 @@ var Index = function Index(_ref, ref) {
38
40
  onPreview = _ref.onPreview,
39
41
  request = _ref.request,
40
42
  maxSize = _ref.maxSize,
43
+ addFormat = _ref.addFormat,
41
44
  props = _objectWithoutProperties(_ref, _excluded);
42
45
  var matchProps = propsMaker.useProps({
43
46
  request: request,
@@ -80,6 +83,37 @@ var Index = function Index(_ref, ref) {
80
83
  var maxNum = maxCount === 1 ? maxCount : Number.MAX_VALUE;
81
84
  var visible = previewModal.visible,
82
85
  previewFile = previewModal.file;
86
+ addFormat === null || addFormat === void 0 ? void 0 : addFormat({
87
+ "float": {
88
+ inputValue: function inputValue(item, initValue) {
89
+ var _item$name = item.name,
90
+ name = _item$name === void 0 ? "" : _item$name;
91
+ var initFileList = initValue[name] || [];
92
+ var fileList = _mapInstanceProperty(initFileList).call(initFileList, function (url, index) {
93
+ return {
94
+ name: url,
95
+ response: {
96
+ url: url
97
+ },
98
+ status: "done",
99
+ uid: "init-".concat(index),
100
+ thumbUrl: url
101
+ };
102
+ });
103
+ return _defineProperty({}, name, fileList);
104
+ },
105
+ outputValue: function outputValue(item, _outputValue) {
106
+ var _item$name2 = item.name,
107
+ valueName = _item$name2 === void 0 ? "" : _item$name2;
108
+ var _outputValue$valueNam = _outputValue[valueName],
109
+ itemVal = _outputValue$valueNam === void 0 ? [] : _outputValue$valueNam;
110
+ var urls = _mapInstanceProperty(itemVal).call(itemVal, function (fileItem) {
111
+ return fileItem.response.url;
112
+ });
113
+ return _defineProperty({}, valueName, urls);
114
+ }
115
+ }
116
+ });
83
117
  return /*#__PURE__*/React.createElement("div", {
84
118
  style: contentStyle
85
119
  }, /*#__PURE__*/React.createElement(antd.Upload, _extends({
@@ -103,7 +137,7 @@ var Index = function Index(_ref, ref) {
103
137
  }
104
138
  }));
105
139
  };
106
- var HUpload = /*#__PURE__*/React.forwardRef(Index);
140
+ var HUpload = HFormConnect.default( /*#__PURE__*/React.forwardRef(Index));
107
141
 
108
142
  exports.default = HUpload;
109
143
  // powered by h
@@ -3,6 +3,7 @@ import type { UploadFile } from "antd/es/upload/interface";
3
3
  import type { BeforeUploadFileType, RcFile } from "rc-upload/lib/interface";
4
4
  import type { UploadChangeParam } from "antd/lib/upload/interface";
5
5
  import type { MediaTypeEnum } from "@/components/Upload/enums";
6
+ import type { addFormatItemModal } from "@/components/Form/modal";
6
7
  export interface IUpLoadProps extends Omit<UploadProps, "onChange"> {
7
8
  exFiles?: string[];
8
9
  request?: (file: Exclude<BeforeUploadFileType, File | boolean> | RcFile) => Promise<{
@@ -13,6 +14,7 @@ export interface IUpLoadProps extends Omit<UploadProps, "onChange"> {
13
14
  value?: UploadFile[];
14
15
  maxRowNum?: number;
15
16
  maxSize?: number;
17
+ addFormat?: (config: Record<string, addFormatItemModal>) => void;
16
18
  }
17
19
  export interface IMediaTypeEleProps {
18
20
  file?: UploadFile;
package/lib/index.d.ts CHANGED
@@ -2,22 +2,23 @@
2
2
  import "./styles/index.less";
3
3
  export { default as HForm } from "./Form";
4
4
  export { default as useHForm } from "./Form/hooks/useHForm";
5
- export { useHModalForm } from "./ModalForm/hooks";
5
+ export { useHModalForm } from "./DiaLogForm/hooks";
6
6
  export declare const HSelect: ({ style, mode, options, modeConfig, value, onChange, fieldNames: propsFieldNames, request, manual, optionLabelProp, filterProvider, optionFilterProp, serviceSearch, onSearch: propsOnSearch, filterOption, showSearch, labelInValue, noMatchItemRender, allSelect, ...props }: import("./Select/modal").HSelectProps) => JSX.Element;
7
7
  export declare const HInput: ({ ...props }: import("antd").InputProps) => JSX.Element;
8
- export declare const HSelectInput: (props: import("./Form/modal").HFormItemProps) => import("react").ReactElement<import("./Form/modal").ConnectResultProps, string | import("react").JSXElementConstructor<any>>;
9
- export declare const HUpload: import("react").ForwardRefExoticComponent<import("./Upload/modal").IUpLoadProps & import("react").RefAttributes<import("./Upload/modal").IUploadRefModal>>;
8
+ export declare const HSelectInput: import("react").ForwardRefExoticComponent<import("./Form/modal").HFormItemProps & import("react").RefAttributes<unknown>>;
9
+ export declare const HUpload: import("react").ForwardRefExoticComponent<import("./Form/modal").HFormItemProps & import("react").RefAttributes<unknown>>;
10
10
  export declare const HUrlUpload: ({ placeholder, value, onChange, mediaType, ...props }: import("./Upload/modal").IUrlUploadProps) => JSX.Element;
11
11
  export declare const HButtonInput: import("react").FC<import("./Input/modal").HButtonInputProps>;
12
12
  export declare const HCheckBox: import("react").FC<import("./CheckboxGroup/modal").HCheckboxProps>;
13
13
  export declare const HSwitch: import("react").FC<import("./Switch").HSwitchProps>;
14
- export declare const HCheckboxGroup: (props: import("./Form/modal").HFormItemProps) => import("react").ReactElement<import("./Form/modal").ConnectResultProps, string | import("react").JSXElementConstructor<any>>;
14
+ export declare const HCheckboxGroup: import("react").ForwardRefExoticComponent<import("./Form/modal").HFormItemProps & import("react").RefAttributes<unknown>>;
15
15
  export declare const HDatePicker: ({ value, onChange, showTime, format, ...props }: import("./TDPicker/modal").HDatePickerProps) => JSX.Element;
16
- export declare const HRangePicker: (props: import("./Form/modal").HFormItemProps) => import("react").ReactElement<import("./Form/modal").ConnectResultProps, string | import("react").JSXElementConstructor<any>>;
16
+ export declare const HRangePicker: import("react").ForwardRefExoticComponent<import("./Form/modal").HFormItemProps & import("react").RefAttributes<unknown>>;
17
17
  export declare const HRadioGroup: ({ value, options, onChange, fieldNames: propsFieldNames, ...props }: import("./RadioGroup").HRadioGroupProps) => JSX.Element;
18
18
  export declare const HTimePicker: ({ value, format, onChange, ...props }: import("./TDPicker/modal").HTimePickerProps) => JSX.Element;
19
19
  export declare const HInputNumber: ({ style, ...props }: import("antd").InputNumberProps<string | number>) => JSX.Element;
20
20
  export declare const HPageHandler: import("react").FC<import("./PageHandler/modal").IHPageHandler<any>>;
21
21
  export declare const HFormConfigProvider: import("react").FC<import("./Form/modal").IFormConfigContextProps>;
22
22
  export declare const HTextArea: ({ autoSize, ...props }: import("antd/es/input").TextAreaProps) => JSX.Element;
23
- export declare const HModalForm: ({ visible, title, onCancel, configData, infoRequest, request, afterClose, modalForm, initialValues, ...props }: import("./ModalForm/modal").ModalFormProps) => JSX.Element;
23
+ export declare const HModalForm: ({ visible, title, onCancel, configData, infoRequest, request, afterClose, modalForm, initialValues, onFinish, ...props }: import("./DiaLogForm/modal").ModalFormProps) => JSX.Element;
24
+ export declare const HDrawerForm: ({ visible, title, onCancel, configData, infoRequest, request, afterClose, modalForm, closable, initialValues, labelWidth, onOk, onFinish, ...props }: import("./DiaLogForm/modal").ModalFormProps) => JSX.Element;
package/lib/index.js CHANGED
@@ -4,8 +4,9 @@ var config = require('./Form/config.js');
4
4
  var index$1 = require('./PageHandler/index.js');
5
5
  var index = require('./Form/index.js');
6
6
  var useHForm = require('./Form/hooks/useHForm.js');
7
- var hooks = require('./ModalForm/hooks.js');
8
- var index$2 = require('./ModalForm/index.js');
7
+ var hooks = require('./DiaLogForm/hooks.js');
8
+ var ModalForm = require('./DiaLogForm/ModalForm.js');
9
+ var index$2 = require('./DiaLogForm/DrawerForm/index.js');
9
10
 
10
11
  var HSelect = config.default.select;
11
12
  var HInput = config.default.input;
@@ -24,7 +25,8 @@ var HInputNumber = config.default.inputNumber;
24
25
  var HPageHandler = index$1.default;
25
26
  var HFormConfigProvider = config.default.formConfigProvider;
26
27
  var HTextArea = config.default.textArea;
27
- var HModalForm = index$2.default;
28
+ var HModalForm = ModalForm.default;
29
+ var HDrawerForm = index$2.default;
28
30
 
29
31
  exports.HForm = index.default;
30
32
  exports.useHForm = useHForm.default;
@@ -33,6 +35,7 @@ exports.HButtonInput = HButtonInput;
33
35
  exports.HCheckBox = HCheckBox;
34
36
  exports.HCheckboxGroup = HCheckboxGroup;
35
37
  exports.HDatePicker = HDatePicker;
38
+ exports.HDrawerForm = HDrawerForm;
36
39
  exports.HFormConfigProvider = HFormConfigProvider;
37
40
  exports.HInput = HInput;
38
41
  exports.HInputNumber = HInputNumber;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hw-component/form",
3
- "version": "0.0.1-beta-v6",
3
+ "version": "0.0.1-beta-v7",
4
4
  "description": "基于antd二次开发",
5
5
  "repository": {
6
6
  "type": "git",
@@ -0,0 +1,19 @@
1
+ import { Row, Space, Button } from "antd";
2
+ import type { ModalFormProps } from "@/components/DiaLogForm/modal";
3
+
4
+ export default ({
5
+ onCancel,
6
+ onOk,
7
+ confirmLoading,
8
+ }: Omit<ModalFormProps, "configData">) => {
9
+ return (
10
+ <Row justify={"end"}>
11
+ <Space size={"middle"}>
12
+ <Button onClick={onCancel}>关闭</Button>
13
+ <Button type={"primary"} onClick={onOk} loading={confirmLoading}>
14
+ 确定
15
+ </Button>
16
+ </Space>
17
+ </Row>
18
+ );
19
+ };
@@ -0,0 +1,12 @@
1
+ import type { ModalProps} from "antd";
2
+ import { Row } from "antd";
3
+ import { CloseOutlined } from "@ant-design/icons";
4
+
5
+ export default ({ title, closable, onCancel }: ModalProps) => {
6
+ return (
7
+ <Row justify={"space-between"}>
8
+ <div>{title}</div>
9
+ {closable && <CloseOutlined onClick={onCancel} />}
10
+ </Row>
11
+ );
12
+ };
@@ -0,0 +1,85 @@
1
+ import { Drawer } from "antd";
2
+ import type { ModalFormProps } from "@/components/DiaLogForm/modal";
3
+ import { useCurrentForm, useModifyProps, useSub } from "../hooks";
4
+ import HForm from "../../Form";
5
+ import Title from "./Title";
6
+ import Footer from "./Footer";
7
+ export default ({
8
+ visible,
9
+ title,
10
+ onCancel,
11
+ configData,
12
+ infoRequest,
13
+ request,
14
+ afterClose,
15
+ modalForm,
16
+ closable = true,
17
+ initialValues = {},
18
+ labelWidth,
19
+ onOk,
20
+ onFinish,
21
+ size,
22
+ form,
23
+ footer,
24
+ ...props
25
+ }: ModalFormProps) => {
26
+ const currentForm = useCurrentForm(modalForm);
27
+ const {
28
+ modalVisible,
29
+ modalFormData,
30
+ setModalVisible,
31
+ initValue,
32
+ onAfterClose,
33
+ } = useModifyProps({
34
+ configData,
35
+ visible,
36
+ initialValues,
37
+ modalForm: currentForm,
38
+ });
39
+ const cancel = (e) => {
40
+ onAfterClose();
41
+ if (onCancel) {
42
+ return onCancel?.(e);
43
+ }
44
+ setModalVisible(false);
45
+ };
46
+ const { loading, run } = useSub({ request, onFinish });
47
+ const footerComponent = () => {
48
+ if (footer === null) {
49
+ return null;
50
+ }
51
+ return (
52
+ footer || (
53
+ <Footer
54
+ onCancel={cancel}
55
+ onOk={currentForm.submit}
56
+ confirmLoading={loading}
57
+ />
58
+ )
59
+ );
60
+ };
61
+ return (
62
+ <Drawer
63
+ visible={modalVisible}
64
+ title={<Title title={title} closable={closable} onCancel={cancel} />}
65
+ {...props}
66
+ onClose={cancel}
67
+ closable={false}
68
+ destroyOnClose={true}
69
+ footer={footerComponent()}
70
+ >
71
+ <HForm
72
+ configData={modalFormData}
73
+ initialValues={initValue}
74
+ {...props}
75
+ form={currentForm}
76
+ onFinish={async (values) => {
77
+ await run(values);
78
+ setModalVisible(false);
79
+ }}
80
+ infoRequest={infoRequest}
81
+ labelWidth={labelWidth}
82
+ />
83
+ </Drawer>
84
+ );
85
+ };
@@ -1,7 +1,7 @@
1
1
  import { Modal } from "antd";
2
- import type { ModalFormProps } from "@/components/ModalForm/modal";
2
+ import type { ModalFormProps } from "@/components/DiaLogForm/modal";
3
3
  import HForm from "../Form";
4
- import { useCurrentForm, useModifyProps } from "./hooks";
4
+ import { useCurrentForm, useModifyProps, useSub } from "./hooks";
5
5
  export default ({
6
6
  visible,
7
7
  title,
@@ -12,6 +12,7 @@ export default ({
12
12
  afterClose,
13
13
  modalForm,
14
14
  initialValues = {},
15
+ onFinish,
15
16
  ...props
16
17
  }: ModalFormProps) => {
17
18
  const currentForm = useCurrentForm(modalForm);
@@ -28,21 +29,28 @@ export default ({
28
29
  }
29
30
  setModalVisible(false);
30
31
  };
32
+ const { loading, run } = useSub({ request, onFinish });
31
33
  return (
32
34
  <Modal
33
35
  title={title}
34
36
  visible={modalVisible}
35
37
  onCancel={cancel}
38
+ confirmLoading={loading}
36
39
  afterClose={() => {
37
40
  currentForm.resetFields();
38
41
  afterClose?.();
39
42
  }}
40
43
  {...props}
44
+ onOk={currentForm.submit}
41
45
  destroyOnClose={true}
42
46
  >
43
47
  <HForm
44
48
  configData={modalFormData}
45
49
  initialValues={initValue}
50
+ onFinish={async (values) => {
51
+ await run(values);
52
+ setModalVisible(false);
53
+ }}
46
54
  {...props}
47
55
  form={currentForm}
48
56
  infoRequest={infoRequest}
@@ -3,17 +3,26 @@ import useHForm from "../Form/hooks/useHForm";
3
3
  import type {
4
4
  HModalFormInstance,
5
5
  ModifyPropsModal,
6
- } from "@/components/ModalForm/modal";
6
+ } from "@/components/DiaLogForm/modal";
7
+ import type { ModalFormProps } from "@/components/DiaLogForm/modal";
8
+ import { useRequest } from "ahooks";
7
9
 
8
10
  export const useModifyProps = ({
9
11
  visible,
10
12
  configData,
11
13
  initialValues,
12
14
  modalForm,
15
+ afterClose,
13
16
  }: ModifyPropsModal) => {
14
17
  const [modalVisible, setModalVisible] = useState(visible);
15
18
  const [modalFormData, setModalFormData] = useState(configData);
16
19
  const [initValue, setInitValue] = useState(initialValues);
20
+ const onAfterClose = () => {
21
+ setTimeout(() => {
22
+ modalForm.resetFields();
23
+ afterClose?.();
24
+ }, 0);
25
+ };
17
26
  useEffect(() => {
18
27
  setModalVisible(visible);
19
28
  }, [visible]);
@@ -33,8 +42,9 @@ export const useModifyProps = ({
33
42
  };
34
43
  modalForm.hide = () => {
35
44
  setModalVisible(false);
45
+ onAfterClose();
36
46
  };
37
- }, []);
47
+ }, [afterClose]);
38
48
  return {
39
49
  modalFormData,
40
50
  modalVisible,
@@ -42,6 +52,7 @@ export const useModifyProps = ({
42
52
  setModalFormData,
43
53
  initValue,
44
54
  setInitValue,
55
+ onAfterClose,
45
56
  };
46
57
  };
47
58
  export const useHModalForm = () => {
@@ -59,3 +70,17 @@ export const useCurrentForm = (hModalForm?: HModalFormInstance) => {
59
70
  const defaultHModalForm = useHModalForm();
60
71
  return hModalForm || defaultHModalForm;
61
72
  };
73
+
74
+ export const useSub = ({ request, onFinish }: Partial<ModalFormProps>) => {
75
+ return useRequest(
76
+ async (values) => {
77
+ if (onFinish) {
78
+ return onFinish(values);
79
+ }
80
+ if (request) {
81
+ return request(values);
82
+ }
83
+ },
84
+ { manual: true }
85
+ );
86
+ };
@@ -1,6 +1,7 @@
1
1
  import type { HFormProps } from "@/components/Form/modal";
2
2
  import type { ModalProps } from "antd";
3
3
  import type { HFormInstance, HItemProps } from "@/components/Form/modal";
4
+ import type { PromiseFnResult } from "@/components/modal";
4
5
 
5
6
  type RootProps = HFormProps & ModalProps;
6
7
 
@@ -9,6 +10,7 @@ export interface ModifyPropsModal {
9
10
  visible?: boolean;
10
11
  initialValues?: Record<string, any>;
11
12
  modalForm: HModalFormInstance;
13
+ afterClose?: VoidFunction;
12
14
  }
13
15
  export interface ShowParamsModal {
14
16
  configData?: HItemProps[];
@@ -20,6 +22,7 @@ export interface HModalFormInstance extends HFormInstance {
20
22
  show: (data: ShowParamsModal) => void;
21
23
  hide: VoidFunction;
22
24
  }
23
- export interface ModalFormProps extends RootProps {
25
+ export interface ModalFormProps extends Omit<RootProps, "onFinish"> {
24
26
  modalForm?: HModalFormInstance;
27
+ onFinish?: PromiseFnResult;
25
28
  }
@@ -25,11 +25,17 @@ const formatMaker = (
25
25
  };
26
26
 
27
27
  export default (
28
- Component: React.FunctionComponent | React.ComponentClass,
28
+ component:
29
+ | React.FunctionComponent
30
+ | React.ComponentClass
31
+ | React.ForwardRefRenderFunction<any, any>,
29
32
  config: ConnectConfigModal = {}
30
33
  ) => {
31
34
  const { format = {} } = config;
32
- return (props: HFormItemProps) => {
35
+ const Index: React.ForwardRefRenderFunction<any, HFormItemProps> = (
36
+ props: HFormItemProps,
37
+ ref
38
+ ) => {
33
39
  const { name = "" } = props;
34
40
 
35
41
  const { form, valueType = "float" } = useFormContext();
@@ -44,10 +50,18 @@ export default (
44
50
  const addDispatchListener = (key: string, fn: argsFn) => {
45
51
  form?.addDispatchListener({ key, name }, fn);
46
52
  };
47
- return React.createElement<ConnectResultProps>(Component, {
48
- ...props,
49
- addFormat,
50
- addDispatchListener,
51
- });
53
+ const Component = component as React.ForwardRefRenderFunction<
54
+ any,
55
+ ConnectResultProps
56
+ >;
57
+ return (
58
+ <Component
59
+ {...props}
60
+ addFormat={addFormat}
61
+ addDispatchListener={addDispatchListener}
62
+ ref={ref}
63
+ />
64
+ );
52
65
  };
66
+ return React.forwardRef(Index);
53
67
  };
@@ -14,7 +14,7 @@ import HUpload from "../Upload";
14
14
  import HUrlUpload from "../Upload/UrlUpload";
15
15
  import HSubmit from "../Submit";
16
16
  import FormConfigProvider from "../Form/Context/FormConfigProvider";
17
- import TextArea from '../TextArea'
17
+ import TextArea from "../TextArea";
18
18
  export const placeholderConfig = {
19
19
  inputType: ["input", "inputNumber", "selectInput", "buttonInput"],
20
20
  selectType: ["select", "datePicker", "timePicker"],
@@ -37,5 +37,5 @@ export default {
37
37
  urlUpload: HUrlUpload,
38
38
  submit: HSubmit,
39
39
  formConfigProvider: FormConfigProvider,
40
- textArea:TextArea
40
+ textArea: TextArea,
41
41
  };
@@ -25,6 +25,7 @@ import type {
25
25
  ValueSwitchMapModal,
26
26
  DateRangePickerValueMapModal,
27
27
  } from "../modal";
28
+ import type { ForwardedRef } from "react";
28
29
  type RenderFun = (
29
30
  props: HItemProps,
30
31
  node: React.ReactNode,
@@ -80,6 +81,8 @@ export interface HFormProps<T = any, R = any> extends Omit<FormProps, "form"> {
80
81
 
81
82
  export interface HFormItemProps extends HItemProps {
82
83
  required?: boolean;
84
+ value?: any;
85
+ onChange?: (val: any, item: any) => void;
83
86
  }
84
87
  export interface FormItemWithRender extends Omit<HFormItemProps, "render"> {
85
88
  render: (form: HFormInstance) => React.ReactNode;
@@ -142,7 +145,10 @@ export interface addFormatItemModal {
142
145
  outputValue: addValueFormat;
143
146
  }
144
147
 
145
- export interface ConnectResultProps {
148
+ export interface ConnectResultProps extends HFormItemProps {
146
149
  addFormat?: (format: Record<string, addFormatItemModal>) => void;
147
150
  addDispatchListener?: (key: string, fn: argsFn) => void;
151
+ ref?: ForwardedRef<any>;
152
+ value?: any;
153
+ onChange?: (value: any, item?: any) => void;
148
154
  }
@@ -3,6 +3,7 @@ import type { HSelectInputProps } from "./modal";
3
3
  import HSelect from "../Select";
4
4
  import { defaultSelectStyle, defaultValueName } from "./defaultConfig";
5
5
  import HFormConnect from "../Form/HFormConnect";
6
+ import { ConnectResultProps } from "@/components/Form/modal";
6
7
  export enum SelectInputType {
7
8
  input,
8
9
  select,
@@ -6,7 +6,6 @@ import type { TimePickerProps } from "antd";
6
6
  import type { DurationInputArg2 } from "moment";
7
7
  import type { DateRangePickerValueMapModal } from "../modal";
8
8
  import type { addFormatItemModal } from "@/components/Form/modal";
9
- import type { argsFn } from "@/components/Form/modal";
10
9
  export interface HDatePickerProps
11
10
  extends Omit<DatePickerProps, "onChange" | "format" | "ranges"> {
12
11
  onChange?: (time?: Moment | string | number) => void;