@hw-component/form 0.0.6-beta-v4 → 0.0.6-beta-v6

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.
@@ -16,6 +16,7 @@ import { useCurrentForm, useModifyProps, useSub } from '../hooks.js';
16
16
  import HForm from '../../Form/index.js';
17
17
  import Title from './Title.js';
18
18
  import Footer from './Footer.js';
19
+ import Index, { useFormConfigContext } from '../../Form/Context/FormConfigProvider.js';
19
20
 
20
21
  var _excluded = ["visible", "title", "onCancel", "configData", "infoRequest", "request", "afterClose", "dialogForm", "closable", "initialValues", "labelWidth", "onOk", "onFinish", "size", "form", "footer", "params", "onValuesChange"];
21
22
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
@@ -43,6 +44,7 @@ var DrawerForm = (function (_ref) {
43
44
  onValuesChange = _ref.onValuesChange,
44
45
  props = _objectWithoutProperties(_ref, _excluded);
45
46
  var currentForm = useCurrentForm(dialogForm);
47
+ var providerConfig = useFormConfigContext();
46
48
  var _useModifyProps = useModifyProps({
47
49
  configData: configData,
48
50
  visible: visible,
@@ -91,44 +93,46 @@ var DrawerForm = (function (_ref) {
91
93
  closable: false,
92
94
  destroyOnClose: true,
93
95
  footer: footerComponent(),
94
- children: jsx(HForm, _objectSpread(_objectSpread({
95
- configData: modalFormData,
96
- initialValues: initValue,
97
- onValuesChange: onValuesChange
98
- }, props), {}, {
99
- form: currentForm,
100
- params: formParams,
101
- onFinish: function () {
102
- var _onFinish = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(values, subParams) {
103
- var result, close;
104
- return _regeneratorRuntime.wrap(function _callee$(_context) {
105
- while (1) switch (_context.prev = _context.next) {
106
- case 0:
107
- _context.next = 2;
108
- return run(values, subParams);
109
- case 2:
110
- result = _context.sent;
111
- close = onOk === null || onOk === void 0 ? void 0 : onOk(result, subParams);
112
- if (!(close === false)) {
113
- _context.next = 6;
114
- break;
115
- }
116
- return _context.abrupt("return");
117
- case 6:
118
- cancel();
119
- case 7:
120
- case "end":
121
- return _context.stop();
122
- }
123
- }, _callee);
124
- }));
125
- function onFinish(_x, _x2) {
126
- return _onFinish.apply(this, arguments);
127
- }
128
- return onFinish;
129
- }(),
130
- infoRequest: infoRequest,
131
- labelWidth: labelWidth
96
+ children: jsx(Index, _objectSpread(_objectSpread({}, providerConfig), {}, {
97
+ children: jsx(HForm, _objectSpread(_objectSpread({
98
+ configData: modalFormData,
99
+ initialValues: initValue,
100
+ onValuesChange: onValuesChange
101
+ }, props), {}, {
102
+ form: currentForm,
103
+ params: formParams,
104
+ onFinish: function () {
105
+ var _onFinish = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(values, subParams) {
106
+ var result, close;
107
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
108
+ while (1) switch (_context.prev = _context.next) {
109
+ case 0:
110
+ _context.next = 2;
111
+ return run(values, subParams);
112
+ case 2:
113
+ result = _context.sent;
114
+ close = onOk === null || onOk === void 0 ? void 0 : onOk(result, subParams);
115
+ if (!(close === false)) {
116
+ _context.next = 6;
117
+ break;
118
+ }
119
+ return _context.abrupt("return");
120
+ case 6:
121
+ cancel();
122
+ case 7:
123
+ case "end":
124
+ return _context.stop();
125
+ }
126
+ }, _callee);
127
+ }));
128
+ function onFinish(_x, _x2) {
129
+ return _onFinish.apply(this, arguments);
130
+ }
131
+ return onFinish;
132
+ }(),
133
+ infoRequest: infoRequest,
134
+ labelWidth: labelWidth
135
+ }))
132
136
  }))
133
137
  }));
134
138
  });
