@hw-component/form 0.0.4-beta-v3 → 0.0.4-beta-v5

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.
@@ -41,13 +41,15 @@ var ModalForm = (function (_ref) {
41
41
  visible: visible,
42
42
  initialValues: initialValues,
43
43
  dialogForm: currentForm,
44
- params: params
44
+ params: params,
45
+ title: title
45
46
  }),
46
47
  modalVisible = _useModifyProps.modalVisible,
47
48
  modalFormData = _useModifyProps.modalFormData,
48
49
  setModalVisible = _useModifyProps.setModalVisible,
49
50
  initValue = _useModifyProps.initValue,
50
- formParams = _useModifyProps.formParams;
51
+ formParams = _useModifyProps.formParams,
52
+ modalTitle = _useModifyProps.title;
51
53
  var cancel = function cancel() {
52
54
  if (onCancel) {
53
55
  return onCancel === null || onCancel === void 0 ? void 0 : onCancel();
@@ -61,7 +63,7 @@ var ModalForm = (function (_ref) {
61
63
  loading = _useSub.loading,
62
64
  run = _useSub.run;
63
65
  return jsx(Modal, _objectSpread(_objectSpread({
64
- title: title,
66
+ title: modalTitle,
65
67
  visible: modalVisible,
66
68
  onCancel: cancel,
67
69
  confirmLoading: loading,
@@ -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;
@@ -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: import("react").ForwardRefExoticComponent<import("@/components/Form/modal").HFormItemProps & import("react").RefAttributes<any>>;
8
+ declare const _default: import("react").ForwardRefExoticComponent<import("../Form/modal").HFormItemProps & import("react").RefAttributes<any>>;
9
9
  export default _default;
@@ -10,7 +10,7 @@ export declare const useOptionReq: ({ manual, request, options, serviceSearch, s
10
10
  data: OptionType[] | undefined;
11
11
  onSearch: ((value: string) => void) | undefined;
12
12
  mathShowSearch: boolean | undefined;
13
- reload: ({ options: changeOpts, params: requestParams }: ParamsModal) => void | Promise<OptionType[] | undefined>;
13
+ reload: ({ options: changeOpts, params: requestParams, }: ParamsModal) => void | Promise<OptionType[] | undefined>;
14
14
  };
15
15
  export declare const useFilterOption: ({ filterOption, serviceSearch, }: PartialHSelectProps) => boolean | import("rc-select/lib/Select").FilterFunc<import("rc-select/lib/Select").DefaultOptionType> | undefined;
16
16
  export {};
@@ -5,6 +5,7 @@ import _regeneratorRuntime from '@babel/runtime-corejs3/regenerator';
5
5
  import _Promise from '@babel/runtime-corejs3/core-js/promise';
6
6
  import { useState, useEffect } from 'react';
7
7
  import { useRequest } from 'ahooks';
8
+ import { useFormContext } from '../../Form/Context/index.js';
8
9
 
9
10
  var useOptionReq = function useOptionReq(_ref) {
10
11
  var manual = _ref.manual,
@@ -13,6 +14,8 @@ var useOptionReq = function useOptionReq(_ref) {
13
14
  serviceSearch = _ref.serviceSearch,
14
15
  showSearch = _ref.showSearch,
15
16
  propsOnSearch = _ref.onSearch;
17
+ var _useFormContext = useFormContext(),
18
+ form = _useFormContext.form;
16
19
  var _useState = useState(),
17
20
  _useState2 = _slicedToArray(_useState, 2),
18
21
  data = _useState2[0],
@@ -20,23 +23,25 @@ var useOptionReq = function useOptionReq(_ref) {
20
23
  var _useRequest = useRequest( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
21
24
  var params,
22
25
  type,
26
+ formData,
23
27
  _args = arguments;
24
28
  return _regeneratorRuntime.wrap(function _callee$(_context) {
25
29
  while (1) switch (_context.prev = _context.next) {
26
30
  case 0:
27
31
  params = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
28
32
  type = _args.length > 1 && _args[1] !== undefined ? _args[1] : "init";
33
+ formData = form === null || form === void 0 ? void 0 : form.getFieldsValue();
29
34
  if (type === "init") {
30
35
  setData(undefined);
31
36
  }
32
37
  if (!request) {
33
- _context.next = 5;
38
+ _context.next = 6;
34
39
  break;
35
40
  }
36
- return _context.abrupt("return", request(params));
37
- case 5:
38
- return _context.abrupt("return", _Promise.resolve(options));
41
+ return _context.abrupt("return", request(params, formData));
39
42
  case 6:
43
+ return _context.abrupt("return", _Promise.resolve(options));
44
+ case 7:
40
45
  case "end":
41
46
  return _context.stop();
42
47
  }
@@ -20,7 +20,7 @@ import Index$2 from './components/AllSelect.js';
20
20
  import { useMatchConfigProps, useChangeOptions } from '../hooks/index.js';
21
21
  import HFormConnect from '../Form/HFormConnect.js';
22
22
 
23
- var _excluded = ["style", "mode", "options", "modeConfig", "value", "onChange", "fieldNames", "request", "manual", "optionLabelProp", "filterProvider", "optionFilterProp", "serviceSearch", "onSearch", "filterOption", "showSearch", "labelInValue", "noMatchItemRender", "allSelect", "addDispatchListener"];
23
+ var _excluded = ["style", "mode", "options", "modeConfig", "value", "onChange", "fieldNames", "request", "manual", "optionLabelProp", "filterProvider", "optionFilterProp", "serviceSearch", "onSearch", "filterOption", "showSearch", "labelInValue", "noMatchItemRender", "allSelect", "addDispatchListener", "addFormat"];
24
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; }
25
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; }
26
26
  var Option = Select.Option;
@@ -51,8 +51,9 @@ var Index = function Index(_ref) {
51
51
  _ref$noMatchItemRende = _ref.noMatchItemRender,
52
52
  noMatchItemRender = _ref$noMatchItemRende === void 0 ? defaultSelectConfig.noMatchItemRender : _ref$noMatchItemRende,
53
53
  allSelect = _ref.allSelect,
54
- addDispatchListener = _ref.addDispatchListener,
55
- props = _objectWithoutProperties(_ref, _excluded);
54
+ addDispatchListener = _ref.addDispatchListener;
55
+ _ref.addFormat;
56
+ var props = _objectWithoutProperties(_ref, _excluded);
56
57
  var _ref2 = (modeConfig === null || modeConfig === void 0 ? void 0 : modeConfig[mode || ""]) || {},
57
58
  icon = _ref2.icon,
58
59
  render = _ref2.render;
@@ -1,7 +1,8 @@
1
1
  import type { SelectProps } from "antd";
2
2
  import type React from "react";
3
3
  import type { PromiseFnResult } from "../modal";
4
- import { argsFn } from "@/components/Form/modal";
4
+ import type { argsFn } from "@/components/Form/modal";
5
+ import type { addFormatItemModal } from "@/components/Form/modal";
5
6
  export type OptionType = Record<string, any>;
6
7
  export type PartialHSelectProps = Partial<HSelectProps>;
7
8
  export type RenderFn = (data: OptionType) => React.ReactNode;
@@ -13,7 +14,7 @@ export interface ModeConfig {
13
14
  multiple?: ModeConfigItem;
14
15
  tags?: ModeConfigItem;
15
16
  }
16
- export interface HSelectProps extends Omit<SelectProps, "options"> {
17
+ export interface HSelectProps extends Omit<SelectProps, "options" | "placeholder"> {
17
18
  style?: React.CSSProperties;
18
19
  request?: PromiseFnResult<any, OptionType[]>;
19
20
  manual?: boolean;
@@ -24,6 +25,8 @@ export interface HSelectProps extends Omit<SelectProps, "options"> {
24
25
  noMatchItemRender?: RenderFn;
25
26
  allSelect?: boolean;
26
27
  addDispatchListener?: (key: string, fn: argsFn) => void;
28
+ addFormat?: (format: Record<string, addFormatItemModal>) => void;
29
+ placeholder?: string;
27
30
  }
28
31
  export interface FilterDataModal {
29
32
  value: any;
package/es/modal.d.ts CHANGED
@@ -2,7 +2,7 @@ export interface ValueCheckMapModal {
2
2
  checked?: any;
3
3
  noChecked?: any;
4
4
  }
5
- export type PromiseFnResult<T = any, R = any> = (params: T) => Promise<R>;
5
+ export type PromiseFnResult<T = any, R = any> = (params: T, formDataValues?: any) => Promise<R>;
6
6
  export interface ValueSwitchMapModal {
7
7
  open?: any;
8
8
  close?: any;
@@ -44,13 +44,15 @@ var ModalForm = (function (_ref) {
44
44
  visible: visible,
45
45
  initialValues: initialValues,
46
46
  dialogForm: currentForm,
47
- params: params
47
+ params: params,
48
+ title: title
48
49
  }),
49
50
  modalVisible = _useModifyProps.modalVisible,
50
51
  modalFormData = _useModifyProps.modalFormData,
51
52
  setModalVisible = _useModifyProps.setModalVisible,
52
53
  initValue = _useModifyProps.initValue,
53
- formParams = _useModifyProps.formParams;
54
+ formParams = _useModifyProps.formParams,
55
+ modalTitle = _useModifyProps.title;
54
56
  var cancel = function cancel() {
55
57
  if (onCancel) {
56
58
  return onCancel === null || onCancel === void 0 ? void 0 : onCancel();
@@ -64,7 +66,7 @@ var ModalForm = (function (_ref) {
64
66
  loading = _useSub.loading,
65
67
  run = _useSub.run;
66
68
  return jsxRuntime.jsx(antd.Modal, _objectSpread(_objectSpread({
67
- title: title,
69
+ title: modalTitle,
68
70
  visible: modalVisible,
69
71
  onCancel: cancel,
70
72
  confirmLoading: loading,
@@ -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;
@@ -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: import("react").ForwardRefExoticComponent<import("@/components/Form/modal").HFormItemProps & import("react").RefAttributes<any>>;
8
+ declare const _default: import("react").ForwardRefExoticComponent<import("../Form/modal").HFormItemProps & import("react").RefAttributes<any>>;
9
9
  export default _default;
@@ -10,7 +10,7 @@ export declare const useOptionReq: ({ manual, request, options, serviceSearch, s
10
10
  data: OptionType[] | undefined;
11
11
  onSearch: ((value: string) => void) | undefined;
12
12
  mathShowSearch: boolean | undefined;
13
- reload: ({ options: changeOpts, params: requestParams }: ParamsModal) => void | Promise<OptionType[] | undefined>;
13
+ reload: ({ options: changeOpts, params: requestParams, }: ParamsModal) => void | Promise<OptionType[] | undefined>;
14
14
  };
15
15
  export declare const useFilterOption: ({ filterOption, serviceSearch, }: PartialHSelectProps) => boolean | import("rc-select/lib/Select").FilterFunc<import("rc-select/lib/Select").DefaultOptionType> | undefined;
16
16
  export {};
@@ -6,6 +6,7 @@ var _regeneratorRuntime = require('@babel/runtime-corejs3/regenerator');
6
6
  var _Promise = require('@babel/runtime-corejs3/core-js/promise');
7
7
  var React = require('react');
8
8
  var ahooks = require('ahooks');
9
+ var index = require('../../Form/Context/index.js');
9
10
 
10
11
  var useOptionReq = function useOptionReq(_ref) {
11
12
  var manual = _ref.manual,
@@ -14,6 +15,8 @@ var useOptionReq = function useOptionReq(_ref) {
14
15
  serviceSearch = _ref.serviceSearch,
15
16
  showSearch = _ref.showSearch,
16
17
  propsOnSearch = _ref.onSearch;
18
+ var _useFormContext = index.useFormContext(),
19
+ form = _useFormContext.form;
17
20
  var _useState = React.useState(),
18
21
  _useState2 = _slicedToArray(_useState, 2),
19
22
  data = _useState2[0],
@@ -21,23 +24,25 @@ var useOptionReq = function useOptionReq(_ref) {
21
24
  var _useRequest = ahooks.useRequest( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
22
25
  var params,
23
26
  type,
27
+ formData,
24
28
  _args = arguments;
25
29
  return _regeneratorRuntime.wrap(function _callee$(_context) {
26
30
  while (1) switch (_context.prev = _context.next) {
27
31
  case 0:
28
32
  params = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
29
33
  type = _args.length > 1 && _args[1] !== undefined ? _args[1] : "init";
34
+ formData = form === null || form === void 0 ? void 0 : form.getFieldsValue();
30
35
  if (type === "init") {
31
36
  setData(undefined);
32
37
  }
33
38
  if (!request) {
34
- _context.next = 5;
39
+ _context.next = 6;
35
40
  break;
36
41
  }
37
- return _context.abrupt("return", request(params));
38
- case 5:
39
- return _context.abrupt("return", _Promise.resolve(options));
42
+ return _context.abrupt("return", request(params, formData));
40
43
  case 6:
44
+ return _context.abrupt("return", _Promise.resolve(options));
45
+ case 7:
41
46
  case "end":
42
47
  return _context.stop();
43
48
  }
@@ -23,7 +23,7 @@ var AllSelect = require('./components/AllSelect.js');
23
23
  var index = require('../hooks/index.js');
24
24
  var HFormConnect = require('../Form/HFormConnect.js');
25
25
 
26
- var _excluded = ["style", "mode", "options", "modeConfig", "value", "onChange", "fieldNames", "request", "manual", "optionLabelProp", "filterProvider", "optionFilterProp", "serviceSearch", "onSearch", "filterOption", "showSearch", "labelInValue", "noMatchItemRender", "allSelect", "addDispatchListener"];
26
+ var _excluded = ["style", "mode", "options", "modeConfig", "value", "onChange", "fieldNames", "request", "manual", "optionLabelProp", "filterProvider", "optionFilterProp", "serviceSearch", "onSearch", "filterOption", "showSearch", "labelInValue", "noMatchItemRender", "allSelect", "addDispatchListener", "addFormat"];
27
27
  function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
28
28
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
29
29
  var Option = antd.Select.Option;
@@ -54,8 +54,9 @@ var Index = function Index(_ref) {
54
54
  _ref$noMatchItemRende = _ref.noMatchItemRender,
55
55
  noMatchItemRender = _ref$noMatchItemRende === void 0 ? defaultConfig.defaultSelectConfig.noMatchItemRender : _ref$noMatchItemRende,
56
56
  allSelect = _ref.allSelect,
57
- addDispatchListener = _ref.addDispatchListener,
58
- props = _objectWithoutProperties(_ref, _excluded);
57
+ addDispatchListener = _ref.addDispatchListener;
58
+ _ref.addFormat;
59
+ var props = _objectWithoutProperties(_ref, _excluded);
59
60
  var _ref2 = (modeConfig === null || modeConfig === void 0 ? void 0 : modeConfig[mode || ""]) || {},
60
61
  icon = _ref2.icon,
61
62
  render = _ref2.render;
@@ -1,7 +1,8 @@
1
1
  import type { SelectProps } from "antd";
2
2
  import type React from "react";
3
3
  import type { PromiseFnResult } from "../modal";
4
- import { argsFn } from "@/components/Form/modal";
4
+ import type { argsFn } from "@/components/Form/modal";
5
+ import type { addFormatItemModal } from "@/components/Form/modal";
5
6
  export type OptionType = Record<string, any>;
6
7
  export type PartialHSelectProps = Partial<HSelectProps>;
7
8
  export type RenderFn = (data: OptionType) => React.ReactNode;
@@ -13,7 +14,7 @@ export interface ModeConfig {
13
14
  multiple?: ModeConfigItem;
14
15
  tags?: ModeConfigItem;
15
16
  }
16
- export interface HSelectProps extends Omit<SelectProps, "options"> {
17
+ export interface HSelectProps extends Omit<SelectProps, "options" | "placeholder"> {
17
18
  style?: React.CSSProperties;
18
19
  request?: PromiseFnResult<any, OptionType[]>;
19
20
  manual?: boolean;
@@ -24,6 +25,8 @@ export interface HSelectProps extends Omit<SelectProps, "options"> {
24
25
  noMatchItemRender?: RenderFn;
25
26
  allSelect?: boolean;
26
27
  addDispatchListener?: (key: string, fn: argsFn) => void;
28
+ addFormat?: (format: Record<string, addFormatItemModal>) => void;
29
+ placeholder?: string;
27
30
  }
28
31
  export interface FilterDataModal {
29
32
  value: any;
package/lib/modal.d.ts CHANGED
@@ -2,7 +2,7 @@ export interface ValueCheckMapModal {
2
2
  checked?: any;
3
3
  noChecked?: any;
4
4
  }
5
- export type PromiseFnResult<T = any, R = any> = (params: T) => Promise<R>;
5
+ export type PromiseFnResult<T = any, R = any> = (params: T, formDataValues?: any) => Promise<R>;
6
6
  export interface ValueSwitchMapModal {
7
7
  open?: any;
8
8
  close?: any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hw-component/form",
3
- "version": "0.0.4-beta-v3",
3
+ "version": "0.0.4-beta-v5",
4
4
  "description": "基于antd二次开发",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,12 +25,14 @@ export default ({
25
25
  setModalVisible,
26
26
  initValue,
27
27
  formParams,
28
+ title: modalTitle,
28
29
  } = useModifyProps({
29
30
  configData,
30
31
  visible,
31
32
  initialValues,
32
33
  dialogForm: currentForm,
33
34
  params,
35
+ title,
34
36
  });
35
37
  const cancel = () => {
36
38
  if (onCancel) {
@@ -41,7 +43,7 @@ export default ({
41
43
  const { loading, run } = useSub({ request, onFinish });
42
44
  return (
43
45
  <Modal
44
- title={title}
46
+ title={modalTitle}
45
47
  visible={modalVisible}
46
48
  onCancel={cancel}
47
49
  confirmLoading={loading}
@@ -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 {
@@ -3,7 +3,6 @@ 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";
7
6
  export enum SelectInputType {
8
7
  input,
9
8
  select,
@@ -4,10 +4,11 @@ import type {
4
4
  PartialHSelectProps,
5
5
  } from "@/components/Select/modal";
6
6
  import { useRequest } from "ahooks";
7
+ import { useFormContext } from "../../Form/Context";
7
8
 
8
- interface ParamsModal{
9
+ interface ParamsModal {
9
10
  options?: OptionType[];
10
- params?:any;
11
+ params?: any;
11
12
  }
12
13
  export const useOptionReq = ({
13
14
  manual,
@@ -17,14 +18,16 @@ export const useOptionReq = ({
17
18
  showSearch,
18
19
  onSearch: propsOnSearch,
19
20
  }: PartialHSelectProps) => {
21
+ const { form } = useFormContext();
20
22
  const [data, setData] = useState<OptionType[] | undefined>();
21
23
  const { run, loading, error } = useRequest(
22
24
  async (params = {}, type = "init") => {
25
+ const formData = form?.getFieldsValue();
23
26
  if (type === "init") {
24
27
  setData(undefined);
25
28
  }
26
29
  if (request) {
27
- return request(params);
30
+ return request(params, formData);
28
31
  }
29
32
  return Promise.resolve(options);
30
33
  },
@@ -36,12 +39,15 @@ export const useOptionReq = ({
36
39
  },
37
40
  }
38
41
  );
39
- const reload=({options:changeOpts,params:requestParams}:ParamsModal)=>{
40
- if (changeOpts){
41
- return setData(changeOpts);
42
- };
43
- return run(requestParams);
44
- }
42
+ const reload = ({
43
+ options: changeOpts,
44
+ params: requestParams,
45
+ }: ParamsModal) => {
46
+ if (changeOpts) {
47
+ return setData(changeOpts);
48
+ }
49
+ return run(requestParams);
50
+ };
45
51
  const onSearch = (inputValue: string) => {
46
52
  if (!serviceSearch) {
47
53
  propsOnSearch?.(inputValue);
@@ -62,7 +68,7 @@ export const useOptionReq = ({
62
68
  data,
63
69
  onSearch: mathShowSearch ? onSearch : propsOnSearch,
64
70
  mathShowSearch: showSearch || serviceSearch,
65
- reload
71
+ reload,
66
72
  };
67
73
  };
68
74
 
@@ -30,7 +30,8 @@ const Index: React.FC<HSelectProps> = ({
30
30
  labelInValue,
31
31
  noMatchItemRender = defaultSelectConfig.noMatchItemRender,
32
32
  allSelect,
33
- addDispatchListener,
33
+ addDispatchListener,
34
+ addFormat,
34
35
  ...props
35
36
  }) => {
36
37
  const { icon, render } = modeConfig?.[mode || ""] || {};
@@ -44,7 +45,7 @@ const Index: React.FC<HSelectProps> = ({
44
45
  error,
45
46
  onSearch,
46
47
  mathShowSearch,
47
- reload
48
+ reload,
48
49
  } = useOptionReq({
49
50
  options,
50
51
  manual,
@@ -65,7 +66,7 @@ const Index: React.FC<HSelectProps> = ({
65
66
  noMatchItemRender,
66
67
  fieldNames,
67
68
  });
68
- addDispatchListener?.("reload",reload);
69
+ addDispatchListener?.("reload", reload);
69
70
  return (
70
71
  <Select
71
72
  style={style}
@@ -1,7 +1,8 @@
1
1
  import type { SelectProps } from "antd";
2
2
  import type React from "react";
3
3
  import type { PromiseFnResult } from "../modal";
4
- import {argsFn} from "@/components/Form/modal";
4
+ import type { argsFn } from "@/components/Form/modal";
5
+ import type { addFormatItemModal } from "@/components/Form/modal";
5
6
  export type OptionType = Record<string, any>;
6
7
  export type PartialHSelectProps = Partial<HSelectProps>;
7
8
  export type RenderFn = (data: OptionType) => React.ReactNode;
@@ -14,7 +15,8 @@ export interface ModeConfig {
14
15
  multiple?: ModeConfigItem;
15
16
  tags?: ModeConfigItem;
16
17
  }
17
- export interface HSelectProps extends Omit<SelectProps, "options"> {
18
+ export interface HSelectProps
19
+ extends Omit<SelectProps, "options" | "placeholder"> {
18
20
  style?: React.CSSProperties;
19
21
  request?: PromiseFnResult<any, OptionType[]>;
20
22
  manual?: boolean;
@@ -25,6 +27,8 @@ export interface HSelectProps extends Omit<SelectProps, "options"> {
25
27
  noMatchItemRender?: RenderFn; //没有数据
26
28
  allSelect?: boolean; //显示全选
27
29
  addDispatchListener?: (key: string, fn: argsFn) => void;
30
+ addFormat?: (format: Record<string, addFormatItemModal>) => void;
31
+ placeholder?: string;
28
32
  }
29
33
  export interface FilterDataModal {
30
34
  value: any;
@@ -2,7 +2,10 @@ export interface ValueCheckMapModal {
2
2
  checked?: any;
3
3
  noChecked?: any;
4
4
  }
5
- export type PromiseFnResult<T = any, R = any> = (params: T) => Promise<R>;
5
+ export type PromiseFnResult<T = any, R = any> = (
6
+ params: T,
7
+ formDataValues?: any
8
+ ) => Promise<R>;
6
9
  export interface ValueSwitchMapModal {
7
10
  open?: any;
8
11
  close?: any;
@@ -25,10 +25,11 @@ const formData = (options) => {
25
25
  name: "select",
26
26
  type: "select",
27
27
  itemProps: {
28
- request: (params={}) => {
29
- const {label="123",value=1}=params;
28
+ request: (params = {}, values) => {
29
+ const { label = "123", value = 1 } = params;
30
30
  return Promise.resolve([{ label, value }]);
31
31
  },
32
+ showSearch: true,
32
33
  },
33
34
  rules: [{ required: true }],
34
35
  },
@@ -175,15 +176,18 @@ export default () => {
175
176
  </HFormConfigProvider>
176
177
  <div
177
178
  onClick={() => {
178
- form.dispatch({
179
- name:"select",
180
- key:"reload"
181
- },{
182
- params:{
183
- label:"更新",
184
- value:2
185
- }
186
- })
179
+ form.dispatch(
180
+ {
181
+ name: "select",
182
+ key: "reload",
183
+ },
184
+ {
185
+ params: {
186
+ label: "更新",
187
+ value: 2,
188
+ },
189
+ }
190
+ );
187
191
  }}
188
192
  >
189
193
  点我
@@ -15,7 +15,6 @@ export default () => {
15
15
  { name: "测试2", value: 20, userId: 112321 },
16
16
  ]}
17
17
  placeholder="多选"
18
- mode={"multiple"}
19
18
  onChange={(val, option) => {
20
19
  console.log(val, option);
21
20
  }}