@hw-component/form 1.9.29 → 1.9.31

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,6 +1,8 @@
1
1
  // welcome to hoo hoo hoo
2
2
  import _defineProperty from '@babel/runtime-corejs3/helpers/defineProperty';
3
3
  import _asyncToGenerator from '@babel/runtime-corejs3/helpers/asyncToGenerator';
4
+ import _objectWithoutProperties from '@babel/runtime-corejs3/helpers/objectWithoutProperties';
5
+ import _typeof from '@babel/runtime-corejs3/helpers/typeof';
4
6
  import _regeneratorRuntime from '@babel/runtime-corejs3/regenerator';
5
7
  import { useRequest } from 'ahooks';
6
8
  import useHForm from './useHForm.js';
@@ -8,6 +10,7 @@ import { useMemo, useEffect } from 'react';
8
10
  import componentConfig from '../config.js';
9
11
  import { useFormConfigContext } from '../Context/FormConfigProvider.js';
10
12
 
13
+ var _excluded = ["request"];
11
14
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
12
15
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
13
16
  var useCurrentForm = function useCurrentForm(form) {
@@ -28,6 +31,22 @@ var useInfoReq = function useInfoReq(_ref) {
28
31
  params: saveParams
29
32
  };
30
33
  }, [params]);
34
+ var _useMemo = useMemo(function () {
35
+ if (_typeof(infoRequest) === "object") {
36
+ var infoReq = infoRequest.request,
37
+ op = _objectWithoutProperties(infoRequest, _excluded);
38
+ return {
39
+ infoReq: infoReq,
40
+ options: op
41
+ };
42
+ }
43
+ return {
44
+ infoReq: infoRequest,
45
+ options: {}
46
+ };
47
+ }, [infoRequest]),
48
+ initReq = _useMemo.infoReq,
49
+ options = _useMemo.options;
31
50
  var subControl = useRequest(/*#__PURE__*/function () {
32
51
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(value) {
33
52
  var subVal;
@@ -64,12 +83,12 @@ var useInfoReq = function useInfoReq(_ref) {
64
83
  case 0:
65
84
  reqParams = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : reqData.params;
66
85
  reqData.params = reqParams;
67
- if (!infoRequest) {
86
+ if (!initReq) {
68
87
  _context2.next = 8;
69
88
  break;
70
89
  }
71
90
  _context2.next = 5;
72
- return infoRequest(reqParams);
91
+ return initReq(reqParams);
73
92
  case 5:
74
93
  result = _context2.sent;
75
94
  form === null || form === void 0 || form.setFieldsValue(result);
@@ -88,7 +107,7 @@ var useInfoReq = function useInfoReq(_ref) {
88
107
  return _context2.stop();
89
108
  }
90
109
  }, _callee2);
91
- })));
110
+ })), options);
92
111
  var run = infoControl.run,
93
112
  mutate = infoControl.mutate;
94
113
  useEffect(function () {
@@ -17,6 +17,7 @@ import type { DataFnProvider } from "../modal";
17
17
  import type { ColProps } from "antd/lib/grid/col";
18
18
  import type { Gutter } from "antd/lib/grid/row";
19
19
  import type { IUrlUploadProps } from "../Upload/modal";
20
+ import { BaseOptions } from "@ahooksjs/use-request/lib/types";
20
21
  type RenderFun = (props: HItemProps, node: React.ReactNode, form: FormInstance) => React.ReactNode;
21
22
  export type ItemPropsType = HCheckboxProps | HInputProps | HSelectInputProps | HButtonProps | HRadioGroupProps | HSelectProps | ButtonProps | HSwitchProps | HDatePickerProps | HRangePickerProps | HTimePickerProps | TextAreaProps | IUpLoadProps | CascaderProps<any> | IUrlUploadProps;
22
23
  export interface HoverModal {
@@ -53,11 +54,14 @@ export interface HItemProps extends Omit<FormItemProps, "name" | "labelAlign" |
53
54
  hidden?: boolean | HideModal;
54
55
  rowWrapper?: boolean;
55
56
  }
57
+ interface InfoRequestOp extends BaseOptions<any, any> {
58
+ request: PromiseFnResult;
59
+ }
56
60
  export interface HFormProps<T = any, R = any> extends Omit<FormProps, "form" | "onFinish" | "labelAlign"> {
57
61
  configData: HItemProps[];
58
62
  labelWidth?: number;
59
63
  request?: (values: T, params?: any) => Promise<R>;
60
- infoRequest?: PromiseFnResult;
64
+ infoRequest?: PromiseFnResult | InfoRequestOp;
61
65
  valueType?: string;
62
66
  form?: HFormInstance;
63
67
  params?: any;
@@ -34,31 +34,14 @@ var _opMk = function opMk(_ref) {
34
34
  }, children, newChild));
35
35
  });