@@ -13,6 +13,7 @@ import _regeneratorRuntime from '@babel/runtime-corejs3/regenerator';
13
13
  import { jsx } from 'react/jsx-runtime';
14
14
  import { Modal } from 'antd';
15
15
  import HForm from '../Form/index.js';
16
+ import Index, { useFormConfigContext } from '../Form/Context/FormConfigProvider.js';
16
17
  import { useCurrentForm, useModifyProps, useSub } from './hooks.js';
17
18
 
18
19
  var _excluded = ["visible", "title", "onCancel", "configData", "infoRequest", "request", "afterClose", "dialogForm", "initialValues", "onFinish", "params", "onOk", "onValuesChange"];
@@ -35,6 +36,7 @@ var ModalForm = (function (_ref) {
35
36
  onValuesChange = _ref.onValuesChange,
36
37
  props = _objectWithoutProperties(_ref, _excluded);
37
38
  var currentForm = useCurrentForm(dialogForm);
39
+ var providerConfig = useFormConfigContext();
38
40
  var _useModifyProps = useModifyProps({
39
41
  configData: configData,
40
42
  visible: visible,
@@ -73,43 +75,45 @@ var ModalForm = (function (_ref) {
73
75
  }, props), {}, {
74
76
  onOk: currentForm.submit,
75
77
  destroyOnClose: true,
76
- children: jsx(HForm, _objectSpread(_objectSpread({
77
- configData: modalFormData,
78
- initialValues: initValue,
79
- onValuesChange: onValuesChange,
80
- onFinish: function () {
81
- var _onFinish = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(values, outParams) {
82
- var result, close;
83
- return _regeneratorRuntime.wrap(function _callee$(_context) {
84
- while (1) switch (_context.prev = _context.next) {
85
- case 0:
86
- _context.next = 2;
87
- return run(values, outParams);
88
- case 2:
89
- result = _context.sent;
90
- close = onOk === null || onOk === void 0 ? void 0 : onOk(result, outParams);
91
- if (!(close === false)) {
92
- _context.next = 6;
93
- break;
94
- }
95
- return _context.abrupt("return");
96
- case 6:
97
- cancel();
98
- case 7:
99
- case "end":
100
- return _context.stop();
101
- }
102
- }, _callee);
103
- }));
104
- function onFinish(_x, _x2) {
105
- return _onFinish.apply(this, arguments);
106
- }
107
- return onFinish;
108
- }()
109
- }, props), {}, {
110
- params: formParams,
111
- form: currentForm,
112
- infoRequest: infoRequest
78
+ children: jsx(Index, _objectSpread(_objectSpread({}, providerConfig), {}, {
79
+ children: jsx(HForm, _objectSpread(_objectSpread({
80
+ configData: modalFormData,
81
+ initialValues: initValue,
82
+ onValuesChange: onValuesChange,
83
+ onFinish: function () {
84
+ var _onFinish = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(values, outParams) {
85
+ var result, close;
86
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
87
+ while (1) switch (_context.prev = _context.next) {
88
+ case 0:
89
+ _context.next = 2;
90
+ return run(values, outParams);
91
+ case 2:
92
+ result = _context.sent;
93
+ close = onOk === null || onOk === void 0 ? void 0 : onOk(result, outParams);
94
+ if (!(close === false)) {
95
+ _context.next = 6;
96
+ break;
97
+ }
98
+ return _context.abrupt("return");
99
+ case 6:
100
+ cancel();
101
+ case 7:
102
+ case "end":
103
+ return _context.stop();
104
+ }
105
+ }, _callee);
106
+ }));
107
+ function onFinish(_x, _x2) {
108
+ return _onFinish.apply(this, arguments);
109
+ }
110
+ return onFinish;
111
+ }()
112
+ }, props), {}, {
113
+ params: formParams,
114
+ form: currentForm,
115
+ infoRequest: infoRequest
116
+ }))
113
117
  }))
114
118
  }));
115
119
  });
@@ -3,6 +3,7 @@ import _defineProperty from '@babel/runtime-corejs3/helpers/defineProperty';
3
3
  import _toConsumableArray from '@babel/runtime-corejs3/helpers/toConsumableArray';
