@para-ui/core 4.0.18 → 4.0.19
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/Form/index.js +1 -1
- package/FormItem/index.js +1 -1
- package/README.md +4 -0
- package/Select/index.js +1 -1
- package/Selector/index.js +325 -2
- package/SelectorPicker/index.js +0 -1
- package/Upload/index.js +408 -625
- package/index.js +1 -2
- package/package.json +1 -1
- package/umd/ComboSelect.js +1 -1
- package/umd/CycleSelector.js +1 -1
- package/umd/DynamicMultiBox.js +1 -1
- package/umd/Form.js +1 -1
- package/umd/FormItem.js +1 -1
- package/umd/Pagination.js +1 -1
- package/umd/Select.js +1 -1
- package/umd/SelectInput.js +1 -1
- package/umd/Table.js +1 -1
- package/_verture/index-287ae1b3.js +0 -327
- /package/_verture/{index-10792f39.js → index-cb2c05c7.js} +0 -0
package/Upload/index.js
CHANGED
|
@@ -4,10 +4,6 @@ import { useState, useEffect, useRef, memo, forwardRef, useCallback, useImperati
|
|
|
4
4
|
import RcUpload from 'rc-upload';
|
|
5
5
|
import UploadIcon from '@para-ui/icons/UploadFile';
|
|
6
6
|
import LoadingIcon from '@para-ui/icons/Loading';
|
|
7
|
-
import { _ as _toConsumableArray } from '../_verture/toConsumableArray-8f4c9589.js';
|
|
8
|
-
import { _ as _typeof } from '../_verture/typeof-adeedc13.js';
|
|
9
|
-
import { _ as _slicedToArray } from '../_verture/slicedToArray-a8206399.js';
|
|
10
|
-
import { r as regenerator } from '../_verture/index-287ae1b3.js';
|
|
11
7
|
import Delete from '@para-ui/icons/Delete';
|
|
12
8
|
import TextIcon from '@para-ui/icons/Text';
|
|
13
9
|
import PhotoIcon from '@para-ui/icons/Photo';
|
|
@@ -18,11 +14,10 @@ import Forbid from '@para-ui/icons/Forbid';
|
|
|
18
14
|
import { u as useFormatMessage } from '../_verture/useFormatMessage-eb13cf56.js';
|
|
19
15
|
import EditOutline from '@para-ui/icons/EditOutline';
|
|
20
16
|
import { Button } from '../Button/index.js';
|
|
17
|
+
import { _ as _slicedToArray } from '../_verture/slicedToArray-a8206399.js';
|
|
21
18
|
import { Slider } from '../Slider/index.js';
|
|
22
19
|
import Cropper from 'react-easy-crop';
|
|
23
20
|
import { Modal } from '../Modal/index.js';
|
|
24
|
-
import '../_verture/unsupportedIterableToArray-cb478f24.js';
|
|
25
|
-
import '../_verture/typeof-6ec38efd.js';
|
|
26
21
|
import '@para-ui/core/GlobalContext';
|
|
27
22
|
import '@para-ui/icons/LoadingF';
|
|
28
23
|
import '../Tooltip/index.js';
|
|
@@ -35,6 +30,7 @@ import '../_verture/usePopupContainer-635f66f4.js';
|
|
|
35
30
|
import 'dayjs';
|
|
36
31
|
import '@paraview/lib';
|
|
37
32
|
import '../AutoTips/index.js';
|
|
33
|
+
import '../_verture/unsupportedIterableToArray-cb478f24.js';
|
|
38
34
|
import 'rc-slider';
|
|
39
35
|
import 'rc-dialog';
|
|
40
36
|
import '@para-ui/icons/Close';
|
|
@@ -47,50 +43,41 @@ import '@para-ui/icons/CloseCircleF';
|
|
|
47
43
|
var css_248z$4 = "@charset \"UTF-8\";\n/**\n* @author Hanz\n* @date 2021/11/11 下午3:08\n* @description\n*/\n/**\n* @author linhd\n* @date 2023/4/11 14:16\n* @description 最新色卡\n*/\n.paraui-v4-upload-list-text .upload-list-item {\n margin-top: 8px;\n}\n.paraui-v4-upload-list-text .upload-list-item-info {\n display: flex;\n align-items: center;\n padding: 0 8px;\n line-height: 28px;\n font-size: 14px;\n color: rgb(29, 33, 38);\n border-radius: 4px;\n transition: background-color 0.3s;\n}\n.paraui-v4-upload-list-text .upload-list-item-info .upload-list-text {\n position: relative;\n display: inline-flex;\n align-items: center;\n}\n.paraui-v4-upload-list-text .upload-list-item-info .upload-list-text .upload-list-fileicon {\n line-height: 0;\n opacity: 1;\n transition: opacity 0.3s;\n}\n.paraui-v4-upload-list-text .upload-list-item-info .upload-list-text .upload-list-fileicon svg {\n color: inherit;\n font-size: inherit;\n}\n.paraui-v4-upload-list-text .upload-list-item-info .upload-list-text-name {\n margin-left: 10px;\n}\n.paraui-v4-upload-list-text .upload-list-item-info .upload-list-text .upload-list-actions {\n position: absolute;\n left: 0;\n top: 50%;\n transform: translateY(-50%);\n z-index: -1;\n opacity: 0;\n visibility: hidden;\n line-height: 0;\n transition: opacity 0.3s;\n cursor: pointer;\n}\n.paraui-v4-upload-list-text .upload-list-item-info .upload-list-text .upload-list-actions svg {\n color: rgb(244, 66, 66);\n font-size: inherit;\n}\n.paraui-v4-upload-list-text .upload-list-item-info:hover {\n background-color: rgb(247, 248, 250);\n}\n.paraui-v4-upload-list-text .upload-list-item-info:hover .upload-list-text .upload-list-actions {\n visibility: visible;\n opacity: 1;\n z-index: 1;\n}\n.paraui-v4-upload-list-text .upload-list-item-info:hover .upload-list-text .upload-list-fileicon-active {\n opacity: 0;\n}\n.paraui-v4-upload-list-picture {\n display: inline-flex;\n align-items: center;\n}\n.paraui-v4-upload-list-picture .upload-list-picture-item {\n position: relative;\n display: inline-block;\n width: 100px;\n height: 100px;\n margin-right: 16px;\n border-radius: 4px;\n cursor: default;\n}\n.paraui-v4-upload-list-picture .upload-list-picture-item::before {\n content: \" \";\n position: absolute;\n left: 0;\n right: 0;\n bottom: 0;\n top: 0;\n background-color: rgb(29, 33, 38);\n border-radius: 4px;\n opacity: 0;\n transition: 0.3s;\n}\n.paraui-v4-upload-list-picture .upload-list-picture-item img {\n width: 100%;\n height: 100%;\n border-radius: 4px;\n}\n.paraui-v4-upload-list-picture .upload-list-picture-item .upload-list-picture-name {\n position: absolute;\n bottom: 0;\n left: 0;\n width: 100%;\n padding: 0 10px;\n font-size: 12px;\n line-height: 24px;\n text-align: center;\n text-overflow: ellipsis;\n overflow: hidden;\n white-space: nowrap;\n background-color: rgb(29, 33, 38);\n border-radius: 0 0 4px 4px;\n color: rgb(255, 255, 255);\n transition: 0.3s;\n}\n.paraui-v4-upload-list-picture .upload-list-picture-item .upload-list-actions {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n opacity: 0;\n line-height: 0;\n cursor: pointer;\n transition: 0.3s;\n}\n.paraui-v4-upload-list-picture .upload-list-picture-item .upload-list-actions svg {\n color: rgb(255, 255, 255);\n}\n.paraui-v4-upload-list-picture .upload-list-picture-item:hover:not(.upload-list-picture-item-readonly)::before {\n opacity: 1;\n}\n.paraui-v4-upload-list-picture .upload-list-picture-item:hover:not(.upload-list-picture-item-readonly) .upload-list-actions {\n opacity: 1;\n}\n.paraui-v4-upload-list-picture .upload-list-picture-item:hover:not(.upload-list-picture-item-readonly) .upload-list-picture-name {\n opacity: 0;\n}";
|
|
48
44
|
styleInject(css_248z$4);
|
|
49
45
|
|
|
50
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
51
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
52
|
-
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; }
|
|
53
46
|
//UploadList
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
listType =
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
var _useState = useState([]),
|
|
66
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
67
|
-
uploadList = _useState2[0],
|
|
68
|
-
setUploadList = _useState2[1];
|
|
47
|
+
const UploadList = props => {
|
|
48
|
+
const {
|
|
49
|
+
listType = 'text',
|
|
50
|
+
items = [],
|
|
51
|
+
onRemove,
|
|
52
|
+
showRemoveIcon = true,
|
|
53
|
+
removeIcon,
|
|
54
|
+
itemRender,
|
|
55
|
+
readonly
|
|
56
|
+
} = props;
|
|
57
|
+
const [uploadList, setUploadList] = useState([]);
|
|
69
58
|
//处理删除
|
|
70
|
-
|
|
59
|
+
const handleRemove = (file, evt) => {
|
|
71
60
|
evt.stopPropagation();
|
|
72
61
|
onRemove === null || onRemove === void 0 ? void 0 : onRemove(file);
|
|
73
62
|
};
|
|
74
63
|
//渲染列表actions
|
|
75
|
-
|
|
64
|
+
const renderActions = file => {
|
|
76
65
|
return showRemoveIcon && !readonly && jsx("span", Object.assign({
|
|
77
66
|
className: 'upload-list-actions',
|
|
78
|
-
onClick:
|
|
79
|
-
return handleRemove(file, evt);
|
|
80
|
-
}
|
|
67
|
+
onClick: evt => handleRemove(file, evt)
|
|
81
68
|
}, {
|
|
82
69
|
children: removeIcon || jsx(Delete, {})
|
|
83
70
|
}));
|
|
84
71
|
};
|
|
85
72
|
//文件列表 text
|
|
86
|
-
|
|
73
|
+
const renderFileListText = () => {
|
|
87
74
|
if (!(uploadList === null || uploadList === void 0 ? void 0 : uploadList.length)) return null;
|
|
88
|
-
return uploadList.map(
|
|
75
|
+
return uploadList.map((file, idx) => {
|
|
89
76
|
var _a;
|
|
90
77
|
if (itemRender)
|
|
91
78
|
//自定义渲染
|
|
92
79
|
return itemRender(file, uploadList);
|
|
93
|
-
|
|
80
|
+
const isImage = !!((_a = file.type) === null || _a === void 0 ? void 0 : _a.includes('image/'));
|
|
94
81
|
return jsx("div", Object.assign({
|
|
95
82
|
className: 'upload-list-item'
|
|
96
83
|
}, {
|
|
@@ -115,9 +102,9 @@ var UploadList = function UploadList(props) {
|
|
|
115
102
|
});
|
|
116
103
|
};
|
|
117
104
|
//文件列表 picture-card
|
|
118
|
-
|
|
105
|
+
const renderFileListPicture = () => {
|
|
119
106
|
if (!(uploadList === null || uploadList === void 0 ? void 0 : uploadList.length)) return null;
|
|
120
|
-
return uploadList.map(
|
|
107
|
+
return uploadList.map((file, idx) => {
|
|
121
108
|
if (itemRender)
|
|
122
109
|
//自定义渲染
|
|
123
110
|
return itemRender(file, uploadList);
|
|
@@ -137,84 +124,31 @@ var UploadList = function UploadList(props) {
|
|
|
137
124
|
});
|
|
138
125
|
};
|
|
139
126
|
//处理文件
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
} else resolve('');
|
|
166
|
-
}));
|
|
167
|
-
case 1:
|
|
168
|
-
case "end":
|
|
169
|
-
return _context.stop();
|
|
170
|
-
}
|
|
171
|
-
}, _callee);
|
|
172
|
-
}));
|
|
173
|
-
};
|
|
174
|
-
_iterator = _createForOfIteratorHelper(items);
|
|
175
|
-
_context2.prev = 4;
|
|
176
|
-
_iterator.s();
|
|
177
|
-
case 6:
|
|
178
|
-
if ((_step = _iterator.n()).done) {
|
|
179
|
-
_context2.next = 15;
|
|
180
|
-
break;
|
|
181
|
-
}
|
|
182
|
-
file = _step.value;
|
|
183
|
-
if (!file.originFileObj) {
|
|
184
|
-
_context2.next = 13;
|
|
185
|
-
break;
|
|
186
|
-
}
|
|
187
|
-
_context2.next = 11;
|
|
188
|
-
return readerFileAsDataUrl(file);
|
|
189
|
-
case 11:
|
|
190
|
-
dataUrl = _context2.sent;
|
|
191
|
-
file.dataUrl = dataUrl;
|
|
192
|
-
case 13:
|
|
193
|
-
_context2.next = 6;
|
|
194
|
-
break;
|
|
195
|
-
case 15:
|
|
196
|
-
_context2.next = 20;
|
|
197
|
-
break;
|
|
198
|
-
case 17:
|
|
199
|
-
_context2.prev = 17;
|
|
200
|
-
_context2.t0 = _context2["catch"](4);
|
|
201
|
-
_iterator.e(_context2.t0);
|
|
202
|
-
case 20:
|
|
203
|
-
_context2.prev = 20;
|
|
204
|
-
_iterator.f();
|
|
205
|
-
return _context2.finish(20);
|
|
206
|
-
case 23:
|
|
207
|
-
setUploadList(_toConsumableArray(items));
|
|
208
|
-
case 24:
|
|
209
|
-
case "end":
|
|
210
|
-
return _context2.stop();
|
|
211
|
-
}
|
|
212
|
-
}, _callee2, null, [[4, 17, 20, 23]]);
|
|
213
|
-
}));
|
|
214
|
-
};
|
|
215
|
-
useEffect(function () {
|
|
216
|
-
if (listType === 'picture-card') handleFileFormat();else setUploadList(function (pre) {
|
|
217
|
-
if (items) return _toConsumableArray(items);
|
|
127
|
+
const handleFileFormat = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
128
|
+
if (!(items === null || items === void 0 ? void 0 : items.length)) return setUploadList([]);
|
|
129
|
+
//读取file as DataUrl
|
|
130
|
+
const readerFileAsDataUrl = file => __awaiter(void 0, void 0, void 0, function* () {
|
|
131
|
+
return new Promise(resolve => {
|
|
132
|
+
const fileReader = new FileReader();
|
|
133
|
+
if (file.originFileObj) {
|
|
134
|
+
fileReader.onload = () => {
|
|
135
|
+
resolve(fileReader.result);
|
|
136
|
+
};
|
|
137
|
+
fileReader.readAsDataURL(file.originFileObj);
|
|
138
|
+
} else resolve('');
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
for (const file of items) {
|
|
142
|
+
if (file.originFileObj) {
|
|
143
|
+
const dataUrl = yield readerFileAsDataUrl(file);
|
|
144
|
+
file.dataUrl = dataUrl;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
setUploadList([...items]);
|
|
148
|
+
});
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
if (listType === 'picture-card') handleFileFormat();else setUploadList(pre => {
|
|
151
|
+
if (items) return [...items];
|
|
218
152
|
return pre;
|
|
219
153
|
});
|
|
220
154
|
}, [items]);
|
|
@@ -235,7 +169,7 @@ var css_248z$3 = "@charset \"UTF-8\";\n/**\n* @author Hanz\n* @date 2021/11/15
|
|
|
235
169
|
styleInject(css_248z$3);
|
|
236
170
|
|
|
237
171
|
//error tip
|
|
238
|
-
|
|
172
|
+
const ErrorTip = props => {
|
|
239
173
|
return jsxs("div", Object.assign({
|
|
240
174
|
className: clsx("".concat($prefixCls, "-upload-error"), props.className)
|
|
241
175
|
}, {
|
|
@@ -268,144 +202,99 @@ var zh = {
|
|
|
268
202
|
};
|
|
269
203
|
|
|
270
204
|
var localeJson = {
|
|
271
|
-
zh
|
|
272
|
-
en
|
|
205
|
+
zh,
|
|
206
|
+
en
|
|
273
207
|
};
|
|
274
208
|
|
|
275
209
|
var css_248z$2 = "@charset \"UTF-8\";\n/**\n* @author Hanz\n* @date 2021/11/11 下午7:31\n* @description\n*/\n/**\n* @author linhd\n* @date 2023/4/11 14:16\n* @description 最新色卡\n*/\n.paraui-v4-upload-image {\n display: inline-flex;\n align-items: center;\n /* &-border {\n .upload-image-select{\n border: 2px dashed $NA1;\n\n &:hover {\n border: 2px dashed $NPT8;\n }\n }\n } */\n}\n.paraui-v4-upload-image .upload-image-select {\n position: relative;\n width: 100px;\n height: 100px;\n cursor: pointer;\n background-color: rgb(247, 248, 250);\n border-radius: 4px;\n transition: 0.3s;\n}\n.paraui-v4-upload-image .upload-image-select-loading {\n pointer-events: none;\n}\n.paraui-v4-upload-image .upload-image-select .component-upload {\n display: inline-block;\n width: 100%;\n height: 100%;\n}\n.paraui-v4-upload-image .upload-image-select:hover .upload-image-picture-card {\n color: rgb(46, 101, 230);\n}\n.paraui-v4-upload-image .upload-image-picture-card {\n display: inline-flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n width: 100%;\n height: 100%;\n font-size: 14px;\n color: rgb(29, 33, 38);\n}\n.paraui-v4-upload-image .upload-image-picture-card .upload-img-wrapper {\n position: relative;\n width: 100%;\n height: 100%;\n cursor: default;\n}\n.paraui-v4-upload-image .upload-image-picture-card .upload-img-wrapper img {\n width: 100%;\n height: 100%;\n border-radius: 4px;\n}\n.paraui-v4-upload-image .upload-image-picture-card .upload-img-wrapper::before {\n position: absolute;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n content: \" \";\n background-color: rgb(29, 33, 38);\n border-radius: 4px;\n opacity: 0;\n transition: 0.3s;\n}\n.paraui-v4-upload-image .upload-image-picture-card .upload-img-wrapper-name {\n position: absolute;\n bottom: 0;\n left: 0;\n width: 100%;\n padding: 0 10px;\n overflow: hidden;\n font-size: 12px;\n line-height: 24px;\n color: rgb(255, 255, 255);\n text-align: center;\n text-overflow: ellipsis;\n white-space: nowrap;\n background-color: rgb(29, 33, 38);\n border-radius: 0 0 4px 4px;\n transition: 0.3s;\n}\n.paraui-v4-upload-image .upload-image-picture-card .upload-img-wrapper-action {\n position: absolute;\n top: 50%;\n left: 50%;\n line-height: 0;\n cursor: pointer;\n opacity: 0;\n transition: 0.3s;\n transform: translate(-50%, -50%);\n}\n.paraui-v4-upload-image .upload-image-picture-card .upload-img-wrapper-action svg {\n color: rgb(255, 255, 255);\n}\n.paraui-v4-upload-image .upload-image-picture-card .upload-img-wrapper:hover::before {\n opacity: 1;\n}\n.paraui-v4-upload-image .upload-image-picture-card .upload-img-wrapper:hover .upload-img-wrapper-name {\n opacity: 0;\n}\n.paraui-v4-upload-image .upload-image-picture-card .upload-img-wrapper:hover .upload-img-wrapper-action {\n opacity: 1;\n}\n.paraui-v4-upload-image .upload-image-picture-card .upload-image-icon {\n font-size: 30px;\n color: rgb(46, 101, 230);\n}\n.paraui-v4-upload-image .upload-image-picture-card .upload-image-loading {\n font-size: 30px;\n color: rgb(46, 101, 230);\n animation: imageLoadingCircle 1s infinite linear;\n}\n.paraui-v4-upload-image .upload-image-picture-card .upload-image-text {\n margin-top: 6px;\n color: inherit;\n text-align: center;\n transition: 0.3s;\n}\n.paraui-v4-upload-image .upload-image-picture-card .upload-image-text-loading {\n color: rgb(46, 101, 230);\n}\n@keyframes imageLoadingCircle {\n 100% {\n transform: rotate(360deg);\n }\n}";
|
|
276
210
|
styleInject(css_248z$2);
|
|
277
211
|
|
|
278
212
|
//ImageUpload
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
_props$loading = props.loading,
|
|
305
|
-
loading = _props$loading === void 0 ? false : _props$loading,
|
|
306
|
-
_props$showLoading = props.showLoading,
|
|
307
|
-
showLoadingProp = _props$showLoading === void 0 ? false : _props$showLoading,
|
|
308
|
-
defaultImage = props.defaultImage,
|
|
309
|
-
readonly = props.readonly,
|
|
213
|
+
const ImageUpload = props => {
|
|
214
|
+
const {
|
|
215
|
+
className,
|
|
216
|
+
style,
|
|
217
|
+
onStart,
|
|
218
|
+
onSuccess,
|
|
219
|
+
onError,
|
|
220
|
+
onProgress,
|
|
221
|
+
onRemove,
|
|
222
|
+
beforeUpload,
|
|
223
|
+
onChange,
|
|
224
|
+
defaultFileList = [],
|
|
225
|
+
fileList,
|
|
226
|
+
showUploadList = true,
|
|
227
|
+
maxCount,
|
|
228
|
+
children = null,
|
|
229
|
+
itemRender,
|
|
230
|
+
showUploadError = true,
|
|
231
|
+
stash = false,
|
|
232
|
+
uploading = true,
|
|
233
|
+
loading = false,
|
|
234
|
+
showLoading: showLoadingProp = false,
|
|
235
|
+
defaultImage,
|
|
236
|
+
readonly
|
|
237
|
+
} = props,
|
|
310
238
|
restProps = __rest(props, ["className", "style", "onStart", "onSuccess", "onError", "onProgress", "onRemove", "beforeUpload", "onChange", "defaultFileList", "fileList", "showUploadList", "maxCount", "children", "itemRender", "showUploadError", "stash", "uploading", "loading", "showLoading", "defaultImage", "readonly"]);
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
var _useState7 = useState({
|
|
325
|
-
imageUrl: ''
|
|
326
|
-
}),
|
|
327
|
-
_useState8 = _slicedToArray(_useState7, 2),
|
|
328
|
-
avatar = _useState8[0],
|
|
329
|
-
setAvatar = _useState8[1]; //不显示列表时上传头像
|
|
330
|
-
var _ref = typeof showUploadList === 'boolean' ? {} : showUploadList,
|
|
331
|
-
showRemoveIcon = _ref.showRemoveIcon,
|
|
332
|
-
removeIcon = _ref.removeIcon; //显示上传列表
|
|
333
|
-
var _ref2 = typeof showUploadError === 'boolean' ? {} : showUploadError,
|
|
334
|
-
_ref2$uploadErrorMsg = _ref2.uploadErrorMsg,
|
|
335
|
-
uploadErrorMsg = _ref2$uploadErrorMsg === void 0 ? intl({
|
|
239
|
+
const intl = useFormatMessage('Upload', localeJson);
|
|
240
|
+
const [uploadFileList, setUploadFileList] = useState(defaultFileList); //文件列表
|
|
241
|
+
const [showLoading, setShowLoading] = useState(false); //upload loading
|
|
242
|
+
const [errTip, setErrTip] = useState(false); //upload error tip
|
|
243
|
+
const [avatar, setAvatar] = useState({
|
|
244
|
+
imageUrl: ''
|
|
245
|
+
}); //不显示列表时上传头像
|
|
246
|
+
const {
|
|
247
|
+
showRemoveIcon,
|
|
248
|
+
removeIcon
|
|
249
|
+
} = typeof showUploadList === 'boolean' ? {} : showUploadList; //显示上传列表
|
|
250
|
+
const {
|
|
251
|
+
uploadErrorMsg = intl({
|
|
336
252
|
id: 'uploadError'
|
|
337
|
-
})
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
useEffect(
|
|
253
|
+
}),
|
|
254
|
+
leaveDelay = 2000
|
|
255
|
+
} = typeof showUploadError === 'boolean' ? {} : showUploadError; //错误信息提示
|
|
256
|
+
const cropFileRef = useRef(); //裁剪文件
|
|
257
|
+
useEffect(() => {
|
|
342
258
|
setShowLoading(loading);
|
|
343
259
|
}, [loading]);
|
|
344
260
|
//复写属性
|
|
345
|
-
|
|
261
|
+
const overrideProps = Object.assign(Object.assign({
|
|
346
262
|
accept: 'image/*'
|
|
347
263
|
}, restProps), {
|
|
348
|
-
beforeUpload:
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
}
|
|
363
|
-
setShowLoading(false);
|
|
364
|
-
return _context.abrupt("return", false);
|
|
365
|
-
case 9:
|
|
366
|
-
if (!(_typeof(result) === 'object' && result)) {
|
|
367
|
-
_context.next = 16;
|
|
368
|
-
break;
|
|
369
|
-
}
|
|
370
|
-
if (!(result instanceof File || result instanceof Blob)) {
|
|
371
|
-
_context.next = 12;
|
|
372
|
-
break;
|
|
373
|
-
}
|
|
374
|
-
return _context.abrupt("return", result);
|
|
375
|
-
case 12:
|
|
376
|
-
cropFileRef.current = result.cropFile;
|
|
377
|
-
return _context.abrupt("return", result.isUpload);
|
|
378
|
-
case 16:
|
|
379
|
-
return _context.abrupt("return", true);
|
|
380
|
-
case 17:
|
|
381
|
-
case "end":
|
|
382
|
-
return _context.stop();
|
|
383
|
-
}
|
|
384
|
-
}, _callee);
|
|
385
|
-
}));
|
|
386
|
-
},
|
|
387
|
-
onStart: function onStart(file) {
|
|
388
|
-
_onStart === null || _onStart === void 0 ? void 0 : _onStart(file);
|
|
264
|
+
beforeUpload: (file, fileList) => __awaiter(void 0, void 0, void 0, function* () {
|
|
265
|
+
if (restProps.action && showLoadingProp && uploading) setShowLoading(true);
|
|
266
|
+
const result = yield beforeUpload === null || beforeUpload === void 0 ? void 0 : beforeUpload(file, fileList);
|
|
267
|
+
if (result === false) {
|
|
268
|
+
setShowLoading(false);
|
|
269
|
+
return false;
|
|
270
|
+
} else if (typeof result === 'object' && result) {
|
|
271
|
+
if (result instanceof File || result instanceof Blob) return result;
|
|
272
|
+
cropFileRef.current = result.cropFile;
|
|
273
|
+
return result.isUpload;
|
|
274
|
+
} else return true;
|
|
275
|
+
}),
|
|
276
|
+
onStart(file) {
|
|
277
|
+
onStart === null || onStart === void 0 ? void 0 : onStart(file);
|
|
389
278
|
},
|
|
390
|
-
onSuccess
|
|
279
|
+
onSuccess(response, file, xhr) {
|
|
391
280
|
setShowLoading(false);
|
|
392
281
|
errTip && showErrTip(false);
|
|
393
|
-
|
|
282
|
+
const nextFileList = updateFileList(file);
|
|
394
283
|
onInternalChange(nextFileList);
|
|
395
|
-
|
|
284
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response, file, xhr);
|
|
396
285
|
},
|
|
397
|
-
onError
|
|
286
|
+
onError(error, response, file) {
|
|
398
287
|
setShowLoading(false);
|
|
399
288
|
showErrTip(!!showUploadError);
|
|
400
|
-
|
|
289
|
+
onError === null || onError === void 0 ? void 0 : onError(error, response, file);
|
|
401
290
|
},
|
|
402
|
-
onProgress
|
|
403
|
-
|
|
291
|
+
onProgress(e, file) {
|
|
292
|
+
onProgress === null || onProgress === void 0 ? void 0 : onProgress(e, file);
|
|
404
293
|
},
|
|
405
|
-
onBatchStart
|
|
294
|
+
onBatchStart(fileList) {
|
|
406
295
|
if (stash) {
|
|
407
296
|
if (cropFileRef.current) {
|
|
408
|
-
|
|
297
|
+
const idx = fileList.findIndex(_ => {
|
|
409
298
|
var _a;
|
|
410
299
|
return _.file.uid === ((_a = cropFileRef.current) === null || _a === void 0 ? void 0 : _a.uid);
|
|
411
300
|
});
|
|
@@ -416,62 +305,40 @@ var ImageUpload = function ImageUpload(props) {
|
|
|
416
305
|
});
|
|
417
306
|
}
|
|
418
307
|
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
});
|
|
422
|
-
var mList = mergedFileList(arr);
|
|
308
|
+
const arr = fileList.map(_ => _.parsedFile || _.file);
|
|
309
|
+
const mList = mergedFileList(arr);
|
|
423
310
|
onInternalChange(mList);
|
|
424
311
|
}
|
|
425
312
|
}
|
|
426
313
|
});
|
|
427
314
|
//内部变化
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
avatar.imageName = file.name;
|
|
452
|
-
setAvatar(Object.assign({}, avatar));
|
|
453
|
-
case 11:
|
|
454
|
-
onChange === null || onChange === void 0 ? void 0 : onChange([file]);
|
|
455
|
-
return _context2.abrupt("return");
|
|
456
|
-
case 13:
|
|
457
|
-
if (maxCount === 1) {
|
|
458
|
-
cloneList = cloneList.slice(-1);
|
|
459
|
-
} else if (maxCount) {
|
|
460
|
-
cloneList = cloneList.slice(0, maxCount);
|
|
461
|
-
}
|
|
462
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(cloneList);
|
|
463
|
-
setUploadFileList(cloneList);
|
|
464
|
-
case 16:
|
|
465
|
-
case "end":
|
|
466
|
-
return _context2.stop();
|
|
467
|
-
}
|
|
468
|
-
}, _callee2);
|
|
469
|
-
}));
|
|
470
|
-
};
|
|
315
|
+
const onInternalChange = changedFileList => __awaiter(void 0, void 0, void 0, function* () {
|
|
316
|
+
let cloneList = [...changedFileList];
|
|
317
|
+
if (!showUploadList) {
|
|
318
|
+
//不显示上传列表
|
|
319
|
+
const file = cloneList.slice(-1)[0];
|
|
320
|
+
if (file) {
|
|
321
|
+
const imageUrl = yield readerFileAsDataUrl(file);
|
|
322
|
+
file.dataUrl = imageUrl;
|
|
323
|
+
avatar.imageUrl = imageUrl;
|
|
324
|
+
avatar.imageName = file.name;
|
|
325
|
+
setAvatar(Object.assign({}, avatar));
|
|
326
|
+
}
|
|
327
|
+
onChange === null || onChange === void 0 ? void 0 : onChange([file]);
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
if (maxCount === 1) {
|
|
331
|
+
cloneList = cloneList.slice(-1);
|
|
332
|
+
} else if (maxCount) {
|
|
333
|
+
cloneList = cloneList.slice(0, maxCount);
|
|
334
|
+
}
|
|
335
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(cloneList);
|
|
336
|
+
setUploadFileList(cloneList);
|
|
337
|
+
});
|
|
471
338
|
//更新文件列表
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
339
|
+
const updateFileList = file => {
|
|
340
|
+
const cloneList = [...uploadFileList];
|
|
341
|
+
const fileObj = Object.assign(Object.assign({}, file), {
|
|
475
342
|
lastModified: file.lastModified,
|
|
476
343
|
lastModifiedDate: file.lastModifiedDate,
|
|
477
344
|
name: file.name,
|
|
@@ -483,9 +350,9 @@ var ImageUpload = function ImageUpload(props) {
|
|
|
483
350
|
return cloneList.concat(fileObj);
|
|
484
351
|
};
|
|
485
352
|
//合并文件列表
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
353
|
+
const mergedFileList = fileList => {
|
|
354
|
+
const cloneList = [...uploadFileList];
|
|
355
|
+
const newFileList = fileList.map(file => {
|
|
489
356
|
return Object.assign(Object.assign({}, file), {
|
|
490
357
|
lastModified: file.lastModified,
|
|
491
358
|
lastModifiedDate: file.lastModifiedDate,
|
|
@@ -499,71 +366,57 @@ var ImageUpload = function ImageUpload(props) {
|
|
|
499
366
|
return cloneList.concat(newFileList);
|
|
500
367
|
};
|
|
501
368
|
//删除文件
|
|
502
|
-
|
|
503
|
-
Promise.resolve(typeof onRemove === 'function' ? onRemove(file) : onRemove).then(
|
|
369
|
+
const handleRemove = file => {
|
|
370
|
+
Promise.resolve(typeof onRemove === 'function' ? onRemove(file) : onRemove).then(ret => {
|
|
504
371
|
// Prevent removing file
|
|
505
372
|
if (ret === false) return;
|
|
506
|
-
|
|
507
|
-
return _.uid === file.uid;
|
|
508
|
-
});
|
|
373
|
+
const idx = uploadFileList.findIndex(_ => _.uid === file.uid);
|
|
509
374
|
if (idx > -1) uploadFileList.splice(idx, 1);
|
|
510
375
|
onInternalChange(uploadFileList);
|
|
511
376
|
});
|
|
512
377
|
};
|
|
513
378
|
//读取dataUrl
|
|
514
|
-
|
|
515
|
-
return
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
fileReader.readAsDataURL(file.originFileObj);
|
|
526
|
-
} else resolve('');
|
|
527
|
-
}));
|
|
528
|
-
case 1:
|
|
529
|
-
case "end":
|
|
530
|
-
return _context3.stop();
|
|
531
|
-
}
|
|
532
|
-
}, _callee3);
|
|
533
|
-
}));
|
|
534
|
-
};
|
|
379
|
+
const readerFileAsDataUrl = file => __awaiter(void 0, void 0, void 0, function* () {
|
|
380
|
+
return new Promise(resolve => {
|
|
381
|
+
const fileReader = new FileReader();
|
|
382
|
+
if (file.originFileObj) {
|
|
383
|
+
fileReader.onload = () => {
|
|
384
|
+
resolve(fileReader.result);
|
|
385
|
+
};
|
|
386
|
+
fileReader.readAsDataURL(file.originFileObj);
|
|
387
|
+
} else resolve('');
|
|
388
|
+
});
|
|
389
|
+
});
|
|
535
390
|
//显示错误提示
|
|
536
|
-
|
|
391
|
+
const showErrTip = flag => {
|
|
537
392
|
setErrTip(flag);
|
|
538
393
|
if (leaveDelay < 0) return;
|
|
539
|
-
setTimeout(
|
|
394
|
+
setTimeout(() => {
|
|
540
395
|
setErrTip(false);
|
|
541
396
|
}, leaveDelay);
|
|
542
397
|
};
|
|
543
|
-
useEffect(
|
|
398
|
+
useEffect(() => {
|
|
544
399
|
if (fileList) {
|
|
545
|
-
setUploadFileList(
|
|
400
|
+
setUploadFileList([...fileList]);
|
|
546
401
|
}
|
|
547
402
|
}, [fileList]);
|
|
548
|
-
useEffect(
|
|
403
|
+
useEffect(() => {
|
|
549
404
|
if (defaultImage) {
|
|
550
405
|
setAvatar(Object.assign({}, defaultImage));
|
|
551
406
|
}
|
|
552
407
|
}, [defaultImage]);
|
|
553
408
|
//渲染上传列表
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
});
|
|
564
|
-
};
|
|
409
|
+
const renderUploadList = () => showUploadList && jsx(UploadList, {
|
|
410
|
+
listType: 'picture-card',
|
|
411
|
+
readonly: readonly,
|
|
412
|
+
items: uploadFileList,
|
|
413
|
+
showRemoveIcon: showRemoveIcon,
|
|
414
|
+
removeIcon: removeIcon,
|
|
415
|
+
onRemove: handleRemove,
|
|
416
|
+
itemRender: itemRender
|
|
417
|
+
});
|
|
565
418
|
//渲染内容
|
|
566
|
-
|
|
419
|
+
const renderUploadContent = () => {
|
|
567
420
|
var _a;
|
|
568
421
|
if (!showUploadList && avatar.imageUrl && !showLoading) {
|
|
569
422
|
return jsxs("div", Object.assign({
|
|
@@ -598,7 +451,7 @@ var ImageUpload = function ImageUpload(props) {
|
|
|
598
451
|
});
|
|
599
452
|
};
|
|
600
453
|
//渲染上传控件
|
|
601
|
-
|
|
454
|
+
const renderUploadSelector = () => {
|
|
602
455
|
if (readonly) return null;
|
|
603
456
|
return jsxs("div", Object.assign({
|
|
604
457
|
className: clsx('upload-image-select', showLoading && 'upload-image-select-loading')
|
|
@@ -626,7 +479,7 @@ var ImageUpload = function ImageUpload(props) {
|
|
|
626
479
|
};
|
|
627
480
|
|
|
628
481
|
//Dragger upload
|
|
629
|
-
|
|
482
|
+
const Dragger = props => {
|
|
630
483
|
return jsx(Upload, Object.assign({}, props, {
|
|
631
484
|
type: 'drag'
|
|
632
485
|
}));
|
|
@@ -791,336 +644,266 @@ var css_248z$1 = "@charset \"UTF-8\";\n/**\n* @author Hanz\n* @date 2022/4/20
|
|
|
791
644
|
styleInject(css_248z$1);
|
|
792
645
|
|
|
793
646
|
//图片裁剪组件
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
aspect =
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
modalCancel = props.modalCancel,
|
|
817
|
-
onModalOk = props.onModalOk,
|
|
818
|
-
onModalCancel = props.onModalCancel,
|
|
819
|
-
beforeCrop = props.beforeCrop,
|
|
820
|
-
onUploadFail = props.onUploadFail,
|
|
821
|
-
cropperProps = props.cropperProps,
|
|
822
|
-
children = props.children,
|
|
823
|
-
_props$fixedCropSize = props.fixedCropSize,
|
|
824
|
-
fixedCropSize = _props$fixedCropSize === void 0 ? {
|
|
647
|
+
const ImgCrop = /*#__PURE__*/forwardRef((props, ref) => {
|
|
648
|
+
const {
|
|
649
|
+
aspect = 1,
|
|
650
|
+
shape = 'rect',
|
|
651
|
+
grid = false,
|
|
652
|
+
quality = 0.4,
|
|
653
|
+
fillColor = 'transparent',
|
|
654
|
+
zoom = true,
|
|
655
|
+
rotate = false,
|
|
656
|
+
minZoom = 1,
|
|
657
|
+
maxZoom = 3,
|
|
658
|
+
modalTitle,
|
|
659
|
+
modalWidth,
|
|
660
|
+
modalOk,
|
|
661
|
+
modalCancel,
|
|
662
|
+
onModalOk,
|
|
663
|
+
onModalCancel,
|
|
664
|
+
beforeCrop,
|
|
665
|
+
onUploadFail,
|
|
666
|
+
cropperProps,
|
|
667
|
+
children,
|
|
668
|
+
fixedCropSize = {
|
|
825
669
|
width: 120,
|
|
826
670
|
height: 120
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
var resolveRef = useRef();
|
|
836
|
-
var rejectRef = useRef();
|
|
671
|
+
}
|
|
672
|
+
} = props;
|
|
673
|
+
const intl = useFormatMessage('Upload', localeJson);
|
|
674
|
+
const [image, setImage] = useState('');
|
|
675
|
+
const fileRef = useRef();
|
|
676
|
+
const beforeUploadRef = useRef();
|
|
677
|
+
const resolveRef = useRef();
|
|
678
|
+
const rejectRef = useRef();
|
|
837
679
|
//存储回调
|
|
838
|
-
|
|
680
|
+
const cbRef = useRef({});
|
|
839
681
|
cbRef.current.onModalOk = onModalOk;
|
|
840
682
|
cbRef.current.onModalCancel = onModalCancel;
|
|
841
683
|
cbRef.current.beforeCrop = beforeCrop;
|
|
842
684
|
cbRef.current.onUploadFail = onUploadFail;
|
|
843
|
-
|
|
685
|
+
const easyCropRef = useRef({});
|
|
844
686
|
//上传组件
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
687
|
+
const uploadComponent = useMemo(() => {
|
|
688
|
+
const upload = Array.isArray(children) ? children[0] : children;
|
|
689
|
+
const _a = upload.props,
|
|
690
|
+
{
|
|
691
|
+
beforeUpload,
|
|
692
|
+
accept
|
|
693
|
+
} = _a,
|
|
850
694
|
restUploadProps = __rest(_a, ["beforeUpload", "accept"]);
|
|
851
695
|
beforeUploadRef.current = beforeUpload;
|
|
852
696
|
return Object.assign(Object.assign({}, upload), {
|
|
853
697
|
props: Object.assign(Object.assign({}, restUploadProps), {
|
|
854
698
|
accept: accept || 'image/*',
|
|
855
|
-
beforeUpload:
|
|
856
|
-
return new Promise(
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
return
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
var flag = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
882
|
-
var _a, _b;
|
|
883
|
-
(_b = (_a = cbRef.current).onModalOk) === null || _b === void 0 ? void 0 : _b.call(_a, newFile);
|
|
884
|
-
if (!flag) return resolve({
|
|
885
|
-
cropFile: newFile,
|
|
886
|
-
isUpload: flag
|
|
887
|
-
});
|
|
888
|
-
resolve(newFile);
|
|
889
|
-
};
|
|
890
|
-
rejectRef.current = function (uploadErr) {
|
|
891
|
-
var _a, _b;
|
|
892
|
-
(_b = (_a = cbRef.current).onUploadFail) === null || _b === void 0 ? void 0 : _b.call(_a, uploadErr);
|
|
893
|
-
reject(uploadErr);
|
|
894
|
-
};
|
|
895
|
-
reader = new FileReader();
|
|
896
|
-
reader.addEventListener('load', function () {
|
|
897
|
-
return typeof reader.result === 'string' && setImage(reader.result);
|
|
898
|
-
});
|
|
899
|
-
reader.readAsDataURL(file);
|
|
900
|
-
case 14:
|
|
901
|
-
case "end":
|
|
902
|
-
return _context.stop();
|
|
903
|
-
}
|
|
904
|
-
}, _callee);
|
|
905
|
-
}));
|
|
906
|
-
});
|
|
699
|
+
beforeUpload: (file, fileList) => {
|
|
700
|
+
return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
701
|
+
if (cbRef.current.beforeCrop && !(yield cbRef.current.beforeCrop(file, fileList))) {
|
|
702
|
+
reject();
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
fileRef.current = file;
|
|
706
|
+
resolveRef.current = function (newFile) {
|
|
707
|
+
let flag = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
708
|
+
var _a, _b;
|
|
709
|
+
(_b = (_a = cbRef.current).onModalOk) === null || _b === void 0 ? void 0 : _b.call(_a, newFile);
|
|
710
|
+
if (!flag) return resolve({
|
|
711
|
+
cropFile: newFile,
|
|
712
|
+
isUpload: flag
|
|
713
|
+
});
|
|
714
|
+
resolve(newFile);
|
|
715
|
+
};
|
|
716
|
+
rejectRef.current = uploadErr => {
|
|
717
|
+
var _a, _b;
|
|
718
|
+
(_b = (_a = cbRef.current).onUploadFail) === null || _b === void 0 ? void 0 : _b.call(_a, uploadErr);
|
|
719
|
+
reject(uploadErr);
|
|
720
|
+
};
|
|
721
|
+
const reader = new FileReader();
|
|
722
|
+
reader.addEventListener('load', () => typeof reader.result === 'string' && setImage(reader.result));
|
|
723
|
+
reader.readAsDataURL(file);
|
|
724
|
+
}));
|
|
907
725
|
}
|
|
908
726
|
})
|
|
909
727
|
});
|
|
910
728
|
}, [children]);
|
|
911
729
|
//modal 关闭后操作
|
|
912
|
-
|
|
730
|
+
const onClose = () => {
|
|
913
731
|
setImage('');
|
|
914
732
|
easyCropRef.current.setZoomVal(INIT_ZOOM);
|
|
915
733
|
easyCropRef.current.setRotateVal(INIT_ROTATE);
|
|
916
734
|
};
|
|
917
735
|
//modal cancel
|
|
918
|
-
|
|
736
|
+
const onCancel = useCallback(() => {
|
|
919
737
|
var _a, _b;
|
|
920
738
|
(_b = (_a = cbRef.current).onModalCancel) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
921
739
|
onClose();
|
|
922
740
|
}, []);
|
|
923
741
|
//modal ok
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
case 14:
|
|
1054
|
-
if (!(res && res instanceof Promise)) {
|
|
1055
|
-
_context2.next = 27;
|
|
1056
|
-
break;
|
|
1057
|
-
}
|
|
1058
|
-
_context2.prev = 15;
|
|
1059
|
-
_context2.next = 18;
|
|
1060
|
-
return res;
|
|
1061
|
-
case 18:
|
|
1062
|
-
passedFile = _context2.sent;
|
|
1063
|
-
if (!(passedFile instanceof File || passedFile instanceof Blob)) {
|
|
1064
|
-
_context2.next = 21;
|
|
1065
|
-
break;
|
|
1066
|
-
}
|
|
1067
|
-
return _context2.abrupt("return", (_d = resolveRef.current) === null || _d === void 0 ? void 0 : _d.call(resolveRef, passedFile));
|
|
1068
|
-
case 21:
|
|
1069
|
-
(_e = resolveRef.current) === null || _e === void 0 ? void 0 : _e.call(resolveRef, changeFile, passedFile);
|
|
1070
|
-
_context2.next = 27;
|
|
1071
|
-
break;
|
|
1072
|
-
case 24:
|
|
1073
|
-
_context2.prev = 24;
|
|
1074
|
-
_context2.t0 = _context2["catch"](15);
|
|
1075
|
-
(_f = rejectRef.current) === null || _f === void 0 ? void 0 : _f.call(rejectRef, _context2.t0);
|
|
1076
|
-
case 27:
|
|
1077
|
-
case "end":
|
|
1078
|
-
return _context2.stop();
|
|
1079
|
-
}
|
|
1080
|
-
}, _callee2, null, [[15, 24]]);
|
|
1081
|
-
}));
|
|
1082
|
-
};
|
|
1083
|
-
canvas.toBlob(onBlob, type, quality);
|
|
1084
|
-
case 11:
|
|
1085
|
-
case "end":
|
|
1086
|
-
return _context3.stop();
|
|
742
|
+
const onOk = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
743
|
+
onClose();
|
|
744
|
+
const canvas = document.createElement('canvas');
|
|
745
|
+
const ctx = canvas.getContext('2d');
|
|
746
|
+
const imgSource = document.querySelector(".".concat(PREFIX, "-media"));
|
|
747
|
+
const {
|
|
748
|
+
width: cropWidth,
|
|
749
|
+
height: cropHeight,
|
|
750
|
+
x: cropX,
|
|
751
|
+
y: cropY
|
|
752
|
+
} = easyCropRef.current.cropPixelsRef.current;
|
|
753
|
+
if (rotate && easyCropRef.current.rotateVal !== INIT_ROTATE) {
|
|
754
|
+
const {
|
|
755
|
+
naturalWidth: imgWidth,
|
|
756
|
+
naturalHeight: imgHeight
|
|
757
|
+
} = imgSource;
|
|
758
|
+
const angle = easyCropRef.current.rotateVal * (Math.PI / 180);
|
|
759
|
+
// get container for rotated image
|
|
760
|
+
const sine = Math.abs(Math.sin(angle));
|
|
761
|
+
const cosine = Math.abs(Math.cos(angle));
|
|
762
|
+
const squareWidth = imgWidth * cosine + imgHeight * sine;
|
|
763
|
+
const squareHeight = imgHeight * cosine + imgWidth * sine;
|
|
764
|
+
canvas.width = squareWidth;
|
|
765
|
+
canvas.height = squareHeight;
|
|
766
|
+
ctx.fillStyle = fillColor;
|
|
767
|
+
ctx.fillRect(0, 0, squareWidth, squareHeight);
|
|
768
|
+
// rotate container
|
|
769
|
+
const squareHalfWidth = squareWidth / 2;
|
|
770
|
+
const squareHalfHeight = squareHeight / 2;
|
|
771
|
+
ctx.translate(squareHalfWidth, squareHalfHeight);
|
|
772
|
+
ctx.rotate(angle);
|
|
773
|
+
ctx.translate(-squareHalfWidth, -squareHalfHeight);
|
|
774
|
+
// draw rotated image
|
|
775
|
+
const imgX = (squareWidth - imgWidth) / 2;
|
|
776
|
+
const imgY = (squareHeight - imgHeight) / 2;
|
|
777
|
+
ctx.drawImage(imgSource, 0, 0, imgWidth, imgHeight, imgX, imgY, imgWidth, imgHeight);
|
|
778
|
+
// crop rotated image
|
|
779
|
+
const imgData = ctx.getImageData(0, 0, squareWidth, squareHeight);
|
|
780
|
+
canvas.width = cropWidth;
|
|
781
|
+
canvas.height = cropHeight;
|
|
782
|
+
ctx.putImageData(imgData, -cropX, -cropY);
|
|
783
|
+
} else {
|
|
784
|
+
canvas.width = cropWidth;
|
|
785
|
+
canvas.height = cropHeight;
|
|
786
|
+
ctx.fillStyle = fillColor;
|
|
787
|
+
ctx.fillRect(0, 0, cropWidth, cropHeight);
|
|
788
|
+
ctx.drawImage(imgSource, cropX, cropY, cropWidth, cropHeight, 0, 0, cropWidth, cropHeight);
|
|
789
|
+
}
|
|
790
|
+
//裁剪之后改变图片大小
|
|
791
|
+
const changeImageSizeAfterCrop = newFile => {
|
|
792
|
+
return new Promise(resolve => {
|
|
793
|
+
const {
|
|
794
|
+
name,
|
|
795
|
+
type,
|
|
796
|
+
uid
|
|
797
|
+
} = newFile;
|
|
798
|
+
const {
|
|
799
|
+
width,
|
|
800
|
+
height
|
|
801
|
+
} = fixedCropSize; //固定裁剪大小
|
|
802
|
+
const changeCanvas = document.createElement('canvas');
|
|
803
|
+
const changeCtx = changeCanvas.getContext('2d');
|
|
804
|
+
const img = new Image();
|
|
805
|
+
img.onload = () => {
|
|
806
|
+
changeCanvas.width = width;
|
|
807
|
+
changeCanvas.height = height;
|
|
808
|
+
changeCtx.drawImage(img, 0, 0, width, height);
|
|
809
|
+
changeCanvas.toBlob(cBlob => {
|
|
810
|
+
const changeFile = Object.assign(new File([cBlob], name, {
|
|
811
|
+
type
|
|
812
|
+
}), {
|
|
813
|
+
uid
|
|
814
|
+
});
|
|
815
|
+
resolve(changeFile);
|
|
816
|
+
}, type, quality);
|
|
817
|
+
};
|
|
818
|
+
img.onerror = () => {
|
|
819
|
+
resolve(newFile);
|
|
820
|
+
};
|
|
821
|
+
const fileReader = new FileReader();
|
|
822
|
+
fileReader.onload = () => {
|
|
823
|
+
img.src = fileReader.result;
|
|
824
|
+
};
|
|
825
|
+
fileReader.onerror = () => {
|
|
826
|
+
resolve(newFile);
|
|
827
|
+
};
|
|
828
|
+
fileReader.readAsDataURL(newFile);
|
|
829
|
+
});
|
|
830
|
+
};
|
|
831
|
+
// get the new image
|
|
832
|
+
let {
|
|
833
|
+
type,
|
|
834
|
+
name,
|
|
835
|
+
uid
|
|
836
|
+
} = fileRef.current;
|
|
837
|
+
if (/svg/gi.test(type)) {
|
|
838
|
+
//svg 转为 png
|
|
839
|
+
type = 'image/png';
|
|
840
|
+
const idx = name.lastIndexOf('.');
|
|
841
|
+
if (idx > -1) name = "".concat(name.substring(0, idx), ".png");
|
|
842
|
+
}
|
|
843
|
+
//转为blob
|
|
844
|
+
const onBlob = blob => __awaiter(void 0, void 0, void 0, function* () {
|
|
845
|
+
var _a, _b, _c, _d, _e, _f;
|
|
846
|
+
const newFile = Object.assign(new File([blob], name, {
|
|
847
|
+
type
|
|
848
|
+
}), {
|
|
849
|
+
uid
|
|
850
|
+
});
|
|
851
|
+
const changeFile = yield changeImageSizeAfterCrop(newFile);
|
|
852
|
+
if (typeof beforeUploadRef.current !== 'function') {
|
|
853
|
+
return (_a = resolveRef.current) === null || _a === void 0 ? void 0 : _a.call(resolveRef, changeFile);
|
|
854
|
+
}
|
|
855
|
+
const res = beforeUploadRef.current(changeFile, [changeFile]);
|
|
856
|
+
if (typeof res !== 'boolean' && !res) {
|
|
857
|
+
console.error('beforeUpload must return a boolean or Promise');
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
860
|
+
if (res === true) return (_b = resolveRef.current) === null || _b === void 0 ? void 0 : _b.call(resolveRef, changeFile);
|
|
861
|
+
if (res === false) return (_c = resolveRef.current) === null || _c === void 0 ? void 0 : _c.call(resolveRef, changeFile, false);
|
|
862
|
+
if (res && res instanceof Promise) {
|
|
863
|
+
try {
|
|
864
|
+
const passedFile = yield res;
|
|
865
|
+
if (passedFile instanceof File || passedFile instanceof Blob) {
|
|
866
|
+
return (_d = resolveRef.current) === null || _d === void 0 ? void 0 : _d.call(resolveRef, passedFile);
|
|
867
|
+
}
|
|
868
|
+
(_e = resolveRef.current) === null || _e === void 0 ? void 0 : _e.call(resolveRef, changeFile, passedFile);
|
|
869
|
+
} catch (err) {
|
|
870
|
+
(_f = rejectRef.current) === null || _f === void 0 ? void 0 : _f.call(rejectRef, err);
|
|
1087
871
|
}
|
|
1088
|
-
}
|
|
1089
|
-
}));
|
|
1090
|
-
}, [fillColor, quality, rotate]);
|
|
1091
|
-
//img crop 组件
|
|
1092
|
-
var getComponent = function getComponent(titleOfModal) {
|
|
1093
|
-
return jsxs(Fragment, {
|
|
1094
|
-
children: [uploadComponent, image && jsx(Modal, Object.assign({
|
|
1095
|
-
open: true,
|
|
1096
|
-
className: "".concat(PREFIX, "-modal"),
|
|
1097
|
-
size: 'md',
|
|
1098
|
-
title: titleOfModal !== null && titleOfModal !== void 0 ? titleOfModal : intl({
|
|
1099
|
-
id: 'editImage'
|
|
1100
|
-
}),
|
|
1101
|
-
onOk: onOk,
|
|
1102
|
-
onCancel: onCancel,
|
|
1103
|
-
okText: modalOk,
|
|
1104
|
-
cancelText: modalCancel,
|
|
1105
|
-
contentWidth: modalWidth
|
|
1106
|
-
}, {
|
|
1107
|
-
children: jsx(EasyCrop$1, {
|
|
1108
|
-
ref: easyCropRef,
|
|
1109
|
-
cropperRef: ref,
|
|
1110
|
-
image: image,
|
|
1111
|
-
aspect: aspect,
|
|
1112
|
-
shape: shape,
|
|
1113
|
-
grid: grid,
|
|
1114
|
-
zoom: zoom,
|
|
1115
|
-
rotate: rotate,
|
|
1116
|
-
minZoom: minZoom,
|
|
1117
|
-
maxZoom: maxZoom,
|
|
1118
|
-
fixedCropSize: fixedCropSize,
|
|
1119
|
-
cropperProps: cropperProps
|
|
1120
|
-
})
|
|
1121
|
-
}))]
|
|
872
|
+
}
|
|
1122
873
|
});
|
|
1123
|
-
|
|
874
|
+
canvas.toBlob(onBlob, type, quality);
|
|
875
|
+
}), [fillColor, quality, rotate]);
|
|
876
|
+
//img crop 组件
|
|
877
|
+
const getComponent = titleOfModal => jsxs(Fragment, {
|
|
878
|
+
children: [uploadComponent, image && jsx(Modal, Object.assign({
|
|
879
|
+
open: true,
|
|
880
|
+
className: "".concat(PREFIX, "-modal"),
|
|
881
|
+
size: 'md',
|
|
882
|
+
title: titleOfModal !== null && titleOfModal !== void 0 ? titleOfModal : intl({
|
|
883
|
+
id: 'editImage'
|
|
884
|
+
}),
|
|
885
|
+
onOk: onOk,
|
|
886
|
+
onCancel: onCancel,
|
|
887
|
+
okText: modalOk,
|
|
888
|
+
cancelText: modalCancel,
|
|
889
|
+
contentWidth: modalWidth
|
|
890
|
+
}, {
|
|
891
|
+
children: jsx(EasyCrop$1, {
|
|
892
|
+
ref: easyCropRef,
|
|
893
|
+
cropperRef: ref,
|
|
894
|
+
image: image,
|
|
895
|
+
aspect: aspect,
|
|
896
|
+
shape: shape,
|
|
897
|
+
grid: grid,
|
|
898
|
+
zoom: zoom,
|
|
899
|
+
rotate: rotate,
|
|
900
|
+
minZoom: minZoom,
|
|
901
|
+
maxZoom: maxZoom,
|
|
902
|
+
fixedCropSize: fixedCropSize,
|
|
903
|
+
cropperProps: cropperProps
|
|
904
|
+
})
|
|
905
|
+
}))]
|
|
906
|
+
});
|
|
1124
907
|
return jsx(Fragment, {
|
|
1125
908
|
children: getComponent(modalTitle)
|
|
1126
909
|
});
|