@kne/react-form-antd 1.2.14 → 2.0.0-alpha.0.3
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/index.css +112 -0
- package/dist/index.css.map +1 -0
- package/dist/index.js +300 -312
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +888 -0
- package/dist/index.modern.js.map +1 -0
- package/package.json +45 -25
- package/dist/index.es.js +0 -875
- package/dist/index.es.js.map +0 -1
- package/dist/react-form-antd.js +0 -13733
- package/dist/react-form-antd.js.map +0 -1
- package/dist/react-form-antd.min.js +0 -8
- package/dist/react-form-antd.min.js.map +0 -1
- package/dist/style.scss +0 -217
|
@@ -0,0 +1,888 @@
|
|
|
1
|
+
import React, { forwardRef, useState, useRef, useEffect, useCallback } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import classnames from 'classnames';
|
|
4
|
+
import ReactForm__default, { preset as preset$1, useSubmit, useReset } from '@kne/react-form';
|
|
5
|
+
export * from '@kne/react-form';
|
|
6
|
+
import { widget, hooks, hoc } from '@kne/react-form-helper';
|
|
7
|
+
export { hooks, utils } from '@kne/react-form-helper';
|
|
8
|
+
import { Upload as Upload$1, message, Modal, Row, Col, Slider, Cascader as Cascader$2, Checkbox as Checkbox$2, DatePicker as DatePicker$1, Input as Input$1, InputNumber as InputNumber$1, Radio, Select as Select$1, Switch as Switch$2, TimePicker as TimePicker$1, TreeSelect as TreeSelect$1, Button, Space } from 'antd';
|
|
9
|
+
import merge from 'lodash/merge';
|
|
10
|
+
import get from 'lodash/get';
|
|
11
|
+
import { LoadingOutlined, PlusOutlined, UploadOutlined } from '@ant-design/icons';
|
|
12
|
+
import AvatarEditor from 'react-avatar-editor';
|
|
13
|
+
import { withFetch } from '@kne/react-fetch';
|
|
14
|
+
import uniqueId from 'lodash/uniqueId';
|
|
15
|
+
import isEqual from 'lodash/isEqual';
|
|
16
|
+
|
|
17
|
+
function _extends() {
|
|
18
|
+
_extends = Object.assign || function (target) {
|
|
19
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
20
|
+
var source = arguments[i];
|
|
21
|
+
|
|
22
|
+
for (var key in source) {
|
|
23
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
24
|
+
target[key] = source[key];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return target;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
return _extends.apply(this, arguments);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
36
|
+
if (source == null) return {};
|
|
37
|
+
var target = {};
|
|
38
|
+
var sourceKeys = Object.keys(source);
|
|
39
|
+
var key, i;
|
|
40
|
+
|
|
41
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
42
|
+
key = sourceKeys[i];
|
|
43
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
44
|
+
target[key] = source[key];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return target;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const _excluded$5 = ["className", "cache", "enterSubmit", "scrollToError", "scrollProps", "type", "size", "children"];
|
|
51
|
+
const {
|
|
52
|
+
ScrollToError,
|
|
53
|
+
EnterSubmit,
|
|
54
|
+
FormStore,
|
|
55
|
+
MaxLabelProvider,
|
|
56
|
+
SizeProvider
|
|
57
|
+
} = widget;
|
|
58
|
+
const Form = forwardRef((_ref, ref) => {
|
|
59
|
+
let {
|
|
60
|
+
className,
|
|
61
|
+
cache,
|
|
62
|
+
enterSubmit,
|
|
63
|
+
scrollToError,
|
|
64
|
+
scrollProps,
|
|
65
|
+
type,
|
|
66
|
+
size,
|
|
67
|
+
children
|
|
68
|
+
} = _ref,
|
|
69
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded$5);
|
|
70
|
+
|
|
71
|
+
let computedClass = 'react-form';
|
|
72
|
+
|
|
73
|
+
if (type !== 'default') {
|
|
74
|
+
computedClass += `--${type}`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (size !== 'middle') {
|
|
78
|
+
computedClass += `--${size}`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const maxLabel = /*#__PURE__*/React.createElement(MaxLabelProvider, null, children);
|
|
82
|
+
return /*#__PURE__*/React.createElement("form", {
|
|
83
|
+
className: classnames(computedClass, className),
|
|
84
|
+
onSubmit: e => {
|
|
85
|
+
e.preventDefault();
|
|
86
|
+
e.stopPropagation();
|
|
87
|
+
}
|
|
88
|
+
}, /*#__PURE__*/React.createElement(SizeProvider, {
|
|
89
|
+
value: {
|
|
90
|
+
size
|
|
91
|
+
}
|
|
92
|
+
}, /*#__PURE__*/React.createElement(ReactForm__default, _extends({}, props, {
|
|
93
|
+
ref: ref
|
|
94
|
+
}), cache ? /*#__PURE__*/React.createElement(FormStore, {
|
|
95
|
+
cache: cache
|
|
96
|
+
}) : null, scrollToError ? /*#__PURE__*/React.createElement(ScrollToError, {
|
|
97
|
+
scrollProps: scrollProps
|
|
98
|
+
}) : null, enterSubmit ? /*#__PURE__*/React.createElement(EnterSubmit, null, maxLabel) : maxLabel)));
|
|
99
|
+
});
|
|
100
|
+
Form.defaultProps = {
|
|
101
|
+
type: 'default',
|
|
102
|
+
size: 'middle',
|
|
103
|
+
scrollToError: true,
|
|
104
|
+
enterSubmit: false,
|
|
105
|
+
scrollProps: {
|
|
106
|
+
block: 'center'
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
Form.propTypes = {
|
|
110
|
+
className: PropTypes.string,
|
|
111
|
+
type: PropTypes.oneOf(['inline', 'default', 'inner']),
|
|
112
|
+
size: PropTypes.oneOf(['small', 'middle', 'large']),
|
|
113
|
+
enterSubmit: PropTypes.bool,
|
|
114
|
+
scrollToError: PropTypes.bool,
|
|
115
|
+
scrollProps: PropTypes.shape({
|
|
116
|
+
block: PropTypes.oneOf(['start', 'center', 'end', 'nearest']),
|
|
117
|
+
behavior: PropTypes.oneOf(['auto', 'smooth']),
|
|
118
|
+
inline: PropTypes.oneOf(['start', 'center', 'end', 'nearest'])
|
|
119
|
+
})
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const globalParams = {
|
|
123
|
+
rules: {},
|
|
124
|
+
field: {
|
|
125
|
+
upload: {
|
|
126
|
+
action: '/open-api/upload_static_file/interview-manager',
|
|
127
|
+
transformResponse: response => {
|
|
128
|
+
return {
|
|
129
|
+
code: response.code,
|
|
130
|
+
msg: response.msg,
|
|
131
|
+
results: get(response, 'results[0].targetPath')
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
avatar: {
|
|
136
|
+
transformResponse: response => {
|
|
137
|
+
return {
|
|
138
|
+
code: response.code,
|
|
139
|
+
results: response.results,
|
|
140
|
+
msg: response.msg
|
|
141
|
+
};
|
|
142
|
+
},
|
|
143
|
+
action: '/upload'
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
var preset = (props => {
|
|
148
|
+
merge(globalParams, props);
|
|
149
|
+
preset$1(globalParams.rules);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const {
|
|
153
|
+
useOnChange: useOnChange$b
|
|
154
|
+
} = hooks;
|
|
155
|
+
const avatarParams = globalParams.field.avatar;
|
|
156
|
+
|
|
157
|
+
const _Avatar = ({
|
|
158
|
+
className,
|
|
159
|
+
value: imageUrl,
|
|
160
|
+
onChange: propsChange,
|
|
161
|
+
beforeUpload: onBeforeUpload,
|
|
162
|
+
transformResponse,
|
|
163
|
+
action,
|
|
164
|
+
imageType,
|
|
165
|
+
fileSize: size,
|
|
166
|
+
children,
|
|
167
|
+
onError,
|
|
168
|
+
editor
|
|
169
|
+
}) => {
|
|
170
|
+
const [loading, setLoading] = useState(false);
|
|
171
|
+
const [showImageUrl, setImageUrl] = useState(imageUrl);
|
|
172
|
+
const editorRef = useRef();
|
|
173
|
+
useEffect(() => {
|
|
174
|
+
setImageUrl(imageUrl);
|
|
175
|
+
}, [imageUrl]);
|
|
176
|
+
/* base64转blob */
|
|
177
|
+
|
|
178
|
+
const dataURLtoBlob = dataurl => {
|
|
179
|
+
let arr = dataurl.split(','); // 注意base64的最后面中括号和引号是不转译的
|
|
180
|
+
|
|
181
|
+
let _arr = arr[1].substring(0, arr[1].length - 2);
|
|
182
|
+
|
|
183
|
+
let mime = arr[0].match(/:(.*?);/)[1],
|
|
184
|
+
bstr = atob(_arr),
|
|
185
|
+
n = bstr.length,
|
|
186
|
+
u8arr = new Uint8Array(n);
|
|
187
|
+
|
|
188
|
+
while (n--) {
|
|
189
|
+
u8arr[n] = bstr.charCodeAt(n);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return new Blob([u8arr], {
|
|
193
|
+
type: mime
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
const AvatarEditorBox = ({
|
|
198
|
+
file
|
|
199
|
+
}) => {
|
|
200
|
+
const [rotate, setRotate] = useState(0);
|
|
201
|
+
const [scale, setScale] = useState(() => {
|
|
202
|
+
if (editor.width === editor.height) {
|
|
203
|
+
return 1;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return 0.35;
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
const onChange = v => {
|
|
210
|
+
console.log(v);
|
|
211
|
+
setRotate(v);
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const onChangeScale = v => {
|
|
215
|
+
console.log(v);
|
|
216
|
+
setScale(v);
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
220
|
+
style: {
|
|
221
|
+
'width': editor.width,
|
|
222
|
+
'margin': 'auto'
|
|
223
|
+
}
|
|
224
|
+
}, /*#__PURE__*/React.createElement(AvatarEditor, {
|
|
225
|
+
ref: editorRef,
|
|
226
|
+
image: file,
|
|
227
|
+
width: editor.width,
|
|
228
|
+
height: editor.height,
|
|
229
|
+
border: 1,
|
|
230
|
+
borderRadius: editor.borderRadius,
|
|
231
|
+
color: [24, 144, 255, 1] // RGBA
|
|
232
|
+
,
|
|
233
|
+
scale: scale,
|
|
234
|
+
rotate: rotate
|
|
235
|
+
}), /*#__PURE__*/React.createElement(Row, {
|
|
236
|
+
gutter: 4
|
|
237
|
+
}, /*#__PURE__*/React.createElement(Col, {
|
|
238
|
+
span: 4
|
|
239
|
+
}, /*#__PURE__*/React.createElement("span", null, "\u65CB\u8F6C")), /*#__PURE__*/React.createElement(Col, {
|
|
240
|
+
span: 15
|
|
241
|
+
}, /*#__PURE__*/React.createElement(Slider, {
|
|
242
|
+
tooltipVisible: false,
|
|
243
|
+
defaultValue: rotate,
|
|
244
|
+
min: -180,
|
|
245
|
+
max: 180,
|
|
246
|
+
onChange: onChange
|
|
247
|
+
}))), /*#__PURE__*/React.createElement(Row, {
|
|
248
|
+
gutter: 4
|
|
249
|
+
}, /*#__PURE__*/React.createElement(Col, {
|
|
250
|
+
span: 4
|
|
251
|
+
}, /*#__PURE__*/React.createElement("span", null, "\u653E\u5927")), /*#__PURE__*/React.createElement(Col, {
|
|
252
|
+
span: 15
|
|
253
|
+
}, /*#__PURE__*/React.createElement(Slider, {
|
|
254
|
+
tooltipVisible: false,
|
|
255
|
+
defaultValue: scale,
|
|
256
|
+
step: 0.05,
|
|
257
|
+
min: 0.2,
|
|
258
|
+
max: 3,
|
|
259
|
+
onChange: onChangeScale
|
|
260
|
+
}))));
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
const uploadButton = /*#__PURE__*/React.createElement("div", null, loading ? /*#__PURE__*/React.createElement(LoadingOutlined, null) : /*#__PURE__*/React.createElement(PlusOutlined, null), children);
|
|
264
|
+
|
|
265
|
+
const beforeUpload = async file => {
|
|
266
|
+
return new Promise((resolve, reject) => {
|
|
267
|
+
console.log('文件', file);
|
|
268
|
+
const isJpgOrPng = imageType.indexOf(file.type) > -1;
|
|
269
|
+
|
|
270
|
+
if (!isJpgOrPng) {
|
|
271
|
+
onError(`只支持${imageType.map(str => str.replace('image/', '')).join('/')}格式图片!`, 'typeError', {
|
|
272
|
+
type: imageType,
|
|
273
|
+
fileType: file.type
|
|
274
|
+
});
|
|
275
|
+
reject();
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const isLt = file.size / 1024 / 1024 < size;
|
|
280
|
+
|
|
281
|
+
if (!isLt) {
|
|
282
|
+
onError(`图片不能超过${size}MB!`, 'sizeError', {
|
|
283
|
+
size,
|
|
284
|
+
fileSize: file.size
|
|
285
|
+
});
|
|
286
|
+
reject();
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
289
|
+
/*剪切图像*/
|
|
290
|
+
// editor:{open:false,width:250,height:250,borderRadius:0-100,text:'剪切'}
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
if (editor.open) {
|
|
294
|
+
Modal.success({
|
|
295
|
+
// title: '剪切图像',
|
|
296
|
+
icon: '',
|
|
297
|
+
width: editor.width * 2,
|
|
298
|
+
content: /*#__PURE__*/React.createElement(AvatarEditorBox, {
|
|
299
|
+
file: file
|
|
300
|
+
}),
|
|
301
|
+
okText: editor.text,
|
|
302
|
+
onOk: close => {
|
|
303
|
+
// console.log(editorRef.current);
|
|
304
|
+
let base64 = editorRef.current.getImage().toDataURL();
|
|
305
|
+
setImageUrl(base64);
|
|
306
|
+
let blob = dataURLtoBlob(base64);
|
|
307
|
+
const files = new window.File([blob], file.name, {
|
|
308
|
+
type: file.type
|
|
309
|
+
});
|
|
310
|
+
onBeforeUpload && onBeforeUpload(files);
|
|
311
|
+
resolve(files); // console.log(files);
|
|
312
|
+
|
|
313
|
+
close();
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
} else {
|
|
317
|
+
onBeforeUpload && onBeforeUpload(file);
|
|
318
|
+
resolve(file); // return onBeforeUpload && onBeforeUpload(file);
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
const onChange = info => {
|
|
324
|
+
if (info.file.status === 'uploading') {
|
|
325
|
+
setLoading(true);
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (info.file.status === 'done') {
|
|
330
|
+
setLoading(false);
|
|
331
|
+
const response = (transformResponse || avatarParams.transformResponse)(info.file.response);
|
|
332
|
+
|
|
333
|
+
if (response.code === 200) {
|
|
334
|
+
propsChange(response.results);
|
|
335
|
+
} else {
|
|
336
|
+
onError(response.msg, 'xhrError', response);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Upload$1, {
|
|
342
|
+
className: classnames(className, 'react-form-avatar'),
|
|
343
|
+
listType: "picture-card",
|
|
344
|
+
showUploadList: false,
|
|
345
|
+
action: action || avatarParams.action,
|
|
346
|
+
beforeUpload: beforeUpload,
|
|
347
|
+
onChange: onChange
|
|
348
|
+
}, showImageUrl ? /*#__PURE__*/React.createElement("div", {
|
|
349
|
+
className: "preview"
|
|
350
|
+
}, /*#__PURE__*/React.createElement("img", {
|
|
351
|
+
src: showImageUrl,
|
|
352
|
+
alt: "avatar"
|
|
353
|
+
})) : uploadButton));
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
_Avatar.defaultProps = {
|
|
357
|
+
imageType: ['image/jpeg', 'image/png'],
|
|
358
|
+
fileSize: 2,
|
|
359
|
+
// 单位MB
|
|
360
|
+
children: /*#__PURE__*/React.createElement("div", {
|
|
361
|
+
className: "ant-upload-text"
|
|
362
|
+
}, "\u70B9\u51FB\u4E0A\u4F20"),
|
|
363
|
+
onError: info => message.error(info),
|
|
364
|
+
editor: {
|
|
365
|
+
open: false,
|
|
366
|
+
width: 250,
|
|
367
|
+
height: 250,
|
|
368
|
+
borderRadius: 1,
|
|
369
|
+
text: '剪切'
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
const AvatarInput = props => {
|
|
374
|
+
const render = useOnChange$b(props);
|
|
375
|
+
return render(_Avatar);
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
AvatarInput.field = _Avatar;
|
|
379
|
+
|
|
380
|
+
const {
|
|
381
|
+
useOnChange: useOnChange$a
|
|
382
|
+
} = hooks;
|
|
383
|
+
|
|
384
|
+
const Cascader$1 = props => {
|
|
385
|
+
const render = useOnChange$a(props);
|
|
386
|
+
return render(Cascader$2);
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
const {
|
|
390
|
+
useOnChange: useOnChange$9,
|
|
391
|
+
useCheckedToValue: useCheckedToValue$1
|
|
392
|
+
} = hooks;
|
|
393
|
+
const {
|
|
394
|
+
withChecked: withChecked$1
|
|
395
|
+
} = hoc;
|
|
396
|
+
const WithCheckbox = withChecked$1(Checkbox$2);
|
|
397
|
+
|
|
398
|
+
const Checkbox$1 = props => {
|
|
399
|
+
const checkedProps = useCheckedToValue$1(props);
|
|
400
|
+
const render = useOnChange$9(checkedProps);
|
|
401
|
+
return render(WithCheckbox);
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
const {
|
|
405
|
+
useOnChange: useOnChange$8
|
|
406
|
+
} = hooks;
|
|
407
|
+
const _CheckboxGroup = Checkbox$2.Group;
|
|
408
|
+
|
|
409
|
+
const CheckboxGroup$1 = props => {
|
|
410
|
+
const render = useOnChange$8(props);
|
|
411
|
+
return render(_CheckboxGroup);
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
CheckboxGroup$1.Checkbox = Checkbox$2;
|
|
415
|
+
|
|
416
|
+
const {
|
|
417
|
+
useOnChange: useOnChange$7
|
|
418
|
+
} = hooks;
|
|
419
|
+
const {
|
|
420
|
+
MonthPicker,
|
|
421
|
+
RangePicker: RangePicker$1,
|
|
422
|
+
WeekPicker
|
|
423
|
+
} = DatePicker$1;
|
|
424
|
+
|
|
425
|
+
const _DatePicker = props => {
|
|
426
|
+
const render = useOnChange$7(props);
|
|
427
|
+
return render(DatePicker$1);
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
const _MonthPicker = props => {
|
|
431
|
+
const render = useOnChange$7(props);
|
|
432
|
+
return render(MonthPicker);
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
const _RangePicker$1 = props => {
|
|
436
|
+
const render = useOnChange$7(props);
|
|
437
|
+
return render(RangePicker$1);
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
const _WeekPicker = props => {
|
|
441
|
+
const render = useOnChange$7(props);
|
|
442
|
+
return render(WeekPicker);
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
_DatePicker.MonthPicker = _MonthPicker;
|
|
446
|
+
_DatePicker.RangePicker = _RangePicker$1;
|
|
447
|
+
_DatePicker.WeekPicker = _WeekPicker;
|
|
448
|
+
|
|
449
|
+
const {
|
|
450
|
+
useDecorator: useDecorator$2
|
|
451
|
+
} = hooks;
|
|
452
|
+
|
|
453
|
+
const InputField = props => {
|
|
454
|
+
const render = useDecorator$2(props);
|
|
455
|
+
return render(Input$1);
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
InputField.defaultProps = {
|
|
459
|
+
autoComplete: 'off'
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
const {
|
|
463
|
+
useDecorator: useDecorator$1
|
|
464
|
+
} = hooks;
|
|
465
|
+
|
|
466
|
+
const InputNumberField = props => {
|
|
467
|
+
const render = useDecorator$1(props);
|
|
468
|
+
return render(InputNumber$1);
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
InputNumberField.defaultProps = {
|
|
472
|
+
autoComplete: 'off'
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
const _excluded$4 = ["onChange"];
|
|
476
|
+
const {
|
|
477
|
+
useOnChange: useOnChange$6
|
|
478
|
+
} = hooks;
|
|
479
|
+
|
|
480
|
+
const RadioGroup$1 = (_ref) => {
|
|
481
|
+
let {
|
|
482
|
+
onChange
|
|
483
|
+
} = _ref,
|
|
484
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded$4);
|
|
485
|
+
|
|
486
|
+
const handler = useCallback(e => {
|
|
487
|
+
onChange && onChange(e.target.value);
|
|
488
|
+
}, [onChange]);
|
|
489
|
+
return /*#__PURE__*/React.createElement(Radio.Group, _extends({}, props, {
|
|
490
|
+
onChange: handler
|
|
491
|
+
}));
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
const _RadioGroup = props => {
|
|
495
|
+
const render = useOnChange$6(props);
|
|
496
|
+
return render(RadioGroup$1);
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
_RadioGroup.Radio = Radio;
|
|
500
|
+
|
|
501
|
+
const {
|
|
502
|
+
useOnChange: useOnChange$5
|
|
503
|
+
} = hooks;
|
|
504
|
+
|
|
505
|
+
const _Select = props => {
|
|
506
|
+
const render = useOnChange$5(props);
|
|
507
|
+
return render(Select$1);
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
_Select.Option = Select$1.Option;
|
|
511
|
+
_Select.OptGroup = Select$1.OptGroup;
|
|
512
|
+
|
|
513
|
+
const _excluded$3 = ["data", "setData", "refresh", "isLoading", "children"];
|
|
514
|
+
const {
|
|
515
|
+
useOnChange: useOnChange$4
|
|
516
|
+
} = hooks;
|
|
517
|
+
|
|
518
|
+
const _SelectFetch = withFetch((_ref) => {
|
|
519
|
+
let {
|
|
520
|
+
data,
|
|
521
|
+
setData,
|
|
522
|
+
refresh,
|
|
523
|
+
isLoading,
|
|
524
|
+
children
|
|
525
|
+
} = _ref,
|
|
526
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded$3);
|
|
527
|
+
|
|
528
|
+
return /*#__PURE__*/React.createElement(Select$1, props, children({
|
|
529
|
+
data,
|
|
530
|
+
refresh,
|
|
531
|
+
isLoading,
|
|
532
|
+
setData
|
|
533
|
+
}));
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
const SelectFetch$1 = props => {
|
|
537
|
+
const render = useOnChange$4(props);
|
|
538
|
+
return render(_SelectFetch);
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
SelectFetch$1.Option = Select$1.Option;
|
|
542
|
+
SelectFetch$1.OptGroup = Select$1.OptGroup;
|
|
543
|
+
|
|
544
|
+
const {
|
|
545
|
+
useOnChange: useOnChange$3,
|
|
546
|
+
useCheckedToValue
|
|
547
|
+
} = hooks;
|
|
548
|
+
const {
|
|
549
|
+
withChecked
|
|
550
|
+
} = hoc;
|
|
551
|
+
const WithSwitch = withChecked(Switch$2);
|
|
552
|
+
|
|
553
|
+
const Switch$1 = props => {
|
|
554
|
+
const checkedProps = useCheckedToValue(props);
|
|
555
|
+
const render = useOnChange$3(checkedProps);
|
|
556
|
+
return render(WithSwitch);
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
const {
|
|
560
|
+
useDecorator
|
|
561
|
+
} = hooks;
|
|
562
|
+
|
|
563
|
+
const TextArea$1 = props => {
|
|
564
|
+
const render = useDecorator(props);
|
|
565
|
+
return render(Input$1.TextArea);
|
|
566
|
+
};
|
|
567
|
+
|
|
568
|
+
const {
|
|
569
|
+
useOnChange: useOnChange$2
|
|
570
|
+
} = hooks;
|
|
571
|
+
const {
|
|
572
|
+
RangePicker
|
|
573
|
+
} = TimePicker$1;
|
|
574
|
+
|
|
575
|
+
const _TimePicker = props => {
|
|
576
|
+
const render = useOnChange$2(props);
|
|
577
|
+
return render(TimePicker$1);
|
|
578
|
+
};
|
|
579
|
+
|
|
580
|
+
const _RangePicker = props => {
|
|
581
|
+
const render = useOnChange$2(props);
|
|
582
|
+
return render(RangePicker);
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
_TimePicker.RangePicker = _RangePicker;
|
|
586
|
+
|
|
587
|
+
const {
|
|
588
|
+
useOnChange: useOnChange$1
|
|
589
|
+
} = hooks;
|
|
590
|
+
|
|
591
|
+
const _TreeSelect = props => {
|
|
592
|
+
const render = useOnChange$1(props);
|
|
593
|
+
return render(TreeSelect$1);
|
|
594
|
+
};
|
|
595
|
+
|
|
596
|
+
_TreeSelect.TreeNode = TreeSelect$1.TreeNode;
|
|
597
|
+
|
|
598
|
+
const _excluded$2 = ["value", "onChange"],
|
|
599
|
+
_excluded2$1 = ["className", "value", "onChange", "onUploadComplete", "beforeUpload", "maxLength", "drag", "transformResponse", "action", "accept", "fileSize", "children", "onError"];
|
|
600
|
+
const {
|
|
601
|
+
useOnChange
|
|
602
|
+
} = hooks;
|
|
603
|
+
const {
|
|
604
|
+
Dragger
|
|
605
|
+
} = Upload$1;
|
|
606
|
+
const uploadParams = globalParams.field.upload;
|
|
607
|
+
|
|
608
|
+
const valueToList = value => {
|
|
609
|
+
if (!value) {
|
|
610
|
+
return [];
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
return value.map(item => ({
|
|
614
|
+
uid: uniqueId(),
|
|
615
|
+
name: item.substr(item.lastIndexOf('/') + 1),
|
|
616
|
+
status: 'done',
|
|
617
|
+
response: {
|
|
618
|
+
code: 200,
|
|
619
|
+
results: item
|
|
620
|
+
}
|
|
621
|
+
}));
|
|
622
|
+
};
|
|
623
|
+
|
|
624
|
+
const listToValue = value => {
|
|
625
|
+
return value.slice(0).filter(({
|
|
626
|
+
status
|
|
627
|
+
}) => status === 'done').map(({
|
|
628
|
+
response
|
|
629
|
+
}) => response.results);
|
|
630
|
+
};
|
|
631
|
+
|
|
632
|
+
const withValueAdapter = WrappedComponent => (_ref) => {
|
|
633
|
+
let {
|
|
634
|
+
value,
|
|
635
|
+
onChange
|
|
636
|
+
} = _ref,
|
|
637
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded$2);
|
|
638
|
+
|
|
639
|
+
const [list, setList] = useState([]);
|
|
640
|
+
const targetListRef = useRef([]);
|
|
641
|
+
useEffect(() => {
|
|
642
|
+
if (isEqual(value, targetListRef.current)) {
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
setList(valueToList(value));
|
|
647
|
+
}, [value]);
|
|
648
|
+
return /*#__PURE__*/React.createElement(WrappedComponent, _extends({}, props, {
|
|
649
|
+
value: list,
|
|
650
|
+
onChange: value => {
|
|
651
|
+
value = value.map(item => Object.assign({}, item));
|
|
652
|
+
setList(value);
|
|
653
|
+
const targetList = listToValue(value);
|
|
654
|
+
targetListRef.current = targetList;
|
|
655
|
+
|
|
656
|
+
if (isEqual(targetList, value)) {
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
onChange(targetList);
|
|
661
|
+
}
|
|
662
|
+
}));
|
|
663
|
+
};
|
|
664
|
+
|
|
665
|
+
const _Upload = (_ref2) => {
|
|
666
|
+
let {
|
|
667
|
+
value: list,
|
|
668
|
+
onChange: setList,
|
|
669
|
+
onUploadComplete,
|
|
670
|
+
beforeUpload: onBeforeUpload,
|
|
671
|
+
maxLength,
|
|
672
|
+
drag,
|
|
673
|
+
transformResponse,
|
|
674
|
+
action,
|
|
675
|
+
accept,
|
|
676
|
+
fileSize: size,
|
|
677
|
+
children,
|
|
678
|
+
onError
|
|
679
|
+
} = _ref2,
|
|
680
|
+
props = _objectWithoutPropertiesLoose(_ref2, _excluded2$1);
|
|
681
|
+
|
|
682
|
+
const beforeUpload = file => {
|
|
683
|
+
if (maxLength === 1) {
|
|
684
|
+
setList([]);
|
|
685
|
+
}
|
|
686
|
+
/*const typeAllowed = accept.length === 0 || !!accept.find((type) => type === file.type);
|
|
687
|
+
if (!typeAllowed) {
|
|
688
|
+
onError(`只支持${accept.join('/')}格式文件!`, 'typeError', {
|
|
689
|
+
type: accept,
|
|
690
|
+
fileType: file.type
|
|
691
|
+
});
|
|
692
|
+
return false;
|
|
693
|
+
}*/
|
|
694
|
+
|
|
695
|
+
|
|
696
|
+
const isLt = file.size / 1024 / 1024 < size;
|
|
697
|
+
|
|
698
|
+
if (!isLt) {
|
|
699
|
+
onError(`文件不能超过${size}MB!`, 'sizeError', {
|
|
700
|
+
size,
|
|
701
|
+
fileSize: file.size
|
|
702
|
+
});
|
|
703
|
+
return false;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
return onBeforeUpload && onBeforeUpload(file);
|
|
707
|
+
};
|
|
708
|
+
|
|
709
|
+
const onChange = info => {
|
|
710
|
+
if (['uploading', 'done', 'error', 'removed'].indexOf(info.file.status) === -1) {
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
if (info.fileList.length > maxLength) {
|
|
715
|
+
onError(`上传文件不能超过最大允许数量${maxLength}`, 'xhrError', maxLength);
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
if (info.file.status === 'done') {
|
|
720
|
+
info.file.response = (transformResponse || uploadParams.transformResponse)(info.file.response);
|
|
721
|
+
|
|
722
|
+
if (info.file.response.code === 200) {
|
|
723
|
+
info.file.name = info.file.response.results.substr(info.file.response.results.lastIndexOf('/') + 1);
|
|
724
|
+
onUploadComplete(info.file);
|
|
725
|
+
} else {
|
|
726
|
+
info.file.status = 'error';
|
|
727
|
+
onError(info.file.response.msg, 'xhrError', info.file.response);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
const newList = list.slice(0);
|
|
732
|
+
const index = newList.findIndex(({
|
|
733
|
+
uid
|
|
734
|
+
}) => uid === info.file.uid);
|
|
735
|
+
index > -1 && newList.splice(index, 1);
|
|
736
|
+
|
|
737
|
+
if (info.file.status !== 'removed') {
|
|
738
|
+
newList.push(info.file);
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
setList(newList);
|
|
742
|
+
};
|
|
743
|
+
|
|
744
|
+
const UploadComponent = drag ? Dragger : Upload$1;
|
|
745
|
+
return /*#__PURE__*/React.createElement(UploadComponent, _extends({}, props, {
|
|
746
|
+
action: action || uploadParams.action,
|
|
747
|
+
fileList: list,
|
|
748
|
+
accept: accept.join(','),
|
|
749
|
+
onChange: onChange,
|
|
750
|
+
beforeUpload: beforeUpload
|
|
751
|
+
}), children);
|
|
752
|
+
};
|
|
753
|
+
|
|
754
|
+
_Upload.defaultProps = {
|
|
755
|
+
value: [],
|
|
756
|
+
accept: [],
|
|
757
|
+
fileSize: 2,
|
|
758
|
+
maxLength: 1,
|
|
759
|
+
children: /*#__PURE__*/React.createElement(Button, null, /*#__PURE__*/React.createElement(UploadOutlined, null), "\u70B9\u51FB\u4E0A\u4F20"),
|
|
760
|
+
onError: info => message.error(info),
|
|
761
|
+
onUploadComplete: () => {}
|
|
762
|
+
};
|
|
763
|
+
const AdapterUpload = withValueAdapter(_Upload);
|
|
764
|
+
|
|
765
|
+
const UploadInput = props => {
|
|
766
|
+
const render = useOnChange(props);
|
|
767
|
+
return render(AdapterUpload);
|
|
768
|
+
};
|
|
769
|
+
|
|
770
|
+
UploadInput.field = _Upload;
|
|
771
|
+
|
|
772
|
+
const _excluded$1 = ["isPass", "isLoading"];
|
|
773
|
+
|
|
774
|
+
const SubmitButton = props => {
|
|
775
|
+
const _useSubmit = useSubmit(props),
|
|
776
|
+
{
|
|
777
|
+
isLoading
|
|
778
|
+
} = _useSubmit,
|
|
779
|
+
submitProps = _objectWithoutPropertiesLoose(_useSubmit, _excluded$1);
|
|
780
|
+
|
|
781
|
+
return /*#__PURE__*/React.createElement(Button, _extends({
|
|
782
|
+
loading: isLoading
|
|
783
|
+
}, submitProps, props));
|
|
784
|
+
};
|
|
785
|
+
|
|
786
|
+
const ResetButton = props => {
|
|
787
|
+
const resetProps = useReset();
|
|
788
|
+
return /*#__PURE__*/React.createElement(Button, _extends({}, resetProps, props));
|
|
789
|
+
};
|
|
790
|
+
|
|
791
|
+
const _excluded = ["className", "formProps", "footer", "children"],
|
|
792
|
+
_excluded2 = ["className", "title", "formProps", "footer", "content"];
|
|
793
|
+
const FetchForm = withFetch(Form);
|
|
794
|
+
|
|
795
|
+
const CommonModal = ({
|
|
796
|
+
formProps,
|
|
797
|
+
footer,
|
|
798
|
+
children
|
|
799
|
+
}) => {
|
|
800
|
+
const TargetForm = formProps.hasOwnProperty('url') ? FetchForm : Form;
|
|
801
|
+
return /*#__PURE__*/React.createElement(TargetForm, formProps, /*#__PURE__*/React.createElement("div", {
|
|
802
|
+
className: "ant-modal-body"
|
|
803
|
+
}, children), /*#__PURE__*/React.createElement("div", {
|
|
804
|
+
className: "ant-modal-footer"
|
|
805
|
+
}, footer ? footer : /*#__PURE__*/React.createElement(Space, null, /*#__PURE__*/React.createElement(ResetButton, null, "\u91CD\u7F6E"), /*#__PURE__*/React.createElement(SubmitButton, {
|
|
806
|
+
type: "primary"
|
|
807
|
+
}, "\u786E\u5B9A"))));
|
|
808
|
+
};
|
|
809
|
+
|
|
810
|
+
const FormModal = (_ref) => {
|
|
811
|
+
let {
|
|
812
|
+
className,
|
|
813
|
+
formProps = {},
|
|
814
|
+
footer,
|
|
815
|
+
children
|
|
816
|
+
} = _ref,
|
|
817
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
818
|
+
|
|
819
|
+
return /*#__PURE__*/React.createElement(Modal, _extends({}, props, {
|
|
820
|
+
className: classnames(className, 'react-form-modal'),
|
|
821
|
+
footer: null
|
|
822
|
+
}), /*#__PURE__*/React.createElement(CommonModal, {
|
|
823
|
+
formProps: formProps,
|
|
824
|
+
footer: footer
|
|
825
|
+
}, children));
|
|
826
|
+
};
|
|
827
|
+
|
|
828
|
+
FormModal.modal = (_ref2) => {
|
|
829
|
+
let {
|
|
830
|
+
className,
|
|
831
|
+
title,
|
|
832
|
+
formProps = {},
|
|
833
|
+
footer,
|
|
834
|
+
content
|
|
835
|
+
} = _ref2,
|
|
836
|
+
props = _objectWithoutPropertiesLoose(_ref2, _excluded2);
|
|
837
|
+
|
|
838
|
+
return Modal.info(_extends({}, props, {
|
|
839
|
+
title: title ? /*#__PURE__*/React.createElement("div", {
|
|
840
|
+
className: "ant-modal-header"
|
|
841
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
842
|
+
className: "ant-modal-title"
|
|
843
|
+
}, title)) : null,
|
|
844
|
+
className: classnames(className, 'react-form-modal'),
|
|
845
|
+
content: /*#__PURE__*/React.createElement(CommonModal, {
|
|
846
|
+
formProps: formProps,
|
|
847
|
+
footer: footer
|
|
848
|
+
}, content),
|
|
849
|
+
icon: null,
|
|
850
|
+
footer: null
|
|
851
|
+
}));
|
|
852
|
+
};
|
|
853
|
+
|
|
854
|
+
const Avatar = AvatarInput;
|
|
855
|
+
const Cascader = Cascader$1;
|
|
856
|
+
const Checkbox = Checkbox$1;
|
|
857
|
+
const CheckboxGroup = CheckboxGroup$1;
|
|
858
|
+
const DatePicker = _DatePicker;
|
|
859
|
+
const Input = InputField;
|
|
860
|
+
const InputNumber = InputNumberField;
|
|
861
|
+
const RadioGroup = _RadioGroup;
|
|
862
|
+
const Select = _Select;
|
|
863
|
+
const SelectFetch = SelectFetch$1;
|
|
864
|
+
const Switch = Switch$1;
|
|
865
|
+
const TextArea = TextArea$1;
|
|
866
|
+
const TimePicker = _TimePicker;
|
|
867
|
+
const TreeSelect = _TreeSelect;
|
|
868
|
+
const Upload = UploadInput;
|
|
869
|
+
const fields = {
|
|
870
|
+
Avatar,
|
|
871
|
+
Cascader,
|
|
872
|
+
Checkbox,
|
|
873
|
+
CheckboxGroup,
|
|
874
|
+
DatePicker,
|
|
875
|
+
Input,
|
|
876
|
+
InputNumber,
|
|
877
|
+
RadioGroup,
|
|
878
|
+
Select,
|
|
879
|
+
SelectFetch,
|
|
880
|
+
Switch,
|
|
881
|
+
TextArea,
|
|
882
|
+
TimePicker,
|
|
883
|
+
TreeSelect,
|
|
884
|
+
Upload
|
|
885
|
+
};
|
|
886
|
+
|
|
887
|
+
export { Avatar, Cascader, Checkbox, CheckboxGroup, DatePicker, FormModal, Input, InputNumber, RadioGroup, ResetButton, Select, SelectFetch, SubmitButton, Switch, TextArea, TimePicker, TreeSelect, Upload, Form as default, fields, preset };
|
|
888
|
+
//# sourceMappingURL=index.modern.js.map
|