4
4
  import _slicedToArray from '@babel/runtime-corejs3/helpers/slicedToArray';
5
5
  import _objectWithoutProperties from '@babel/runtime-corejs3/helpers/objectWithoutProperties';
6
+ import 'core-js/modules/es.array.slice.js';
6
7
  import 'core-js/modules/es.object.to-string.js';
7
8
  import 'core-js/modules/es.regexp.to-string.js';
8
9
  import 'core-js/modules/es.string.trim.js';
@@ -10,6 +11,7 @@ import 'core-js/modules/es.array.map.js';
10
11
  import 'core-js/modules/es.array.from.js';
11
12
  import 'core-js/modules/es.string.iterator.js';
12
13
  import 'core-js/modules/es.function.name.js';
14
+ import 'core-js/modules/es.array.concat.js';
13
15
  import 'core-js/modules/es.object.keys.js';
14
16
  import 'core-js/modules/es.symbol.js';
15
17
  import 'core-js/modules/es.array.filter.js';
@@ -26,6 +28,14 @@ import { useState, useRef } from 'react';
26
28
  var _excluded = ["placeholder", "value", "onChange", "mediaType"];
27
29
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
28
30
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
31
+ var mkSubFileList = function mkSubFileList(fileList) {
32
+ var maxCount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
33
+ var len = fileList.length;
34
+ if (len > maxCount) {
35
+ return fileList.slice(len - maxCount);
36
+ }
37
+ return fileList;
38
+ };
29
39
  var Index = function Index(_ref) {
30
40
  var _ref$placeholder = _ref.placeholder,
31
41
  placeholder = _ref$placeholder === void 0 ? "请输入文件地址" : _ref$placeholder,
@@ -34,6 +44,7 @@ var Index = function Index(_ref) {
34
44
  onChange = _ref.onChange,
35
45
  mediaType = _ref.mediaType,
36
46
  props = _objectWithoutProperties(_ref, _excluded);
47
+ var maxCount = props.maxCount;
37
48
  var _useState = useState(""),
38
49
  _useState2 = _slicedToArray(_useState, 2),
39
50
  url = _useState2[0],
@@ -55,7 +66,7 @@ var Index = function Index(_ref) {
55
66
  url: url
56
67
  }
57
68
  });
58
- onChange === null || onChange === void 0 || onChange(newFileList);
69
+ onChange === null || onChange === void 0 || onChange(mkSubFileList(newFileList, maxCount));
59
70
  setUrl("");
60
71
  setLoad(false);
61
72
  };
@@ -91,7 +102,7 @@ var Index = function Index(_ref) {
91
102
  };
92
103
  });
93
104
  (_ref$current = ref.current) === null || _ref$current === void 0 || _ref$current.change({
94
- fileList: newFileList,
105
+ fileList: mkSubFileList([].concat(_toConsumableArray(value), _toConsumableArray(newFileList)), maxCount),
95
106
  file: newFileList[0]
96
107
  });
97
108
  setUrl("");
@@ -19,6 +19,7 @@ var hooks = require('../hooks.js');
19
19
  var index = require('../../Form/index.js');
20
20
  var Title = require('./Title.js');
21
21
  var Footer = require('./Footer.js');
22
+ var FormConfigProvider = require('../../Form/Context/FormConfigProvider.js');
22
23
 
23
24
  var _excluded = ["visible", "title", "onCancel", "configData", "infoRequest", "request", "afterClose", "dialogForm", "closable", "initialValues", "labelWidth", "onOk", "onFinish", "size", "form", "footer", "params", "onValuesChange"];
