@hw-component/form 0.0.4-beta-v2 → 0.0.4-beta-v4

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.
@@ -1,3 +1,3 @@
1
1
  import type { DialogFormProps } from "../modal";
2
- declare const _default: ({ visible, title, onCancel, configData, infoRequest, request, afterClose, dialogForm, closable, initialValues, labelWidth, onOk, onFinish, size, form, footer, params, ...props }: DialogFormProps) => JSX.Element;
2
+ declare const _default: ({ visible, title, onCancel, configData, infoRequest, request, afterClose, dialogForm, closable, initialValues, labelWidth, onOk, onFinish, size, form, footer, params, onValuesChange, ...props }: DialogFormProps) => JSX.Element;
3
3
  export default _default;
@@ -18,7 +18,7 @@ import HForm from '../../Form/index.js';
18
18
  import Title from './Title.js';
19
19
  import Footer from './Footer.js';
20
20
 
21
- var _excluded = ["visible", "title", "onCancel", "configData", "infoRequest", "request", "afterClose", "dialogForm", "closable", "initialValues", "labelWidth", "onOk", "onFinish", "size", "form", "footer", "params"];
21
+ var _excluded = ["visible", "title", "onCancel", "configData", "infoRequest", "request", "afterClose", "dialogForm", "closable", "initialValues", "labelWidth", "onOk", "onFinish", "size", "form", "footer", "params", "onValuesChange"];
22
22
  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; }
