@teamias/rex-design 0.0.26 → 0.0.27
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.
- package/dist/components/base-form/components/ProFormDateRangePickerV2.js +46 -20
- package/dist/components/base-form/components/ProFormDigitRangeV2.js +99 -87
- package/dist/components/base-form/components/ResetView.d.ts +5 -0
- package/dist/components/base-form/components/ResetView.js +15 -0
- package/dist/components/base-form/demo/BaseProFormDateRangePickerV2.js +5 -5
- package/dist/components/base-form/demo/BaseProFormDigitRangeV2.js +7 -6
- package/package.json +1 -1
|
@@ -19,7 +19,9 @@ import { DatePicker, Form } from 'antd';
|
|
|
19
19
|
import dayjs from 'dayjs';
|
|
20
20
|
import { get } from 'radash';
|
|
21
21
|
import { useContext, useMemo, useState } from 'react';
|
|
22
|
+
import { ResetView } from "./ResetView";
|
|
22
23
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
23
25
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
24
26
|
export var ProFormDateRangePickerV2 = function ProFormDateRangePickerV2(_ref) {
|
|
25
27
|
var name = _ref.name,
|
|
@@ -95,17 +97,29 @@ export var ProFormDateRangePickerV2 = function ProFormDateRangePickerV2(_ref) {
|
|
|
95
97
|
startValue = form.getFieldValue(startFieldName);
|
|
96
98
|
endValue = form.getFieldValue(endFieldName);
|
|
97
99
|
if (!(!startValue || !endValue)) {
|
|
98
|
-
_context.next =
|
|
100
|
+
_context.next = 7;
|
|
99
101
|
break;
|
|
100
102
|
}
|
|
101
103
|
setValidateStatus('error');
|
|
102
104
|
setHelp(!startValue && !endValue ? "\u8BF7\u9009\u62E9".concat(label || '') : '');
|
|
105
|
+
form.setFields([{
|
|
106
|
+
name: startFieldName,
|
|
107
|
+
errors: !startValue ? ["\u8BF7\u9009\u62E9".concat(label || '')] : []
|
|
108
|
+
}, {
|
|
109
|
+
name: endFieldName,
|
|
110
|
+
errors: !endValue ? ["\u8BF7\u9009\u62E9".concat(label || '')] : []
|
|
111
|
+
}]);
|
|
103
112
|
return _context.abrupt("return", Promise.reject(new Error("\u8BF7\u9009\u62E9".concat(label || ''))));
|
|
104
|
-
case
|
|
113
|
+
case 7:
|
|
105
114
|
setValidateStatus('');
|
|
106
115
|
setHelp('');
|
|
116
|
+
form.setFields([{
|
|
117
|
+
name: startFieldName
|
|
118
|
+
}, {
|
|
119
|
+
name: endFieldName
|
|
120
|
+
}]);
|
|
107
121
|
return _context.abrupt("return", Promise.resolve());
|
|
108
|
-
case
|
|
122
|
+
case 11:
|
|
109
123
|
case "end":
|
|
110
124
|
return _context.stop();
|
|
111
125
|
}
|
|
@@ -153,23 +167,35 @@ export var ProFormDateRangePickerV2 = function ProFormDateRangePickerV2(_ref) {
|
|
|
153
167
|
children: startValue && endValue ? "".concat(startValue, " ~ ").concat(endValue) : '-'
|
|
154
168
|
});
|
|
155
169
|
}
|
|
156
|
-
return /*#__PURE__*/
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
|
|
170
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
171
|
+
children: [/*#__PURE__*/_jsx(ResetView, {
|
|
172
|
+
data: data,
|
|
173
|
+
onReset: function onReset() {
|
|
174
|
+
if (!form.getFieldsError([startFieldName, endFieldName]).map(function (ii) {
|
|
175
|
+
return ii.errors;
|
|
176
|
+
}).flat().length && validateStatus !== '') {
|
|
177
|
+
setValidateStatus('');
|
|
178
|
+
setHelp('');
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}), /*#__PURE__*/_jsx(DatePicker.RangePicker, _objectSpread(_objectSpread({
|
|
182
|
+
placeholder: placeholder,
|
|
183
|
+
format: dataFormat,
|
|
184
|
+
allowClear: allowClear
|
|
185
|
+
}, fieldProps), {}, {
|
|
186
|
+
style: _objectSpread({
|
|
187
|
+
width: '100%'
|
|
188
|
+
}, fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.style),
|
|
189
|
+
value: startValue && endValue ? [dayjs(startValue), dayjs(endValue)] : undefined,
|
|
190
|
+
onChange: function onChange(dates, dateStrings) {
|
|
191
|
+
form.setFieldValue(startFieldName, dateStrings[0] || undefined);
|
|
192
|
+
form.setFieldValue(endFieldName, dateStrings[1] || undefined);
|
|
193
|
+
setTimeout(function () {
|
|
194
|
+
validateRules === null || validateRules === void 0 || validateRules[0].validator().catch(function () {});
|
|
195
|
+
}, 0);
|
|
196
|
+
}
|
|
197
|
+
}))]
|
|
198
|
+
});
|
|
173
199
|
}
|
|
174
200
|
})]
|
|
175
201
|
}));
|
|
@@ -13,11 +13,12 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
13
13
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
14
14
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
15
15
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
16
|
-
import { ProForm } from '@ant-design/pro-components';
|
|
16
|
+
import { ProForm, ProFormDependency } from '@ant-design/pro-components';
|
|
17
17
|
import { EditOrReadOnlyContext } from '@ant-design/pro-form/es/BaseForm/EditOrReadOnlyContext';
|
|
18
18
|
import { Form, Input, InputNumber, Space } from 'antd';
|
|
19
|
-
import { useCallback, useContext, useMemo } from 'react';
|
|
19
|
+
import { useCallback, useContext, useMemo, useState } from 'react';
|
|
20
20
|
import { RenderText } from "./RenderText";
|
|
21
|
+
import { ResetView } from "./ResetView";
|
|
21
22
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
22
23
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
23
24
|
export var ProFormDigitRangeV2 = function ProFormDigitRangeV2(_ref) {
|
|
@@ -37,6 +38,16 @@ export var ProFormDigitRangeV2 = function ProFormDigitRangeV2(_ref) {
|
|
|
37
38
|
var context = useContext(EditOrReadOnlyContext);
|
|
38
39
|
var formReadonly = context.mode === 'read';
|
|
39
40
|
|
|
41
|
+
// 校验状态
|
|
42
|
+
var _useState = useState(''),
|
|
43
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
44
|
+
validateStatus = _useState2[0],
|
|
45
|
+
setValidateStatus = _useState2[1];
|
|
46
|
+
var _useState3 = useState(''),
|
|
47
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
48
|
+
help = _useState4[0],
|
|
49
|
+
setHelp = _useState4[1];
|
|
50
|
+
|
|
40
51
|
// 获取字段名
|
|
41
52
|
var _useMemo = useMemo(function () {
|
|
42
53
|
return name || [undefined, undefined];
|
|
@@ -46,84 +57,56 @@ export var ProFormDigitRangeV2 = function ProFormDigitRangeV2(_ref) {
|
|
|
46
57
|
maxFieldName = _useMemo2[1];
|
|
47
58
|
|
|
48
59
|
// 生成校验规则
|
|
49
|
-
var
|
|
50
|
-
if (!required) return undefined;
|
|
51
|
-
if (requiredMode === 'both') {
|
|
52
|
-
// 两边都必填
|
|
53
|
-
return [{
|
|
54
|
-
required: true,
|
|
55
|
-
message: '请输入最小值'
|
|
56
|
-
}];
|
|
57
|
-
} else {
|
|
58
|
-
// 至少填一边
|
|
59
|
-
return [{
|
|
60
|
-
validator: function () {
|
|
61
|
-
var _validator = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_, value) {
|
|
62
|
-
var maxValue;
|
|
63
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
64
|
-
while (1) switch (_context.prev = _context.next) {
|
|
65
|
-
case 0:
|
|
66
|
-
maxValue = form.getFieldValue(maxFieldName);
|
|
67
|
-
if (!((value === null || value === undefined || value === '') && (maxValue === null || maxValue === undefined || maxValue === ''))) {
|
|
68
|
-
_context.next = 3;
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
return _context.abrupt("return", Promise.reject(new Error('请至少输入一个值')));
|
|
72
|
-
case 3:
|
|
73
|
-
return _context.abrupt("return", Promise.resolve());
|
|
74
|
-
case 4:
|
|
75
|
-
case "end":
|
|
76
|
-
return _context.stop();
|
|
77
|
-
}
|
|
78
|
-
}, _callee);
|
|
79
|
-
}));
|
|
80
|
-
function validator(_x, _x2) {
|
|
81
|
-
return _validator.apply(this, arguments);
|
|
82
|
-
}
|
|
83
|
-
return validator;
|
|
84
|
-
}()
|
|
85
|
-
}];
|
|
86
|
-
}
|
|
87
|
-
}, [required, requiredMode, maxFieldName, form]);
|
|
88
|
-
var maxRules = useMemo(function () {
|
|
60
|
+
var validateRules = useMemo(function () {
|
|
89
61
|
if (!required) return undefined;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
62
|
+
return [{
|
|
63
|
+
validator: function () {
|
|
64
|
+
var _validator = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
65
|
+
var minValue, maxValue;
|
|
66
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
67
|
+
while (1) switch (_context.prev = _context.next) {
|
|
68
|
+
case 0:
|
|
69
|
+
minValue = form.getFieldValue(minFieldName);
|
|
70
|
+
maxValue = form.getFieldValue(maxFieldName);
|
|
71
|
+
if (!(requiredMode === 'both')) {
|
|
72
|
+
_context.next = 9;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
if (!(minValue === null || minValue === undefined || minValue === '' || maxValue === null || maxValue === undefined || maxValue === '')) {
|
|
76
|
+
_context.next = 7;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
setValidateStatus('error');
|
|
80
|
+
setHelp((minValue === null || minValue === undefined || minValue === '') && (maxValue === null || maxValue === undefined || maxValue === '') ? "\u8BF7\u8F93\u5165".concat(label || '数值范围') : minValue === null || minValue === undefined || minValue === '' ? '请输入最小值' : '请输入最大值');
|
|
81
|
+
return _context.abrupt("return", Promise.reject(new Error("\u8BF7\u8F93\u5165".concat(label || '数值范围'))));
|
|
82
|
+
case 7:
|
|
83
|
+
_context.next = 13;
|
|
84
|
+
break;
|
|
85
|
+
case 9:
|
|
86
|
+
if (!((minValue === null || minValue === undefined || minValue === '') && (maxValue === null || maxValue === undefined || maxValue === ''))) {
|
|
87
|
+
_context.next = 13;
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
setValidateStatus('error');
|
|
91
|
+
setHelp('请至少输入一个值');
|
|
92
|
+
return _context.abrupt("return", Promise.reject(new Error('请至少输入一个值')));
|
|
93
|
+
case 13:
|
|
94
|
+
setValidateStatus('');
|
|
95
|
+
setHelp('');
|
|
96
|
+
return _context.abrupt("return", Promise.resolve());
|
|
97
|
+
case 16:
|
|
98
|
+
case "end":
|
|
99
|
+
return _context.stop();
|
|
100
|
+
}
|
|
101
|
+
}, _callee);
|
|
102
|
+
}));
|
|
103
|
+
function validator() {
|
|
104
|
+
return _validator.apply(this, arguments);
|
|
105
|
+
}
|
|
106
|
+
return validator;
|
|
107
|
+
}()
|
|
108
|
+
}];
|
|
109
|
+
}, [required, requiredMode, minFieldName, maxFieldName, form, label]);
|
|
127
110
|
|
|
128
111
|
// 处理最小值失去焦点
|
|
129
112
|
var handleMinBlur = useCallback(function () {
|
|
@@ -156,11 +139,28 @@ export var ProFormDigitRangeV2 = function ProFormDigitRangeV2(_ref) {
|
|
|
156
139
|
}
|
|
157
140
|
}, 0);
|
|
158
141
|
}, [autoSwap, minFieldName, maxFieldName, form]);
|
|
159
|
-
return /*#__PURE__*/
|
|
142
|
+
return /*#__PURE__*/_jsxs(Form.Item, _objectSpread(_objectSpread({
|
|
160
143
|
label: label,
|
|
161
|
-
required: required
|
|
144
|
+
required: required,
|
|
145
|
+
validateStatus: validateStatus,
|
|
146
|
+
help: help
|
|
162
147
|
}, formItemProps), {}, {
|
|
163
|
-
children: /*#__PURE__*/
|
|
148
|
+
children: [/*#__PURE__*/_jsx(ProFormDependency, {
|
|
149
|
+
name: [minFieldName, maxFieldName],
|
|
150
|
+
children: function children(data) {
|
|
151
|
+
return /*#__PURE__*/_jsx(ResetView, {
|
|
152
|
+
data: data,
|
|
153
|
+
onReset: function onReset() {
|
|
154
|
+
if (!form.getFieldsError([minFieldName, maxFieldName]).map(function (ii) {
|
|
155
|
+
return ii.errors;
|
|
156
|
+
}).flat().length && validateStatus !== '') {
|
|
157
|
+
setValidateStatus('');
|
|
158
|
+
setHelp('');
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}), /*#__PURE__*/_jsxs(Space.Compact, {
|
|
164
164
|
style: {
|
|
165
165
|
width: '100%'
|
|
166
166
|
},
|
|
@@ -168,7 +168,8 @@ export var ProFormDigitRangeV2 = function ProFormDigitRangeV2(_ref) {
|
|
|
168
168
|
noStyle: true,
|
|
169
169
|
name: minFieldName,
|
|
170
170
|
initialValue: initialValue === null || initialValue === void 0 ? void 0 : initialValue[0],
|
|
171
|
-
rules:
|
|
171
|
+
rules: validateRules,
|
|
172
|
+
validateStatus: validateStatus,
|
|
172
173
|
children: formReadonly ? /*#__PURE__*/_jsx(RenderText, {}) : /*#__PURE__*/_jsx(InputNumber, _objectSpread(_objectSpread({
|
|
173
174
|
placeholder: (placeholder === null || placeholder === void 0 ? void 0 : placeholder[0]) || '最小值',
|
|
174
175
|
precision: precision,
|
|
@@ -177,7 +178,12 @@ export var ProFormDigitRangeV2 = function ProFormDigitRangeV2(_ref) {
|
|
|
177
178
|
style: _objectSpread({
|
|
178
179
|
flex: 1
|
|
179
180
|
}, fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.style),
|
|
180
|
-
onBlur: handleMinBlur
|
|
181
|
+
onBlur: handleMinBlur,
|
|
182
|
+
onChange: function onChange() {
|
|
183
|
+
setTimeout(function () {
|
|
184
|
+
validateRules === null || validateRules === void 0 || validateRules[0].validator().catch(function () {});
|
|
185
|
+
}, 0);
|
|
186
|
+
}
|
|
181
187
|
}))
|
|
182
188
|
}), formReadonly ? /*#__PURE__*/_jsx(RenderText, {
|
|
183
189
|
value: "~",
|
|
@@ -199,7 +205,8 @@ export var ProFormDigitRangeV2 = function ProFormDigitRangeV2(_ref) {
|
|
|
199
205
|
noStyle: true,
|
|
200
206
|
name: maxFieldName,
|
|
201
207
|
initialValue: initialValue === null || initialValue === void 0 ? void 0 : initialValue[1],
|
|
202
|
-
rules:
|
|
208
|
+
rules: validateRules,
|
|
209
|
+
validateStatus: validateStatus,
|
|
203
210
|
children: formReadonly ? /*#__PURE__*/_jsx(RenderText, {}) : /*#__PURE__*/_jsx(InputNumber, _objectSpread(_objectSpread({
|
|
204
211
|
placeholder: (placeholder === null || placeholder === void 0 ? void 0 : placeholder[1]) || '最大值',
|
|
205
212
|
precision: precision,
|
|
@@ -208,9 +215,14 @@ export var ProFormDigitRangeV2 = function ProFormDigitRangeV2(_ref) {
|
|
|
208
215
|
style: _objectSpread({
|
|
209
216
|
flex: 1
|
|
210
217
|
}, fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.style),
|
|
211
|
-
onBlur: handleMaxBlur
|
|
218
|
+
onBlur: handleMaxBlur,
|
|
219
|
+
onChange: function onChange() {
|
|
220
|
+
setTimeout(function () {
|
|
221
|
+
validateRules === null || validateRules === void 0 || validateRules[0].validator().catch(function () {});
|
|
222
|
+
}, 0);
|
|
223
|
+
}
|
|
212
224
|
}))
|
|
213
225
|
})]
|
|
214
|
-
})
|
|
226
|
+
})]
|
|
215
227
|
}));
|
|
216
228
|
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useDebounceEffect } from 'ahooks';
|
|
2
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
export var ResetView = function ResetView(_ref) {
|
|
5
|
+
var data = _ref.data,
|
|
6
|
+
onReset = _ref.onReset;
|
|
7
|
+
useDebounceEffect(function () {
|
|
8
|
+
onReset();
|
|
9
|
+
}, [data], {
|
|
10
|
+
wait: 0,
|
|
11
|
+
trailing: true,
|
|
12
|
+
leading: false
|
|
13
|
+
});
|
|
14
|
+
return /*#__PURE__*/_jsx(_Fragment, {});
|
|
15
|
+
};
|
|
@@ -20,8 +20,8 @@ export default (function () {
|
|
|
20
20
|
data: {
|
|
21
21
|
// min: 2,
|
|
22
22
|
// max: 1111,
|
|
23
|
-
}
|
|
24
|
-
testName: 'qweqwe'
|
|
23
|
+
}
|
|
24
|
+
// testName: 'qweqwe',
|
|
25
25
|
}
|
|
26
26
|
// size="small"
|
|
27
27
|
// disabled
|
|
@@ -32,10 +32,10 @@ export default (function () {
|
|
|
32
32
|
console.log(values);
|
|
33
33
|
},
|
|
34
34
|
children: [/*#__PURE__*/_jsx(ProFormDateRangePickerV2, {
|
|
35
|
-
required:
|
|
35
|
+
required: true,
|
|
36
36
|
label: "\u65E5\u671F\u8303\u56F4",
|
|
37
|
-
name: [['data', 'start'], ['data', 'end']]
|
|
38
|
-
initialValue
|
|
37
|
+
name: [['data', 'start'], ['data', 'end']]
|
|
38
|
+
// initialValue={-30}
|
|
39
39
|
// dataFormat="YYYY-MM-DD"
|
|
40
40
|
}), /*#__PURE__*/_jsx(ProFormText, {
|
|
41
41
|
required: true,
|
|
@@ -35,12 +35,13 @@ export default (function () {
|
|
|
35
35
|
required: true,
|
|
36
36
|
label: "\u6570\u5B57\u8303\u56F4",
|
|
37
37
|
name: [['data', 'min'], ['data', 'max']],
|
|
38
|
-
initialValue: [undefined, 3]
|
|
39
|
-
formItemProps
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
38
|
+
initialValue: [undefined, 3]
|
|
39
|
+
// formItemProps={{
|
|
40
|
+
// style: {
|
|
41
|
+
// margin: 0,
|
|
42
|
+
// },
|
|
43
|
+
// }}
|
|
44
|
+
,
|
|
44
45
|
fieldProps: {
|
|
45
46
|
min: 0,
|
|
46
47
|
max: 1000
|