24
25
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
@@ -46,6 +47,7 @@ var DrawerForm = (function (_ref) {
46
47
  onValuesChange = _ref.onValuesChange,
47
48
  props = _objectWithoutProperties(_ref, _excluded);
48
49
  var currentForm = hooks.useCurrentForm(dialogForm);
50
+ var providerConfig = FormConfigProvider.useFormConfigContext();
49
51
  var _useModifyProps = hooks.useModifyProps({
50
52
  configData: configData,
51
53
  visible: visible,
@@ -94,44 +96,46 @@ var DrawerForm = (function (_ref) {
94
96
  closable: false,
95
97
  destroyOnClose: true,
96
98
  footer: footerComponent(),
97
- children: jsxRuntime.jsx(index.default, _objectSpread(_objectSpread({
98
- configData: modalFormData,
99
- initialValues: initValue,
100
- onValuesChange: onValuesChange
101
- }, props), {}, {
102
- form: currentForm,
103
- params: formParams,
104
- onFinish: function () {
105
- var _onFinish = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(values, subParams) {
106
- var result, close;
107
- return _regeneratorRuntime.wrap(function _callee$(_context) {
108
- while (1) switch (_context.prev = _context.next) {
109
- case 0:
110
- _context.next = 2;
111
- return run(values, subParams);
112
- case 2:
113
- result = _context.sent;
114
- close = onOk === null || onOk === void 0 ? void 0 : onOk(result, subParams);
115
- if (!(close === false)) {
116
- _context.next = 6;
117
- break;
118
- }
119
- return _context.abrupt("return");
120
- case 6:
121
- cancel();
122
- case 7:
123
- case "end":
124
- return _context.stop();
125
- }
126
- }, _callee);
127
- }));
128
- function onFinish(_x, _x2) {
129
- return _onFinish.apply(this, arguments);
130
- }
131
- return onFinish;
132
- }(),
133
- infoRequest: infoRequest,
134
- labelWidth: labelWidth
99
+ children: jsxRuntime.jsx(FormConfigProvider.default, _objectSpread(_objectSpread({}, providerConfig), {}, {
100
+ children: jsxRuntime.jsx(index.default, _objectSpread(_objectSpread({
101
+ configData: modalFormData,
102
+ initialValues: initValue,
103
+ onValuesChange: onValuesChange
104
+ }, props), {}, {
105
+ form: currentForm,
106
+ params: formParams,
107
+ onFinish: function () {
108
+ var _onFinish = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(values, subParams) {
109
+ var result, close;
110
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
111
+ while (1) switch (_context.prev = _context.next) {
112
+ case 0:
113
+ _context.next = 2;
114
+ return run(values, subParams);
115
+ case 2:
116
+ result = _context.sent;
117
+ close = onOk === null || onOk === void 0 ? void 0 : onOk(result, subParams);
118
+ if (!(close === false)) {
119
+ _context.next = 6;
120
+ break;
121
+ }
122
+ return _context.abrupt("return");
123
+ case 6:
124
+ cancel();
125
+ case 7:
126
+ case "end":
127
+ return _context.stop();
128
+ }
129
+ }, _callee);
130
+ }));
131
+ function onFinish(_x, _x2) {
132
+ return _onFinish.apply(this, arguments);
133
+ }
134
+ return onFinish;
135
+ }(),
136
+ infoRequest: infoRequest,
137
+ labelWidth: labelWidth
138
+ }))
135
139
  }))
136
140
  }));
137
141
  });
@@ -16,6 +16,7 @@ var _regeneratorRuntime = require('@babel/runtime-corejs3/regenerator');
16
16
  var jsxRuntime = require('react/jsx-runtime');
17
17
  var antd = require('antd');
18
18
  var index = require('../Form/index.js');
19
+ var FormConfigProvider = require('../Form/Context/FormConfigProvider.js');
19
20
  var hooks = require('./hooks.js');
20
21
 
21
22
  var _excluded = ["visible", "title", "onCancel", "configData", "infoRequest", "request", "afterClose", "dialogForm", "initialValues", "onFinish", "params", "onOk", "onValuesChange"];