23
23
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context2 = ownKeys(Object(source), !0)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
24
24
  var DrawerForm = (function (_ref) {
@@ -41,6 +41,7 @@ var DrawerForm = (function (_ref) {
41
41
  _ref.form;
42
42
  var footer = _ref.footer,
43
43
  params = _ref.params,
44
+ onValuesChange = _ref.onValuesChange,
44
45
  props = _objectWithoutProperties(_ref, _excluded);
45
46
  var currentForm = useCurrentForm(dialogForm);
46
47
  var _useModifyProps = useModifyProps({
@@ -93,7 +94,8 @@ var DrawerForm = (function (_ref) {
93
94
  footer: footerComponent(),
94
95
  children: jsx(HForm, _objectSpread(_objectSpread({
95
96
  configData: modalFormData,
96
- initialValues: initValue
97
+ initialValues: initValue,
98
+ onValuesChange: onValuesChange
97
99
  }, props), {}, {
98
100
  form: currentForm,
99
101
  params: formParams,
@@ -1,3 +1,3 @@
1
1
  import type { DialogFormProps } from "./modal";
2
- declare const _default: ({ visible, title, onCancel, configData, infoRequest, request, afterClose, dialogForm, initialValues, onFinish, params, onOk, ...props }: DialogFormProps) => JSX.Element;
2
+ declare const _default: ({ visible, title, onCancel, configData, infoRequest, request, afterClose, dialogForm, initialValues, onFinish, params, onOk, onValuesChange, ...props }: DialogFormProps) => JSX.Element;
3
3
  export default _default;
@@ -16,7 +16,7 @@ import { Modal } from 'antd';
16
16
  import HForm from '../Form/index.js';
17
17
  import { useCurrentForm, useModifyProps, useSub } from './hooks.js';
18
18
 
19
- var _excluded = ["visible", "title", "onCancel", "configData", "infoRequest", "request", "afterClose", "dialogForm", "initialValues", "onFinish", "params", "onOk"];
19
+ var _excluded = ["visible", "title", "onCancel", "configData", "infoRequest", "request", "afterClose", "dialogForm", "initialValues", "onFinish", "params", "onOk", "onValuesChange"];
20
20
  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; }
21
21
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context2 = ownKeys(Object(source), !0)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
22
22
  var ModalForm = (function (_ref) {
@@ -33,6 +33,7 @@ var ModalForm = (function (_ref) {
33
33
  onFinish = _ref.onFinish,
34
34
  params = _ref.params,
35
35
  onOk = _ref.onOk,
36
+ onValuesChange = _ref.onValuesChange,
36
37
  props = _objectWithoutProperties(_ref, _excluded);
37
38
  var currentForm = useCurrentForm(dialogForm);
38
39
  var _useModifyProps = useModifyProps({
@@ -40,13 +41,15 @@ var ModalForm = (function (_ref) {
40
41
  visible: visible,
41
42
  initialValues: initialValues,
42
43
  dialogForm: currentForm,
43
- params: params
44
+ params: params,
45
+ title: title
44
46
  }),
45
47
  modalVisible = _useModifyProps.modalVisible,
46
48
  modalFormData = _useModifyProps.modalFormData,
47
49
  setModalVisible = _useModifyProps.setModalVisible,
48
50
  initValue = _useModifyProps.initValue,
49
- formParams = _useModifyProps.formParams;
51
+ formParams = _useModifyProps.formParams,
52
+ modalTitle = _useModifyProps.title;
50
53
  var cancel = function cancel() {
51
54
  if (onCancel) {
52
55
  return onCancel === null || onCancel === void 0 ? void 0 : onCancel();
@@ -60,7 +63,7 @@ var ModalForm = (function (_ref) {
60
63
  loading = _useSub.loading,
61
64
  run = _useSub.run;
62
65
  return jsx(Modal, _objectSpread(_objectSpread({
63
- title: title,
66
+ title: modalTitle,
64
67
  visible: modalVisible,
65
68
  onCancel: cancel,
66
69
  confirmLoading: loading,
@@ -74,6 +77,7 @@ var ModalForm = (function (_ref) {
74
77
  children: jsx(HForm, _objectSpread(_objectSpread({
75
78
  configData: modalFormData,
76
79
  initialValues: initValue,
80
+ onValuesChange: onValuesChange,
77
81
  onFinish: function () {
78
82
  var _onFinish = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(values, outParams) {
79
83
  var result, close;
@@ -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, }: ModifyPropsModal) => {
3
+ export declare const useModifyProps: ({ visible, configData, initialValues, dialogForm, afterClose, params, title }: ModifyPropsModal) => {
4
4
  modalFormData: import("../Form/modal").HItemProps[];
5
5
  modalVisible: boolean | undefined;
6
6
  setModalVisible: import("react").Dispatch<import("react").SetStateAction<boolean | undefined>>;
@@ -9,6 +9,7 @@ export declare const useModifyProps: ({ visible, configData, initialValues, dial
9
9
  setInitValue: import("react").Dispatch<import("react").SetStateAction<Record<string, any> | undefined>>;
10
10
  onAfterClose: () => void;
11
11
  formParams: any;
12
+ title: string | (string & import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>) | (string & import("react").ReactNodeArray) | (string & import("react").ReactPortal) | undefined;
12
13
  };
13
14
  export declare const useHDialogForm: () => HDialogFormInstance<any, any>;
14
15
  export declare const useCurrentForm: (hDialogForm?: HDialogFormInstance) => HDialogFormInstance<any, any>;
@@ -24,7 +24,8 @@ var useModifyProps = function useModifyProps(_ref) {
24
24
  initialValues = _ref.initialValues,
25
25
  dialogForm = _ref.dialogForm,
26
26
  afterClose = _ref.afterClose,
27
- params = _ref.params;
27
+ params = _ref.params,
28
+ title = _ref.title;
28
29
  var _useState = useState(visible),
29
30
  _useState2 = _slicedToArray(_useState, 2),
30
31
  modalVisible = _useState2[0],
@@ -41,6 +42,10 @@ var useModifyProps = function useModifyProps(_ref) {
41
42
  _useState8 = _slicedToArray(_useState7, 2),
42
43
  formParams = _useState8[0],
43
44
  setFormParams = _useState8[1];
45
+ var _useState9 = useState(title),
46
+ _useState10 = _slicedToArray(_useState9, 2),
47
+ modalTitle = _useState10[0],
48
+ setModalTitle = _useState10[1];
44
49
  var onAfterClose = function onAfterClose() {
45
50
  _setTimeout(function () {
46
51
  dialogForm.resetFields();
@@ -56,18 +61,25 @@ var useModifyProps = function useModifyProps(_ref) {
56
61
  useEffect(function () {
57
62
  setFormParams(params);
58
63
  }, [params]);
64
+ useEffect(function () {
65
+ setModalTitle(title);
66
+ }, [title]);
59
67
  useEffect(function () {
60
68
  dialogForm.show = function () {
61
69
  var showParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
62
70
  var changeConfigData = showParams.configData,
63
71
  changeInitialValues = showParams.initialValues,
64
- changeParams = showParams.params;
72
+ changeParams = showParams.params,
73
+ changeTitle = showParams.title;
65
74
  if (!!changeConfigData) {
66
75
  setModalFormData(changeConfigData);
67
76
  }
68
77
  if (!!changeParams) {
69
78
  setFormParams(changeParams);
70
79
  }
80
+ if (!!changeTitle) {
81
+ setModalTitle(changeTitle);
82
+ }
71
83
  setInitValue(changeInitialValues);
72
84
  setModalVisible(true);
73
85
  };
@@ -84,7 +96,8 @@ var useModifyProps = function useModifyProps(_ref) {
84
96
  initValue: initValue,
85
97
  setInitValue: setInitValue,
86
98
  onAfterClose: onAfterClose,
87
- formParams: formParams
99
+ formParams: formParams,
100
+ title: modalTitle
88
101
  };
89
102
  };
90
103
  var useHDialogForm = function useHDialogForm() {
@@ -9,6 +9,7 @@ export interface ModifyPropsModal<P = any> {
9
9
  dialogForm: HDialogFormInstance;
10
10
  afterClose?: VoidFunction;
11
11
  params?: P;
12
+ title?: DialogFormProps["title"];
12
13
  }
13
14
  export interface ShowParamsModal<P = any, T = any> {
14
15
  configData?: HItemProps[];
@@ -16,6 +17,7 @@ export interface ShowParamsModal<P = any, T = any> {
16
17
  initialValues?: Record<string, any>;
17
18
  infoRequest?: PromiseFnResult<P, T>;
18
19
  params?: P;
20
+ title?: DialogFormProps["title"];
19
21
  }
20
22
  export interface HDialogFormInstance<P = any, T = any> extends HFormInstance {
21
23
  show: (data?: ShowParamsModal<P, T>) => void;
@@ -1,4 +1,8 @@
1
1
  import type { OptionType, PartialHSelectProps } from "@/components/Select/modal";
2
+ interface ParamsModal {
3
+ options?: OptionType[];
4
+ params?: any;
5
+ }
2
6
  export declare const useOptionReq: ({ manual, request, options, serviceSearch, showSearch, onSearch: propsOnSearch, }: PartialHSelectProps) => {
3
7
  run: (params?: any, type?: any) => Promise<OptionType[] | undefined>;
4
8
  loading: boolean;
@@ -6,5 +10,7 @@ export declare const useOptionReq: ({ manual, request, options, serviceSearch, s
6
10
  data: OptionType[] | undefined;
7
11
  onSearch: ((value: string) => void) | undefined;
8
12
  mathShowSearch: boolean | undefined;
13
+ reload: ({ options: changeOpts, params: requestParams, }: ParamsModal) => void | Promise<OptionType[] | undefined>;
9
14
  };
10
15
  export declare const useFilterOption: ({ filterOption, serviceSearch, }: PartialHSelectProps) => boolean | import("rc-select/lib/Select").FilterFunc<import("rc-select/lib/Select").DefaultOptionType> | undefined;
16
+ export {};
@@ -51,6 +51,14 @@ var useOptionReq = function useOptionReq(_ref) {
51
51
  run = _useRequest.run,
52
52
  loading = _useRequest.loading,
53
53
  error = _useRequest.error;
54
+ var reload = function reload(_ref3) {
55
+ var changeOpts = _ref3.options,
56
+ requestParams = _ref3.params;
57
+ if (changeOpts) {
58
+ return setData(changeOpts);
59
+ }
60
+ return run(requestParams);
61
+ };
54
62
  var onSearch = function onSearch(inputValue) {
55
63
  if (!serviceSearch) {
56
64
  propsOnSearch === null || propsOnSearch === void 0 ? void 0 : propsOnSearch(inputValue);
@@ -72,12 +80,13 @@ var useOptionReq = function useOptionReq(_ref) {
72
80
  error: error,
73
81
  data: data,
74
82
  onSearch: mathShowSearch ? onSearch : propsOnSearch,
75
- mathShowSearch: showSearch || serviceSearch
83
+ mathShowSearch: showSearch || serviceSearch,
84
+ reload: reload
76
85
  };
77
86
  };
78
- var useFilterOption = function useFilterOption(_ref3) {
79
- var filterOption = _ref3.filterOption,
80
- serviceSearch = _ref3.serviceSearch;
87
+ var useFilterOption = function useFilterOption(_ref4) {
88
+ var filterOption = _ref4.filterOption,
89
+ serviceSearch = _ref4.serviceSearch;
81
90
  if (serviceSearch) {
82
91
  return function () {
83
92
  return true;
@@ -1,3 +1,3 @@
1
- import type { HSelectProps } from "./modal";
2
- declare const _default: ({ style, mode, options, modeConfig, value, onChange, fieldNames: propsFieldNames, request, manual, optionLabelProp, filterProvider, optionFilterProp, serviceSearch, onSearch: propsOnSearch, filterOption, showSearch, labelInValue, noMatchItemRender, allSelect, ...props }: HSelectProps) => JSX.Element;
1
+ import React from "react";
2
+ declare const _default: React.ForwardRefExoticComponent<import("../Form/modal").HFormItemProps & React.RefAttributes<any>>;
3
3
  export default _default;
@@ -15,15 +15,16 @@ import { Select } from 'antd';
15
15
  import { useFilterOption, useOptionReq } from './hooks/norHooks.js';
16
16
  import { useValueChange } from './hooks/changeHooks.js';
17
17
  import { defaultModeConfig, defaultSelectConfig } from './defaultConfig.js';
18
- import Index from './components/DropdownComponent.js';
19
- import Index$1 from './components/AllSelect.js';
18
+ import Index$1 from './components/DropdownComponent.js';
19
+ import Index$2 from './components/AllSelect.js';
20
20
  import { useMatchConfigProps, useChangeOptions } from '../hooks/index.js';
21
+ import HFormConnect from '../Form/HFormConnect.js';
21
22
 
22
- var _excluded = ["style", "mode", "options", "modeConfig", "value", "onChange", "fieldNames", "request", "manual", "optionLabelProp", "filterProvider", "optionFilterProp", "serviceSearch", "onSearch", "filterOption", "showSearch", "labelInValue", "noMatchItemRender", "allSelect"];
23
+ var _excluded = ["style", "mode", "options", "modeConfig", "value", "onChange", "fieldNames", "request", "manual", "optionLabelProp", "filterProvider", "optionFilterProp", "serviceSearch", "onSearch", "filterOption", "showSearch", "labelInValue", "noMatchItemRender", "allSelect", "addDispatchListener"];
23
24
  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; }
24
25
  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; }
25
26
  var Option = Select.Option;
26
- var HSelect = (function (_ref) {
27
+ var Index = function Index(_ref) {
27
28
  var _ref$style = _ref.style,
28
29
  style = _ref$style === void 0 ? {
29
30
  width: "100%"
@@ -50,6 +51,7 @@ var HSelect = (function (_ref) {
50
51
  _ref$noMatchItemRende = _ref.noMatchItemRender,
51
52
  noMatchItemRender = _ref$noMatchItemRende === void 0 ? defaultSelectConfig.noMatchItemRender : _ref$noMatchItemRende,
52
53
  allSelect = _ref.allSelect,
54
+ addDispatchListener = _ref.addDispatchListener,
53
55
  props = _objectWithoutProperties(_ref, _excluded);
54
56
  var _ref2 = (modeConfig === null || modeConfig === void 0 ? void 0 : modeConfig[mode || ""]) || {},
55
57
  icon = _ref2.icon,
@@ -76,7 +78,8 @@ var HSelect = (function (_ref) {
76
78
  resultData = _useOptionReq.data,
77
79
  error = _useOptionReq.error,
78
80
  onSearch = _useOptionReq.onSearch,
79
- mathShowSearch = _useOptionReq.mathShowSearch;
81
+ mathShowSearch = _useOptionReq.mathShowSearch,
82
+ reload = _useOptionReq.reload;
80
83
  var data = useChangeOptions({
81
84
  options: resultData,
82
85
  fieldNames: fieldNames
@@ -92,6 +95,7 @@ var HSelect = (function (_ref) {
92
95
  }),
93
96
  val = _useValueChange.val,
94
97
  change = _useValueChange.change;
98
+ addDispatchListener === null || addDispatchListener === void 0 ? void 0 : addDispatchListener("reload", reload);
95
99
  return jsx(Select, _objectSpread(_objectSpread({
96
100
  style: style,
97
101
  mode: mode,
@@ -100,12 +104,12 @@ var HSelect = (function (_ref) {
100
104
  onSearch: onSearch,
101
105
  onChange: change,
102
106
  dropdownRender: function dropdownRender(node) {
103
- return jsx(Index, {
107
+ return jsx(Index$1, {
104
108
  loading: loading,
105
109
  reload: run,
106
110
  error: error,
107
111
  options: data,
108
- children: jsx(Index$1, {
112
+ children: jsx(Index$2, {
109
113
  allSelect: allSelect,
110
114
  options: data,
111
115
  mode: mode,
@@ -136,7 +140,8 @@ var HSelect = (function (_ref) {
136
140
  }), optionValue);
137
141
  })
138
142
  }));
139
- });
143
+ };
144
+ var HSelect = HFormConnect(Index);
140
145
 
141
146
  export { HSelect as default };
142
147
  // powered by hdj
@@ -1,6 +1,7 @@
1
1
  import type { SelectProps } from "antd";
2
2
  import type React from "react";
3
3
  import type { PromiseFnResult } from "../modal";
4
+ import type { argsFn } from "@/components/Form/modal";
4
5
  export type OptionType = Record<string, any>;
5
6
  export type PartialHSelectProps = Partial<HSelectProps>;
6
7
  export type RenderFn = (data: OptionType) => React.ReactNode;
@@ -22,6 +23,7 @@ export interface HSelectProps extends Omit<SelectProps, "options"> {
22
23
  options?: OptionType[];
23
24
  noMatchItemRender?: RenderFn;
24
25
  allSelect?: boolean;
26
+ addDispatchListener?: (key: string, fn: argsFn) => void;
25
27
  }
26
28
  export interface FilterDataModal {
27
29
  value: any;
@@ -1,3 +1,3 @@
1
1
  import type { DialogFormProps } from "../modal";
2
- declare const _default: ({ visible, title, onCancel, configData, infoRequest, request, afterClose, dialogForm, closable, initialValues, labelWidth, onOk, onFinish, size, form, footer, params, ...props }: DialogFormProps) => JSX.Element;
2
+ declare const _default: ({ visible, title, onCancel, configData, infoRequest, request, afterClose, dialogForm, closable, initialValues, labelWidth, onOk, onFinish, size, form, footer, params, onValuesChange, ...props }: DialogFormProps) => JSX.Element;
3
3
  export default _default;
@@ -21,7 +21,7 @@ var index = require('../../Form/index.js');
21
21
  var Title = require('./Title.js');
22
22
  var Footer = require('./Footer.js');
23
23
 
24
- var _excluded = ["visible", "title", "onCancel", "configData", "infoRequest", "request", "afterClose", "dialogForm", "closable", "initialValues", "labelWidth", "onOk", "onFinish", "size", "form", "footer", "params"];
24
+ var _excluded = ["visible", "title", "onCancel", "configData", "infoRequest", "request", "afterClose", "dialogForm", "closable", "initialValues", "labelWidth", "onOk", "onFinish", "size", "form", "footer", "params", "onValuesChange"];
25
25
  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
26
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context2 = ownKeys(Object(source), !0)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
27
27
  var DrawerForm = (function (_ref) {
@@ -44,6 +44,7 @@ var DrawerForm = (function (_ref) {
44
44
  _ref.form;
45
45
  var footer = _ref.footer,
46
46
  params = _ref.params,
47
+ onValuesChange = _ref.onValuesChange,
47
48
  props = _objectWithoutProperties(_ref, _excluded);
48
49
  var currentForm = hooks.useCurrentForm(dialogForm);
49
50
  var _useModifyProps = hooks.useModifyProps({
@@ -96,7 +97,8 @@ var DrawerForm = (function (_ref) {
96
97
  footer: footerComponent(),
97
98
  children: jsxRuntime.jsx(index.default, _objectSpread(_objectSpread({
98
99
  configData: modalFormData,
99
- initialValues: initValue
100
+ initialValues: initValue,
101
+ onValuesChange: onValuesChange
100
102
  }, props), {}, {
101
103
  form: currentForm,
102
104
  params: formParams,
@@ -1,3 +1,3 @@
1
1
  import type { DialogFormProps } from "./modal";
2
- declare const _default: ({ visible, title, onCancel, configData, infoRequest, request, afterClose, dialogForm, initialValues, onFinish, params, onOk, ...props }: DialogFormProps) => JSX.Element;
2
+ declare const _default: ({ visible, title, onCancel, configData, infoRequest, request, afterClose, dialogForm, initialValues, onFinish, params, onOk, onValuesChange, ...props }: DialogFormProps) => JSX.Element;
3
3
  export default _default;
@@ -19,7 +19,7 @@ var antd = require('antd');
19
19
  var index = require('../Form/index.js');
20
20
  var hooks = require('./hooks.js');
21
21
 
22
- var _excluded = ["visible", "title", "onCancel", "configData", "infoRequest", "request", "afterClose", "dialogForm", "initialValues", "onFinish", "params", "onOk"];
22
+ var _excluded = ["visible", "title", "onCancel", "configData", "infoRequest", "request", "afterClose", "dialogForm", "initialValues", "onFinish", "params", "onOk", "onValuesChange"];
23
23
  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; }
24
24
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context2 = ownKeys(Object(source), !0)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
25
25
  var ModalForm = (function (_ref) {
@@ -36,6 +36,7 @@ var ModalForm = (function (_ref) {
36
36
  onFinish = _ref.onFinish,
37
37
  params = _ref.params,
38
38
  onOk = _ref.onOk,
39
+ onValuesChange = _ref.onValuesChange,
39
40
  props = _objectWithoutProperties(_ref, _excluded);
40
41
  var currentForm = hooks.useCurrentForm(dialogForm);
41
42
  var _useModifyProps = hooks.useModifyProps({
@@ -43,13 +44,15 @@ var ModalForm = (function (_ref) {
43
44
  visible: visible,
44
45
  initialValues: initialValues,
45
46
  dialogForm: currentForm,
46
- params: params
47
+ params: params,
48
+ title: title
47
49
  }),
48
50
  modalVisible = _useModifyProps.modalVisible,
49
51
  modalFormData = _useModifyProps.modalFormData,
50
52
  setModalVisible = _useModifyProps.setModalVisible,
51
53
  initValue = _useModifyProps.initValue,
52
- formParams = _useModifyProps.formParams;
54
+ formParams = _useModifyProps.formParams,
55
+ modalTitle = _useModifyProps.title;
53
56
  var cancel = function cancel() {
54
57
  if (onCancel) {
55
58
  return onCancel === null || onCancel === void 0 ? void 0 : onCancel();
@@ -63,7 +66,7 @@ var ModalForm = (function (_ref) {
63
66
  loading = _useSub.loading,
64
67
  run = _useSub.run;
65
68
  return jsxRuntime.jsx(antd.Modal, _objectSpread(_objectSpread({
66
- title: title,
69
+ title: modalTitle,
67
70
  visible: modalVisible,
68
71
  onCancel: cancel,
69
72
  confirmLoading: loading,
@@ -77,6 +80,7 @@ var ModalForm = (function (_ref) {
77
80
  children: jsxRuntime.jsx(index.default, _objectSpread(_objectSpread({
78
81
  configData: modalFormData,
79
82
  initialValues: initValue,
83
+ onValuesChange: onValuesChange,
80
84
  onFinish: function () {
81
85
  var _onFinish = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(values, outParams) {
82
86
  var result, close;
@@ -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, }: ModifyPropsModal) => {
3
+ export declare const useModifyProps: ({ visible, configData, initialValues, dialogForm, afterClose, params, title }: ModifyPropsModal) => {
4
4
  modalFormData: import("../Form/modal").HItemProps[];
5
5
  modalVisible: boolean | undefined;
6
6
  setModalVisible: import("react").Dispatch<import("react").SetStateAction<boolean | undefined>>;
@@ -9,6 +9,7 @@ export declare const useModifyProps: ({ visible, configData, initialValues, dial
9
9
  setInitValue: import("react").Dispatch<import("react").SetStateAction<Record<string, any> | undefined>>;
10
10
  onAfterClose: () => void;
11
11
  formParams: any;
12
+ title: string | (string & import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>) | (string & import("react").ReactNodeArray) | (string & import("react").ReactPortal) | undefined;
12
13
  };
13
14
  export declare const useHDialogForm: () => HDialogFormInstance<any, any>;
14
15
  export declare const useCurrentForm: (hDialogForm?: HDialogFormInstance) => HDialogFormInstance<any, any>;
@@ -25,7 +25,8 @@ var useModifyProps = function useModifyProps(_ref) {
25
25
  initialValues = _ref.initialValues,
26
26
  dialogForm = _ref.dialogForm,
27
27
  afterClose = _ref.afterClose,
28
- params = _ref.params;
28
+ params = _ref.params,
29
+ title = _ref.title;
29
30
  var _useState = React.useState(visible),
30
31
  _useState2 = _slicedToArray(_useState, 2),
31
32
  modalVisible = _useState2[0],
@@ -42,6 +43,10 @@ var useModifyProps = function useModifyProps(_ref) {
42
43
  _useState8 = _slicedToArray(_useState7, 2),
43
44
  formParams = _useState8[0],
44
45
  setFormParams = _useState8[1];
46
+ var _useState9 = React.useState(title),
47
+ _useState10 = _slicedToArray(_useState9, 2),
48
+ modalTitle = _useState10[0],
49
+ setModalTitle = _useState10[1];
45
50
  var onAfterClose = function onAfterClose() {
46
51
  _setTimeout(function () {
47
52
  dialogForm.resetFields();
@@ -57,18 +62,25 @@ var useModifyProps = function useModifyProps(_ref) {
57
62
  React.useEffect(function () {
58
63
  setFormParams(params);
59
64
  }, [params]);
65
+ React.useEffect(function () {
66
+ setModalTitle(title);
67
+ }, [title]);
60
68
  React.useEffect(function () {
61
69
  dialogForm.show = function () {
62
70
  var showParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
63
71
  var changeConfigData = showParams.configData,
64
72
  changeInitialValues = showParams.initialValues,
65
- changeParams = showParams.params;
73
+ changeParams = showParams.params,
74
+ changeTitle = showParams.title;
66
75
  if (!!changeConfigData) {
67
76
  setModalFormData(changeConfigData);
68
77
  }
69
78
  if (!!changeParams) {
70
79
  setFormParams(changeParams);
71
80
  }
81
+ if (!!changeTitle) {
82
+ setModalTitle(changeTitle);
83
+ }
72
84
  setInitValue(changeInitialValues);
73
85
  setModalVisible(true);
74
86
  };
@@ -85,7 +97,8 @@ var useModifyProps = function useModifyProps(_ref) {
85
97
  initValue: initValue,
86
98
  setInitValue: setInitValue,
87
99
  onAfterClose: onAfterClose,
88
- formParams: formParams
100
+ formParams: formParams,
101
+ title: modalTitle
89
102
  };
90
103
  };
91
104
  var useHDialogForm = function useHDialogForm() {
@@ -9,6 +9,7 @@ export interface ModifyPropsModal<P = any> {
9
9
  dialogForm: HDialogFormInstance;
10
10
  afterClose?: VoidFunction;
11
11
  params?: P;
12
+ title?: DialogFormProps["title"];
12
13
  }
13
14
  export interface ShowParamsModal<P = any, T = any> {
14
15
  configData?: HItemProps[];
@@ -16,6 +17,7 @@ export interface ShowParamsModal<P = any, T = any> {
16
17
  initialValues?: Record<string, any>;
17
18
  infoRequest?: PromiseFnResult<P, T>;
18
19
  params?: P;
20
+ title?: DialogFormProps["title"];
19
21
  }
20
22
  export interface HDialogFormInstance<P = any, T = any> extends HFormInstance {
21
23
  show: (data?: ShowParamsModal<P, T>) => void;
@@ -1,4 +1,8 @@
1
1
  import type { OptionType, PartialHSelectProps } from "@/components/Select/modal";
2
+ interface ParamsModal {
3
+ options?: OptionType[];
4
+ params?: any;
5
+ }
2
6
  export declare const useOptionReq: ({ manual, request, options, serviceSearch, showSearch, onSearch: propsOnSearch, }: PartialHSelectProps) => {
3
7
  run: (params?: any, type?: any) => Promise<OptionType[] | undefined>;
4
8
  loading: boolean;
@@ -6,5 +10,7 @@ export declare const useOptionReq: ({ manual, request, options, serviceSearch, s
6
10
  data: OptionType[] | undefined;
7
11
  onSearch: ((value: string) => void) | undefined;
8
12
  mathShowSearch: boolean | undefined;
13
+ reload: ({ options: changeOpts, params: requestParams, }: ParamsModal) => void | Promise<OptionType[] | undefined>;
9
14
  };
10
15
  export declare const useFilterOption: ({ filterOption, serviceSearch, }: PartialHSelectProps) => boolean | import("rc-select/lib/Select").FilterFunc<import("rc-select/lib/Select").DefaultOptionType> | undefined;
16
+ export {};
@@ -52,6 +52,14 @@ var useOptionReq = function useOptionReq(_ref) {
52
52
  run = _useRequest.run,
53
53
  loading = _useRequest.loading,
54
54
  error = _useRequest.error;
55
+ var reload = function reload(_ref3) {
56
+ var changeOpts = _ref3.options,
57
+ requestParams = _ref3.params;
58
+ if (changeOpts) {
59
+ return setData(changeOpts);
60
+ }
61
+ return run(requestParams);
62
+ };
55
63
  var onSearch = function onSearch(inputValue) {
56
64
  if (!serviceSearch) {
57
65
  propsOnSearch === null || propsOnSearch === void 0 ? void 0 : propsOnSearch(inputValue);
@@ -73,12 +81,13 @@ var useOptionReq = function useOptionReq(_ref) {
73
81
  error: error,
74
82
  data: data,
75
83
  onSearch: mathShowSearch ? onSearch : propsOnSearch,
76
- mathShowSearch: showSearch || serviceSearch
84
+ mathShowSearch: showSearch || serviceSearch,
85
+ reload: reload
77
86
  };
78
87
  };
79
- var useFilterOption = function useFilterOption(_ref3) {
80
- var filterOption = _ref3.filterOption,
81
- serviceSearch = _ref3.serviceSearch;
88
+ var useFilterOption = function useFilterOption(_ref4) {
89
+ var filterOption = _ref4.filterOption,
90
+ serviceSearch = _ref4.serviceSearch;
82
91
  if (serviceSearch) {
83
92
  return function () {
84
93
  return true;
@@ -1,3 +1,3 @@
1
- import type { HSelectProps } from "./modal";
2
- declare const _default: ({ style, mode, options, modeConfig, value, onChange, fieldNames: propsFieldNames, request, manual, optionLabelProp, filterProvider, optionFilterProp, serviceSearch, onSearch: propsOnSearch, filterOption, showSearch, labelInValue, noMatchItemRender, allSelect, ...props }: HSelectProps) => JSX.Element;
1
+ import React from "react";
2
+ declare const _default: React.ForwardRefExoticComponent<import("../Form/modal").HFormItemProps & React.RefAttributes<any>>;
3
3
  export default _default;
@@ -21,12 +21,13 @@ var defaultConfig = require('./defaultConfig.js');
21
21
  var DropdownComponent = require('./components/DropdownComponent.js');
22
22
  var AllSelect = require('./components/AllSelect.js');
23
23
  var index = require('../hooks/index.js');
24
+ var HFormConnect = require('../Form/HFormConnect.js');
24
25
 
25
- var _excluded = ["style", "mode", "options", "modeConfig", "value", "onChange", "fieldNames", "request", "manual", "optionLabelProp", "filterProvider", "optionFilterProp", "serviceSearch", "onSearch", "filterOption", "showSearch", "labelInValue", "noMatchItemRender", "allSelect"];
26
+ var _excluded = ["style", "mode", "options", "modeConfig", "value", "onChange", "fieldNames", "request", "manual", "optionLabelProp", "filterProvider", "optionFilterProp", "serviceSearch", "onSearch", "filterOption", "showSearch", "labelInValue", "noMatchItemRender", "allSelect", "addDispatchListener"];
26
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; }
27
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; }
28
29
  var Option = antd.Select.Option;
29
- var HSelect = (function (_ref) {
30
+ var Index = function Index(_ref) {
30
31
  var _ref$style = _ref.style,
31
32
  style = _ref$style === void 0 ? {
32
33
  width: "100%"
@@ -53,6 +54,7 @@ var HSelect = (function (_ref) {
53
54
  _ref$noMatchItemRende = _ref.noMatchItemRender,
54
55
  noMatchItemRender = _ref$noMatchItemRende === void 0 ? defaultConfig.defaultSelectConfig.noMatchItemRender : _ref$noMatchItemRende,
55
56
  allSelect = _ref.allSelect,
57
+ addDispatchListener = _ref.addDispatchListener,
56
58
  props = _objectWithoutProperties(_ref, _excluded);
57
59
  var _ref2 = (modeConfig === null || modeConfig === void 0 ? void 0 : modeConfig[mode || ""]) || {},
58
60
  icon = _ref2.icon,
@@ -79,7 +81,8 @@ var HSelect = (function (_ref) {
79
81
  resultData = _useOptionReq.data,
80
82
  error = _useOptionReq.error,
81
83
  onSearch = _useOptionReq.onSearch,
82
- mathShowSearch = _useOptionReq.mathShowSearch;
84
+ mathShowSearch = _useOptionReq.mathShowSearch,
85
+ reload = _useOptionReq.reload;
83
86
  var data = index.useChangeOptions({
84
87
  options: resultData,
85
88
  fieldNames: fieldNames
@@ -95,6 +98,7 @@ var HSelect = (function (_ref) {
95
98
  }),
96
99
  val = _useValueChange.val,
97
100
  change = _useValueChange.change;
101
+ addDispatchListener === null || addDispatchListener === void 0 ? void 0 : addDispatchListener("reload", reload);
98
102
  return jsxRuntime.jsx(antd.Select, _objectSpread(_objectSpread({
99
103
  style: style,
100
104
  mode: mode,
@@ -139,7 +143,8 @@ var HSelect = (function (_ref) {
139
143
  }), optionValue);
140
144
  })
141
145
  }));
142
- });
146
+ };
147
+ var HSelect = HFormConnect.default(Index);
143
148
 
144
149
  exports.default = HSelect;
145
150
  // powered by h
@@ -1,6 +1,7 @@
1
1
  import type { SelectProps } from "antd";
2
2
  import type React from "react";
3
3
  import type { PromiseFnResult } from "../modal";
4
+ import type { argsFn } from "@/components/Form/modal";
4
5
  export type OptionType = Record<string, any>;
5
6
  export type PartialHSelectProps = Partial<HSelectProps>;
6
7
  export type RenderFn = (data: OptionType) => React.ReactNode;
@@ -22,6 +23,7 @@ export interface HSelectProps extends Omit<SelectProps, "options"> {
22
23
  options?: OptionType[];
23
24
  noMatchItemRender?: RenderFn;
24
25
  allSelect?: boolean;
26
+ addDispatchListener?: (key: string, fn: argsFn) => void;
25
27
  }
26
28
  export interface FilterDataModal {
27
29
  value: any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hw-component/form",
3
- "version": "0.0.4-beta-v2",
3
+ "version": "0.0.4-beta-v4",
4
4
  "description": "基于antd二次开发",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,6 +22,7 @@ export default ({
22
22
  form,
23
23
  footer,
24
24
  params,
25
+ onValuesChange,
25
26
  ...props
26
27
  }: DialogFormProps) => {
27
28
  const currentForm = useCurrentForm(dialogForm);
@@ -74,6 +75,7 @@ export default ({
74
75
  <HForm
75
76
  configData={modalFormData}
76
77
  initialValues={initValue}
78
+ onValuesChange={onValuesChange}
77
79
  {...props}
78
80
  form={currentForm}
79
81
  params={formParams}
@@ -15,6 +15,7 @@ export default ({
15
15
  onFinish,
16
16
  params,
17
17
  onOk,
18
+ onValuesChange,
18
19
  ...props
19
20
  }: DialogFormProps) => {
20
21
  const currentForm = useCurrentForm(dialogForm);
@@ -24,12 +25,14 @@ export default ({
24
25
  setModalVisible,
25
26
  initValue,
26
27
  formParams,
28
+ title:modalTitle
27
29
  } = useModifyProps({
28
30
  configData,
29
31
  visible,
30
32
  initialValues,
31
33
  dialogForm: currentForm,
32
34
  params,
35
+ title
33
36
  });
34
37
  const cancel = () => {
35
38
  if (onCancel) {
@@ -40,7 +43,7 @@ export default ({
40
43
  const { loading, run } = useSub({ request, onFinish });
41
44
  return (
42
45
  <Modal
43
- title={title}
46
+ title={modalTitle}
44
47
  visible={modalVisible}
45
48
  onCancel={cancel}
46
49
  confirmLoading={loading}
@@ -55,6 +58,7 @@ export default ({
55
58
  <HForm
56
59
  configData={modalFormData}
57
60
  initialValues={initValue}
61
+ onValuesChange={onValuesChange}
58
62
  onFinish={async (values, outParams) => {
59
63
  const result = await run(values, outParams);
60
64
  const close = onOk?.(result, outParams);
@@ -14,11 +14,13 @@ export const useModifyProps = ({
14
14
  dialogForm,
15
15
  afterClose,
16
16
  params,
17
+ title
17
18
  }: ModifyPropsModal) => {
18
19
  const [modalVisible, setModalVisible] = useState(visible);
19
20
  const [modalFormData, setModalFormData] = useState(configData);
20
21
  const [initValue, setInitValue] = useState(initialValues);
21
22
  const [formParams, setFormParams] = useState(params);
23
+ const [modalTitle,setModalTitle]=useState(title)
22
24
  const onAfterClose = () => {
23
25
  setTimeout(() => {
24
26
  dialogForm.resetFields();
@@ -36,13 +38,16 @@ export const useModifyProps = ({
36
38
  useEffect(() => {
37
39
  setFormParams(params);
38
40
  }, [params]);
39
-
41
+ useEffect(() => {
42
+ setModalTitle(title);
43
+ }, [title]);
40
44
  useEffect(() => {
41
45
  dialogForm.show = (showParams = {}) => {
42
46
  const {
43
47
  configData: changeConfigData,
44
48
  initialValues: changeInitialValues,
45
49
  params: changeParams,
50
+ title:changeTitle
46
51
  } = showParams;
47
52
  if (!!changeConfigData) {
48
53
  setModalFormData(changeConfigData);
@@ -50,6 +55,9 @@ export const useModifyProps = ({
50
55
  if (!!changeParams) {
51
56
  setFormParams(changeParams);
52
57
  }
58
+ if (!!changeTitle){
59
+ setModalTitle(changeTitle);
60
+ }
53
61
  setInitValue(changeInitialValues);
54
62
  setModalVisible(true);
55
63
  };
@@ -67,6 +75,7 @@ export const useModifyProps = ({
67
75
  setInitValue,
68
76
  onAfterClose,
69
77
  formParams,
78
+ title:modalTitle
70
79
  };
71
80
  };
72
81
  export const useHDialogForm = () => {
@@ -11,6 +11,7 @@ export interface ModifyPropsModal<P = any> {
11
11
  dialogForm: HDialogFormInstance;
12
12
  afterClose?: VoidFunction;
13
13
  params?: P;
14
+ title?:DialogFormProps["title"];
14
15
  }
15
16
  export interface ShowParamsModal<P = any, T = any> {
16
17
  configData?: HItemProps[];
@@ -18,6 +19,7 @@ export interface ShowParamsModal<P = any, T = any> {
18
19
  initialValues?: Record<string, any>;
19
20
  infoRequest?: PromiseFnResult<P, T>;
20
21
  params?: P;
22
+ title?:DialogFormProps["title"];
21
23
  }
22
24
 
23
25
  export interface HDialogFormInstance<P = any, T = any> extends HFormInstance {
@@ -1,10 +1,14 @@
1
- import {useEffect, useState} from "react";
1
+ import { useEffect, useState } from "react";
2
2
  import type {
3
3
  OptionType,
4
4
  PartialHSelectProps,
5
5
  } from "@/components/Select/modal";
6
6
  import { useRequest } from "ahooks";
7
7
 
8
+ interface ParamsModal {
9
+ options?: OptionType[];
10
+ params?: any;
11
+ }
8
12
  export const useOptionReq = ({
9
13
  manual,
10
14
  request,
@@ -32,6 +36,15 @@ export const useOptionReq = ({
32
36
  },
33
37
  }
34
38
  );
39
+ const reload = ({
40
+ options: changeOpts,
41
+ params: requestParams,
42
+ }: ParamsModal) => {
43
+ if (changeOpts) {
44
+ return setData(changeOpts);
45
+ }
46
+ return run(requestParams);
47
+ };
35
48
  const onSearch = (inputValue: string) => {
36
49
  if (!serviceSearch) {
37
50
  propsOnSearch?.(inputValue);
@@ -39,11 +52,11 @@ export const useOptionReq = ({
39
52
  }
40
53
  run({ inputValue });
41
54
  };
42
- useEffect(()=>{
43
- if (options){
44
- setData(options);
55
+ useEffect(() => {
56
+ if (options) {
57
+ setData(options);
45
58
  }
46
- },[options]);
59
+ }, [options]);
47
60
  const mathShowSearch = showSearch || serviceSearch;
48
61
  return {
49
62
  run,
@@ -52,6 +65,7 @@ export const useOptionReq = ({
52
65
  data,
53
66
  onSearch: mathShowSearch ? onSearch : propsOnSearch,
54
67
  mathShowSearch: showSearch || serviceSearch,
68
+ reload,
55
69
  };
56
70
  };
57
71
 
@@ -7,9 +7,10 @@ import { defaultModeConfig, defaultSelectConfig } from "./defaultConfig";
7
7
  import DropdownComponent from "./components/DropdownComponent";
8
8
  import AllSelect from "./components/AllSelect";
9
9
  import { useChangeOptions, useMatchConfigProps } from "../hooks";
10
+ import HFormConnect from "../Form/HFormConnect";
10
11
  const { Option } = Select;
11
12
 
12
- export default ({
13
+ const Index: React.FC<HSelectProps> = ({
13
14
  style = { width: "100%" },
14
15
  mode,
15
16
  options,
@@ -29,8 +30,9 @@ export default ({
29
30
  labelInValue,
30
31
  noMatchItemRender = defaultSelectConfig.noMatchItemRender,
31
32
  allSelect,
33
+ addDispatchListener,
32
34
  ...props
33
- }: HSelectProps) => {
35
+ }) => {
34
36
  const { icon, render } = modeConfig?.[mode || ""] || {};
35
37
  const { fieldNames } = useMatchConfigProps({ fieldNames: propsFieldNames });
36
38
 
@@ -42,6 +44,7 @@ export default ({
42
44
  error,
43
45
  onSearch,
44
46
  mathShowSearch,
47
+ reload,
45
48
  } = useOptionReq({
46
49
  options,
47
50
  manual,
@@ -62,7 +65,7 @@ export default ({
62
65
  noMatchItemRender,
63
66
  fieldNames,
64
67
  });
65
-
68
+ addDispatchListener?.("reload", reload);
66
69
  return (
67
70
  <Select
68
71
  style={style}
@@ -118,3 +121,4 @@ export default ({
118
121
  </Select>
119
122
  );
120
123
  };
124
+ export default HFormConnect(Index);
@@ -1,6 +1,7 @@
1
1
  import type { SelectProps } from "antd";
2
2
  import type React from "react";
3
3
  import type { PromiseFnResult } from "../modal";
4
+ import type { argsFn } from "@/components/Form/modal";
4
5
  export type OptionType = Record<string, any>;
5
6
  export type PartialHSelectProps = Partial<HSelectProps>;
6
7
  export type RenderFn = (data: OptionType) => React.ReactNode;
@@ -23,6 +24,7 @@ export interface HSelectProps extends Omit<SelectProps, "options"> {
23
24
  options?: OptionType[];
24
25
  noMatchItemRender?: RenderFn; //没有数据
25
26
  allSelect?: boolean; //显示全选
27
+ addDispatchListener?: (key: string, fn: argsFn) => void;
26
28
  }
27
29
  export interface FilterDataModal {
28
30
  value: any;
@@ -1,8 +1,8 @@
1
1
  import { HForm, HFormConfigProvider, useHForm } from "../../components";
2
- import {useState} from "react";
2
+ import { useState } from "react";
3
3
 
4
- const formData=(options)=>{
5
- return [
4
+ const formData = (options) => {
5
+ return [
6
6
  {
7
7
  label: "输入框",
8
8
  name: "name",
@@ -21,13 +21,14 @@ const formData=(options)=>{
21
21
  rules: [{ required: true }],
22
22
  },
23
23
  {
24
- label: "数字",
25
- name: "sz",
24
+ label: "下拉框",
25
+ name: "select",
26
26
  type: "select",
27
27
  itemProps: {
28
- request:()=>{
29
- return Promise.resolve([{label:"123",value:1}])
30
- }
28
+ request: (params = {}) => {
29
+ const { label = "123", value = 1 } = params;
30
+ return Promise.resolve([{ label, value }]);
31
+ },
31
32
  },
32
33
  rules: [{ required: true }],
33
34
  },
@@ -122,13 +123,13 @@ const formData=(options)=>{
122
123
  type: "submit",
123
124
  },
124
125
  ];
125
- }
126
+ };
126
127
  const Test = (props) => {
127
128
  return <div>ffff</div>;
128
129
  };
129
130
  export default () => {
130
131
  const form = useHForm();
131
- const [options,setOptions]=useState([{label:"1",value:1}]);
132
+ const [options, setOptions] = useState([{ label: "1", value: 1 }]);
132
133
 
133
134
  return (
134
135
  <div style={{ overflow: "auto", height: "90vh" }}>
@@ -172,9 +173,24 @@ export default () => {
172
173
  }}
173
174
  />
174
175
  </HFormConfigProvider>
175
- <div onClick={()=>{
176
- setOptions([{label:"2",value: 2}])
177
- }}>点我</div>
176
+ <div
177
+ onClick={() => {
178
+ form.dispatch(
179
+ {
180
+ name: "select",
181
+ key: "reload",
182
+ },
183
+ {
184
+ params: {
185
+ label: "更新",
186
+ value: 2,
187
+ },
188
+ }
189
+ );
190
+ }}
191
+ >
192
+ 点我
193
+ </div>
178
194
  </div>
179
195
  );
180
196
  };