36
36
  };
37
- var useGetOnlyCheckChild = function useGetOnlyCheckChild(_ref3) {
38
- var onlyCheckChild = _ref3.onlyCheckChild,
37
+ var HTreeSelect = (function (_ref3) {
38
+ var request = _ref3.request,
39
+ onlyCheckChild = _ref3.onlyCheckChild,
40
+ multiple = _ref3.multiple,
39
41
  treeCheckable = _ref3.treeCheckable,
40
- multiple = _ref3.multiple;
41
- if (typeof onlyCheckChild !== "undefined") {
42
- return onlyCheckChild;
43
- }
44
- if (!treeCheckable && !multiple) {
45
- return true;
46
- }
47
- return false;
48
- };
49
- var HTreeSelect = (function (_ref4) {
50
- var request = _ref4.request,
51
- onlyCheckChild = _ref4.onlyCheckChild,
52
- multiple = _ref4.multiple,
53
- treeCheckable = _ref4.treeCheckable,
54
- treeData = _ref4.treeData,
55
- fieldNames = _ref4.fieldNames,
56
- props = _objectWithoutProperties(_ref4, _excluded);
57
- var cuOnlyCheckChild = useGetOnlyCheckChild({
58
- onlyCheckChild: onlyCheckChild,
59
- treeCheckable: treeCheckable,
60
- multiple: multiple
61
- });
42
+ treeData = _ref3.treeData,
43
+ fieldNames = _ref3.fieldNames,
44
+ props = _objectWithoutProperties(_ref3, _excluded);
62
45
  var _useRequest = useRequest(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
63
46
  var options;
64
47
  return _regeneratorRuntime.wrap(function _callee$(_context) {
@@ -76,7 +59,7 @@ var HTreeSelect = (function (_ref4) {
76
59
  case 5:
77
60
  return _context.abrupt("return", _opMk({
78
61
  options: options,
79
- onlyCheckChild: cuOnlyCheckChild,
62
+ onlyCheckChild: onlyCheckChild,
80
63
  fieldNames: fieldNames
81
64
  }));
82
65
  case 6:
@@ -2,6 +2,8 @@
2
2
 
3
3
  var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
4
4
  var _asyncToGenerator = require('@babel/runtime-corejs3/helpers/asyncToGenerator');
5
+ var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWithoutProperties');
6
+ var _typeof = require('@babel/runtime-corejs3/helpers/typeof');
5
7
  var _regeneratorRuntime = require('@babel/runtime-corejs3/regenerator');
6
8
  var ahooks = require('ahooks');
7
9
  var useHForm = require('./useHForm.js');
@@ -9,6 +11,7 @@ var React = require('react');
9
11
  var config = require('../config.js');
10
12
  var FormConfigProvider = require('../Context/FormConfigProvider.js');
11
13
 
14
+ var _excluded = ["request"];
12
15
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
13
16
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
14
17
  var useCurrentForm = function useCurrentForm(form) {
@@ -29,6 +32,22 @@ var useInfoReq = function useInfoReq(_ref) {
29
32
  params: saveParams
30
33
  };
31
34
  }, [params]);
35
+ var _useMemo = React.useMemo(function () {
36
+ if (_typeof(infoRequest) === "object") {
37
+ var infoReq = infoRequest.request,
38
+ op = _objectWithoutProperties(infoRequest, _excluded);
39
+ return {
40
+ infoReq: infoReq,
41
+ options: op
42
+ };
43
+ }
44
+ return {
45
+ infoReq: infoRequest,
46
+ options: {}
47
+ };
48
+ }, [infoRequest]),
49
+ initReq = _useMemo.infoReq,
50
+ options = _useMemo.options;
32
51
  var subControl = ahooks.useRequest(/*#__PURE__*/function () {
33
52
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(value) {
34
53
  var subVal;
@@ -65,12 +84,12 @@ var useInfoReq = function useInfoReq(_ref) {
65
84
  case 0:
66
85
  reqParams = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : reqData.params;
67
86
  reqData.params = reqParams;
68
- if (!infoRequest) {
87
+ if (!initReq) {
69
88
  _context2.next = 8;
70
89
  break;
71
90
  }
72
91
  _context2.next = 5;
73
- return infoRequest(reqParams);
92
+ return initReq(reqParams);
74
93
  case 5:
75
94
  result = _context2.sent;
76
95
  form === null || form === void 0 || form.setFieldsValue(result);
@@ -89,7 +108,7 @@ var useInfoReq = function useInfoReq(_ref) {
89
108
  return _context2.stop();
90
109
  }
91
110
  }, _callee2);
92
- })));
111
+ })), options);
93
112
  var run = infoControl.run,
94
113
  mutate = infoControl.mutate;
95
114
  React.useEffect(function () {
@@ -17,6 +17,7 @@ import type { DataFnProvider } from "../modal";
17
17
  import type { ColProps } from "antd/lib/grid/col";
18
18
  import type { Gutter } from "antd/lib/grid/row";
19
19
  import type { IUrlUploadProps } from "../Upload/modal";
20
+ import { BaseOptions } from "@ahooksjs/use-request/lib/types";
20
21
  type RenderFun = (props: HItemProps, node: React.ReactNode, form: FormInstance) => React.ReactNode;
21
22
  export type ItemPropsType = HCheckboxProps | HInputProps | HSelectInputProps | HButtonProps | HRadioGroupProps | HSelectProps | ButtonProps | HSwitchProps | HDatePickerProps | HRangePickerProps | HTimePickerProps | TextAreaProps | IUpLoadProps | CascaderProps<any> | IUrlUploadProps;
22
23
  export interface HoverModal {
@@ -53,11 +54,14 @@ export interface HItemProps extends Omit<FormItemProps, "name" | "labelAlign" |
53
54
  hidden?: boolean | HideModal;
54
55
  rowWrapper?: boolean;
55
56
  }
57
+ interface InfoRequestOp extends BaseOptions<any, any> {
58
+ request: PromiseFnResult;
59
+ }
56
60
  export interface HFormProps<T = any, R = any> extends Omit<FormProps, "form" | "onFinish" | "labelAlign"> {
57
61
  configData: HItemProps[];
58
62
  labelWidth?: number;
59
63
  request?: (values: T, params?: any) => Promise<R>;
60
- infoRequest?: PromiseFnResult;
64
+ infoRequest?: PromiseFnResult | InfoRequestOp;
61
65
  valueType?: string;
62
66
  form?: HFormInstance;
63
67
  params?: any;
@@ -37,31 +37,14 @@ var _opMk = function opMk(_ref) {
37
37
  }, children, newChild));
38
38
  });
39
39
  };
40
- var useGetOnlyCheckChild = function useGetOnlyCheckChild(_ref3) {
41
- var onlyCheckChild = _ref3.onlyCheckChild,
40
+ var HTreeSelect = (function (_ref3) {
41
+ var request = _ref3.request,
42
+ onlyCheckChild = _ref3.onlyCheckChild,
43
+ multiple = _ref3.multiple,
42
44
  treeCheckable = _ref3.treeCheckable,
43
- multiple = _ref3.multiple;
44
- if (typeof onlyCheckChild !== "undefined") {
45
- return onlyCheckChild;
46
- }
47
- if (!treeCheckable && !multiple) {
48
- return true;
49
- }
50
- return false;
51
- };
52
- var HTreeSelect = (function (_ref4) {
53
- var request = _ref4.request,
54
- onlyCheckChild = _ref4.onlyCheckChild,
55
- multiple = _ref4.multiple,
56
- treeCheckable = _ref4.treeCheckable,
57
- treeData = _ref4.treeData,
58
- fieldNames = _ref4.fieldNames,
59
- props = _objectWithoutProperties(_ref4, _excluded);
60
- var cuOnlyCheckChild = useGetOnlyCheckChild({
61
- onlyCheckChild: onlyCheckChild,
62
- treeCheckable: treeCheckable,
63
- multiple: multiple
64
- });
45
+ treeData = _ref3.treeData,
46
+ fieldNames = _ref3.fieldNames,
47
+ props = _objectWithoutProperties(_ref3, _excluded);
65
48
  var _useRequest = ahooks.useRequest(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
66
49
  var options;
67
50
  return _regeneratorRuntime.wrap(function _callee$(_context) {
@@ -79,7 +62,7 @@ var HTreeSelect = (function (_ref4) {
79
62
  case 5:
80
63
  return _context.abrupt("return", _opMk({
81
64
  options: options,
82
- onlyCheckChild: cuOnlyCheckChild,
65
+ onlyCheckChild: onlyCheckChild,
83
66
  fieldNames: fieldNames
84
67
  }));
85
68
  case 6:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hw-component/form",
3
- "version": "1.9.29",
3
+ "version": "1.9.31",
4
4
  "description": "基于antd二次开发",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,6 +33,19 @@ export const useInfoReq = ({
33
33
  params: saveParams,
34
34
  };
35
35
  }, [params]);
36
+ const {infoReq:initReq,options}=useMemo(()=>{
37
+ if (typeof infoRequest==="object"){
38
+ const {request:infoReq,...op}=infoRequest;
39
+ return {
40
+ infoReq,
41
+ options:op
42
+ }
43
+ }
44
+ return {
45
+ infoReq:infoRequest,
46
+ options:{}
47
+ };
48
+ },[infoRequest]);
36
49
 
37
50
  const subControl = useRequest(
38
51
  async (value) => {
@@ -46,8 +59,8 @@ export const useInfoReq = ({
46
59
  );
47
60
  const infoControl = useRequest(async (reqParams = reqData.params) => {
48
61
  reqData.params = reqParams;
49
- if (infoRequest) {
50
- const result = await infoRequest(reqParams);
62
+ if (initReq) {
63
+ const result = await initReq(reqParams);
51
64
  form?.setFieldsValue(result);
52
65
  return result || {};
53
66
  }
@@ -56,7 +69,7 @@ export const useInfoReq = ({
56
69
  }
57
70
  form?.setFieldsValue(initialValues);
58
71
  return initialValues;
59
- });
72
+ },options);
60
73
  const { run, mutate } = infoControl;
61
74
  useEffect(() => {
62
75
  if (form) {
@@ -36,6 +36,7 @@ import type { ColProps } from "antd/lib/grid/col";
36
36
  import type { Gutter } from "antd/lib/grid/row";
37
37
  import type { IUrlUploadProps } from "../Upload/modal";
38
38
  import { NamePath } from "rc-field-form/es/interface";
39
+ import {BaseOptions} from "@ahooksjs/use-request/lib/types";
39
40
 
40
41
  type RenderFun = (
41
42
  props: HItemProps,
@@ -100,12 +101,15 @@ export interface HItemProps
100
101
  hidden?: boolean | HideModal;
101
102
  rowWrapper?: boolean;
102
103
  }
104
+ interface InfoRequestOp extends BaseOptions<any,any> {
105
+ request:PromiseFnResult;
106
+ }
103
107
  export interface HFormProps<T = any, R = any>
104
108
  extends Omit<FormProps, "form" | "onFinish" | "labelAlign"> {
105
109
  configData: HItemProps[];
106
110
  labelWidth?: number;
107
111
  request?: (values: T, params?: any) => Promise<R>;
108
- infoRequest?: PromiseFnResult;
112
+ infoRequest?: PromiseFnResult|InfoRequestOp;
109
113
  valueType?: string;
110
114
  form?: HFormInstance;
111
115
  params?: any;
@@ -29,21 +29,7 @@ const opMk=({options,onlyCheckChild=false,fieldNames}:OpMkParamsModal)=>{
29
29
  }
30
30
  })
31
31
  }
32
- const useGetOnlyCheckChild=({onlyCheckChild,treeCheckable,multiple}:IProps)=>{
33
- if (typeof onlyCheckChild!=="undefined"){
34
- return onlyCheckChild;
35
- }
36
- if (!treeCheckable&&!multiple){
37
- return true
38
- }
39
- return false;
40
- }
41
32
  export default ({ request,onlyCheckChild,multiple,treeCheckable,treeData,fieldNames, ...props }: IProps) => {
42
- const cuOnlyCheckChild=useGetOnlyCheckChild({
43
- onlyCheckChild,
44
- treeCheckable,
45
- multiple
46
- })
47
33
  const { loading, data } = useRequest(async () => {
48
34
  let options=treeData;
49
35
  if (request) {
@@ -51,7 +37,7 @@ export default ({ request,onlyCheckChild,multiple,treeCheckable,treeData,fieldNa
51
37
  }
52
38
  return opMk({
53
39
  options,
54
- onlyCheckChild:cuOnlyCheckChild,
40
+ onlyCheckChild:onlyCheckChild,
55
41
  fieldNames
56
42
  });
57
43
  });