@@ -38,6 +39,7 @@ var ModalForm = (function (_ref) {
38
39
  onValuesChange = _ref.onValuesChange,
39
40
  props = _objectWithoutProperties(_ref, _excluded);
40
41
  var currentForm = hooks.useCurrentForm(dialogForm);
42
+ var providerConfig = FormConfigProvider.useFormConfigContext();
41
43
  var _useModifyProps = hooks.useModifyProps({
42
44
  configData: configData,
43
45
  visible: visible,
@@ -76,43 +78,45 @@ var ModalForm = (function (_ref) {
76
78
  }, props), {}, {
77
79
  onOk: currentForm.submit,
78
80
  destroyOnClose: true,
79
- children: jsxRuntime.jsx(index.default, _objectSpread(_objectSpread({
80
- configData: modalFormData,
81
- initialValues: initValue,
82
- onValuesChange: onValuesChange,
83
- onFinish: function () {
84
- var _onFinish = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(values, outParams) {
85
- var result, close;
86
- return _regeneratorRuntime.wrap(function _callee$(_context) {
87
- while (1) switch (_context.prev = _context.next) {
88
- case 0:
89
- _context.next = 2;
90
- return run(values, outParams);
91
- case 2:
92
- result = _context.sent;
93
- close = onOk === null || onOk === void 0 ? void 0 : onOk(result, outParams);
94
- if (!(close === false)) {
95
- _context.next = 6;
96
- break;
97
- }
98
- return _context.abrupt("return");
99
- case 6:
100
- cancel();
101
- case 7:
102
- case "end":
103
- return _context.stop();
104
- }
105
- }, _callee);
106
- }));
107
- function onFinish(_x, _x2) {
108
- return _onFinish.apply(this, arguments);
109
- }
110
- return onFinish;
111
- }()
112
- }, props), {}, {
113
- params: formParams,
114
- form: currentForm,
115
- infoRequest: infoRequest
81
+ children: jsxRuntime.jsx(FormConfigProvider.default, _objectSpread(_objectSpread({}, providerConfig), {}, {
82
+ children: jsxRuntime.jsx(index.default, _objectSpread(_objectSpread({
83
+ configData: modalFormData,
84
+ initialValues: initValue,
85
+ onValuesChange: onValuesChange,
86
+ onFinish: function () {
87
+ var _onFinish = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(values, outParams) {
88
+ var result, close;
89
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
90
+ while (1) switch (_context.prev = _context.next) {
91
+ case 0:
92
+ _context.next = 2;
93
+ return run(values, outParams);
94
+ case 2:
95
+ result = _context.sent;
96
+ close = onOk === null || onOk === void 0 ? void 0 : onOk(result, outParams);
97
+ if (!(close === false)) {
98
+ _context.next = 6;
99
+ break;
100
+ }
101
+ return _context.abrupt("return");
102
+ case 6:
103
+ cancel();
104
+ case 7:
105
+ case "end":
106
+ return _context.stop();
107
+ }
108
+ }, _callee);
109
+ }));
110
+ function onFinish(_x, _x2) {
111
+ return _onFinish.apply(this, arguments);
112
+ }
113
+ return onFinish;
114
+ }()
115
+ }, props), {}, {
116
+ params: formParams,
117
+ form: currentForm,
118
+ infoRequest: infoRequest
119
+ }))
116
120
  }))
117
121
  }));
118
122
  });
@@ -6,6 +6,7 @@ var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
6
6
  var _toConsumableArray = require('@babel/runtime-corejs3/helpers/toConsumableArray');
7
7
  var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
8
8
  var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWithoutProperties');
9
+ require('core-js/modules/es.array.slice.js');
9
10
  require('core-js/modules/es.object.to-string.js');
10
11
  require('core-js/modules/es.regexp.to-string.js');
11
12
  require('core-js/modules/es.string.trim.js');
@@ -13,6 +14,7 @@ require('core-js/modules/es.array.map.js');
13
14
  require('core-js/modules/es.array.from.js');
14
15
  require('core-js/modules/es.string.iterator.js');
15
16
  require('core-js/modules/es.function.name.js');
17
+ require('core-js/modules/es.array.concat.js');
16
18
  require('core-js/modules/es.object.keys.js');
17
19
  require('core-js/modules/es.symbol.js');
18
20
  require('core-js/modules/es.array.filter.js');
@@ -29,6 +31,14 @@ var React = require('react');
29
31
  var _excluded = ["placeholder", "value", "onChange", "mediaType"];
30
32
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
31
33
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
34
+ var mkSubFileList = function mkSubFileList(fileList) {
35
+ var maxCount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
36
+ var len = fileList.length;
37
+ if (len > maxCount) {
38
+ return fileList.slice(len - maxCount);
39
+ }
40
+ return fileList;
41
+ };
32
42
  var Index = function Index(_ref) {
33
43
  var _ref$placeholder = _ref.placeholder,
34
44
  placeholder = _ref$placeholder === void 0 ? "请输入文件地址" : _ref$placeholder,
@@ -37,6 +47,7 @@ var Index = function Index(_ref) {
37
47
  onChange = _ref.onChange,
38
48
  mediaType = _ref.mediaType,
39
49
  props = _objectWithoutProperties(_ref, _excluded);
50
+ var maxCount = props.maxCount;
40
51
  var _useState = React.useState(""),
41
52
  _useState2 = _slicedToArray(_useState, 2),
42
53
  url = _useState2[0],
@@ -58,7 +69,7 @@ var Index = function Index(_ref) {
58
69
  url: url
59
70
  }
60
71
  });
61
- onChange === null || onChange === void 0 || onChange(newFileList);
72
+ onChange === null || onChange === void 0 || onChange(mkSubFileList(newFileList, maxCount));
62
73
  setUrl("");
63
74
  setLoad(false);
64
75
  };
@@ -94,7 +105,7 @@ var Index = function Index(_ref) {
94
105
  };
95
106
  });
96
107
  (_ref$current = ref.current) === null || _ref$current === void 0 || _ref$current.change({
97
- fileList: newFileList,
108
+ fileList: mkSubFileList([].concat(_toConsumableArray(value), _toConsumableArray(newFileList)), maxCount),
98
109
  file: newFileList[0]
99
110
  });
100
111
  setUrl("");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hw-component/form",
3
- "version": "0.0.6-beta-v4",
3
+ "version": "0.0.6-beta-v6",
4
4
  "description": "基于antd二次开发",
5
5
  "repository": {
6
6
  "type": "git",
@@ -4,6 +4,7 @@ import { useCurrentForm, useModifyProps, useSub } from "../hooks";
4
4
  import HForm from "../../Form";
5
5
  import Title from "./Title";
6
6
  import Footer from "./Footer";
7
+ import FormConfigProvider,{useFormConfigContext} from "../../Form/Context/FormConfigProvider";
7
8
  export default ({
8
9
  visible,
9
10
  title,
@@ -26,6 +27,7 @@ export default ({
26
27
  ...props
27
28
  }: DialogFormProps) => {
28
29
  const currentForm = useCurrentForm(dialogForm);
30
+ const providerConfig=useFormConfigContext();
29
31
  const {
30
32
  modalVisible,
31
33
  modalFormData,
@@ -72,24 +74,26 @@ export default ({
72
74
  destroyOnClose={true}
73
75
  footer={footerComponent()}
74
76
  >
75
- <HForm
76
- configData={modalFormData}
77
- initialValues={initValue}
78
- onValuesChange={onValuesChange}
79
- {...props}
80
- form={currentForm}
81
- params={formParams}
82
- onFinish={async (values, subParams) => {
83
- const result = await run(values, subParams);
84
- const close = onOk?.(result, subParams);
85
- if (close === false) {
86
- return;
87
- }
88
- cancel();
89
- }}
90
- infoRequest={infoRequest}
91
- labelWidth={labelWidth}
92
- />
77
+ <FormConfigProvider {...providerConfig}>
78
+ <HForm
79
+ configData={modalFormData}
80
+ initialValues={initValue}
81
+ onValuesChange={onValuesChange}
82
+ {...props}
83
+ form={currentForm}
84
+ params={formParams}
85
+ onFinish={async (values, subParams) => {
86
+ const result = await run(values, subParams);
87
+ const close = onOk?.(result, subParams);
88
+ if (close === false) {
89
+ return;
90
+ }
91
+ cancel();
92
+ }}
93
+ infoRequest={infoRequest}
94
+ labelWidth={labelWidth}
95
+ />
96
+ </FormConfigProvider>
93
97
  </Drawer>
94
98
  );
95
99
  };
@@ -1,6 +1,7 @@
1
1
  import { Modal } from "antd";
2
2
  import type { DialogFormProps } from "./modal";
3
3
  import HForm from "../Form";
4
+ import FormConfigProvider, {useFormConfigContext} from '../Form/Context/FormConfigProvider'
4
5
  import { useCurrentForm, useModifyProps, useSub } from "./hooks";
5
6
  export default ({
6
7
  visible,
@@ -19,6 +20,7 @@ export default ({
19
20
  ...props
20
21
  }: DialogFormProps) => {
21
22
  const currentForm = useCurrentForm(dialogForm);
23
+ const providerConfig=useFormConfigContext();
22
24
  const {
23
25
  modalVisible,
24
26
  modalFormData,
@@ -55,23 +57,25 @@ export default ({
55
57
  onOk={currentForm.submit}
56
58
  destroyOnClose={true}
57
59
  >
58
- <HForm
59
- configData={modalFormData}
60
- initialValues={initValue}
61
- onValuesChange={onValuesChange}
62
- onFinish={async (values, outParams) => {
63
- const result = await run(values, outParams);
64
- const close = onOk?.(result, outParams);
65
- if (close === false) {
66
- return;
67
- }
68
- cancel();
69
- }}
70
- {...props}
71
- params={formParams}
72
- form={currentForm}
73
- infoRequest={infoRequest}
74
- />
60
+ <FormConfigProvider {...providerConfig}>
61
+ <HForm
62
+ configData={modalFormData}
63
+ initialValues={initValue}
64
+ onValuesChange={onValuesChange}
65
+ onFinish={async (values, outParams) => {
66
+ const result = await run(values, outParams);
67
+ const close = onOk?.(result, outParams);
68
+ if (close === false) {
69
+ return;
70
+ }
71
+ cancel();
72
+ }}
73
+ {...props}
74
+ params={formParams}
75
+ form={currentForm}
76
+ infoRequest={infoRequest}
77
+ />
78
+ </FormConfigProvider>
75
79
  </Modal>
76
80
  );
77
81
  };
@@ -45,8 +45,8 @@ export const useModifyProps = ({
45
45
  dialogForm.show = (showParams = {}) => {
46
46
  const {
47
47
  configData: changeConfigData,
48
- initialValues: changeInitialValues={},
49
- params: changeParams={},
48
+ initialValues: changeInitialValues = {},
49
+ params: changeParams = {},
50
50
  title: changeTitle,
51
51
  } = showParams;
52
52
  if (!!changeConfigData) {
@@ -159,10 +159,10 @@ export default () => {
159
159
  });
160
160
  });
161
161
  },
162
- resetFields:()=>{
162
+ resetFields: () => {
163
163
  form.resetFields();
164
- isLoading=false;
165
- }
164
+ isLoading = false;
165
+ },
166
166
  };
167
167
  }, []);
168
168
  };
@@ -5,6 +5,15 @@ import type { IUploadRefModal, IUrlUploadProps } from "../modal";
5
5
  import TypeEle from "../MediaTypeEle/TypeEle";
6
6
  import { useRef, useState } from "react";
7
7
  import type { RcFile, UploadFile } from "antd/es/upload/interface";
8
+
9
+ const mkSubFileList = (fileList: UploadFile[], maxCount = 1) => {
10
+ const len = fileList.length;
11
+ if (len > maxCount) {
12
+ return fileList.slice(len - maxCount);
13
+ }
14
+ return fileList;
15
+ };
16
+
8
17
  const Index = ({
9
18
  placeholder = "请输入文件地址",
10
19
  value = [],
@@ -12,6 +21,7 @@ const Index = ({
12
21
  mediaType,
13
22
  ...props
14
23
  }: IUrlUploadProps) => {
24
+ const { maxCount } = props;
15
25
  const [url, setUrl] = useState("");
16
26
  const [load, setLoad] = useState<boolean>(false);
17
27
  const ref = useRef<IUploadRefModal | null>(null);
@@ -27,7 +37,7 @@ const Index = ({
27
37
  url,
28
38
  },
29
39
  });
30
- onChange?.(newFileList);
40
+ onChange?.(mkSubFileList(newFileList, maxCount));
31
41
  setUrl("");
32
42
  setLoad(false);
33
43
  };
@@ -59,7 +69,10 @@ const Index = ({
59
69
  type,
60
70
  };
61
71
  });
62
- ref.current?.change({ fileList: newFileList, file: newFileList[0] });
72
+ ref.current?.change({
73
+ fileList: mkSubFileList([...value, ...newFileList], maxCount),
74
+ file: newFileList[0],
75
+ });
63
76
  setUrl("");
64
77
  setLoad(false);
65
78
  };
@@ -117,14 +117,13 @@ export default () => {
117
117
  显示
118
118
  </Button>
119
119
  <Button
120
- onClick={() => {
121
- modalForm.show();
122
- }}
120
+ onClick={() => {
121
+ modalForm.show();
122
+ }}
123
123
  >
124
- 打开
124
+ 打开
125
125
  </Button>
126
126
  <HDrawerForm
127
-
128
127
  configData={data}
129
128
  labelWidth={88}
130
129
  dialogForm={modalForm}
@@ -114,6 +114,9 @@ const formData = (options) => {
114
114
  label: "地址文件",
115
115
  name: "urlUpload",
116
116
  type: "urlUpload",
117
+ itemProps: {
118
+ maxCount: 3,
119
+ },
117
120
  rules: [{ required: true }],
118
121
  },
119
122
  {
@@ -151,7 +154,7 @@ export default () => {
151
154
  labelWidth={200}
152
155
  form={form}
153
156
  initialValues={{
154
- name:'fff'
157
+ name: "fff",
155
158
  }}
156
159
  onFinish={(value) => {
157
160
  console.log(value);
@@ -184,15 +187,15 @@ export default () => {
184
187
  </HFormConfigProvider>
185
188
  <div
186
189
  onClick={() => {
187
- form.setFieldsValue({name:"123"})
190
+ form.setFieldsValue({ name: "123" });
188
191
  }}
189
192
  >
190
193
  点我
191
194
  </div>
192
195
  <div
193
- onClick={() => {
194
- form.resetFields();
195
- }}
196
+ onClick={() => {
197
+ form.resetFields();
198
+ }}
196
199
  >
197
200
  重置
198
201
  </div>
@@ -1,5 +1,5 @@
1
1
  import { Button } from "antd";
2
- import { HModalForm, useHDialogForm } from "../../components";
2
+ import { HModalForm, useHDialogForm ,HFormConfigProvider} from "../../components";
3
3
  const data = [
4
4
  {
5
5
  label: "输入框",
@@ -133,28 +133,37 @@ export default () => {
133
133
  打开
134
134
  </Button>
135
135
  <Button
136
- onClick={() => {
137
- modalForm.show({
138
- params: {
139
- name: num,
140
- },
141
- initialValues:{
142
- name:"name"
143
- }
144
- });
145
- }}
136
+ onClick={() => {
137
+ modalForm.show({
138
+ params: {
139
+ name: num,
140
+ },
141
+ initialValues: {
142
+ name: "name",
143
+ },
144
+ });
145
+ }}
146
146
  >
147
147
  宣誓
148
148
  </Button>
149
- <HModalForm
150
- configData={data}
151
- labelWidth={88}
152
- request={(val, params) => {
153
- console.log(val, params);
154
- }}
155
- dialogForm={modalForm}
156
- title="测试"
157
- />
149
+ <HFormConfigProvider
150
+ uploadProps={{
151
+ request:()=>{
152
+ console.log("request,request,request,request")
153
+ return Promise.resolve({url:"https://gw.alicdn.com/imgextra/i2/O1CN01MYuwJQ1GXVBWryCFJ_!!6000000000632-2-tps-1125-570.png_468x468q75.jpg_.webp"});
154
+ }
155
+ }}
156
+ >
157
+ <HModalForm
158
+ configData={data}
159
+ labelWidth={88}
160
+ request={(val, params) => {
161
+ console.log(val, params);
162
+ }}
163
+ dialogForm={modalForm}
164
+ title="测试"
165
+ />
166
+ </HFormConfigProvider>
158
167
  </>
159
168
  );
160
169
  };