@para-ui/core 4.0.28 → 4.0.30
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/ContentBox/index.d.ts +33 -0
- package/ContentBox/index.js +89 -0
- package/README.md +7 -0
- package/RangeInput/index.d.ts +55 -0
- package/RangeInput/index.js +169 -0
- package/Transfer/index.js +49 -43
- package/Upload/index.js +756 -479
- package/index.d.ts +4 -0
- package/index.js +2 -0
- package/package.json +1 -1
- package/umd/ContentBox.js +28 -0
- package/umd/RangeInput.js +43 -0
package/Upload/index.js
CHANGED
|
@@ -5,6 +5,10 @@ import RcUpload from 'rc-upload';
|
|
|
5
5
|
import clsx from 'clsx';
|
|
6
6
|
import UploadIcon from '@para-ui/icons/UploadFile';
|
|
7
7
|
import LoadingIcon from '@para-ui/icons/Loading';
|
|
8
|
+
import { _ as _toConsumableArray } from '../_verture/toConsumableArray-8f4c9589.js';
|
|
9
|
+
import { _ as _typeof } from '../_verture/defineProperty-f0e15205.js';
|
|
10
|
+
import { _ as _slicedToArray } from '../_verture/slicedToArray-a8206399.js';
|
|
11
|
+
import { r as regenerator } from '../_verture/index-8ac46bd9.js';
|
|
8
12
|
import EditOutline from '@para-ui/icons/EditOutline';
|
|
9
13
|
import Delete from '@para-ui/icons/Delete';
|
|
10
14
|
import FileOutlined from '@para-ui/icons/Document';
|
|
@@ -20,7 +24,6 @@ import { s as styleInject } from '../_verture/style-inject.es-300983ab.js';
|
|
|
20
24
|
import Forbid from '@para-ui/icons/Forbid';
|
|
21
25
|
import { u as useFormatMessage } from '../_verture/useFormatMessage-1fc7c957.js';
|
|
22
26
|
import { Button } from '../Button/index.js';
|
|
23
|
-
import { _ as _slicedToArray } from '../_verture/slicedToArray-a8206399.js';
|
|
24
27
|
import Cropper from 'react-easy-crop';
|
|
25
28
|
import PlusCircle from '@para-ui/icons/PlusCircle';
|
|
26
29
|
import MinusCircle from '@para-ui/icons/MinusCircle';
|
|
@@ -28,14 +31,13 @@ import TurnRight from '@para-ui/icons/TurnRight';
|
|
|
28
31
|
import TurnLeft from '@para-ui/icons/TurnLeft';
|
|
29
32
|
import { Slider } from '../Slider/index.js';
|
|
30
33
|
import { Modal } from '../Modal/index.js';
|
|
34
|
+
import '../_verture/unsupportedIterableToArray-cb478f24.js';
|
|
35
|
+
import '../_verture/typeof-6ec38efd.js';
|
|
31
36
|
import 'rc-tooltip';
|
|
32
37
|
import 'rc-tooltip/lib/placements';
|
|
33
38
|
import '@paraview/lib';
|
|
34
39
|
import '../_verture/Portal-5bf66fed.js';
|
|
35
40
|
import 'react-dom';
|
|
36
|
-
import '../_verture/defineProperty-f0e15205.js';
|
|
37
|
-
import '../_verture/toConsumableArray-8f4c9589.js';
|
|
38
|
-
import '../_verture/unsupportedIterableToArray-cb478f24.js';
|
|
39
41
|
import 'rc-dialog';
|
|
40
42
|
import 'rc-motion';
|
|
41
43
|
import '@para-ui/icons/Sort';
|
|
@@ -91,7 +93,11 @@ var isImageUrl = function isImageUrl(file) {
|
|
|
91
93
|
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: 10px;\n position: relative;\n}\n.paraui-v4-upload-list-text .upload-list-item-info {\n display: flex;\n align-items: center;\n line-height: 30px;\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 width: 440px;\n height: 30px;\n background-color: rgb(247, 248, 250);\n border-radius: 4px;\n}\n.paraui-v4-upload-list-text .upload-list-item-info .upload-list-text .upload-list-text-item {\n display: flex;\n align-items: center;\n flex: 1;\n padding-left: 10px;\n max-width: 76%;\n}\n.paraui-v4-upload-list-text .upload-list-item-info .upload-list-text .upload-list-text-item .upload-list-text-name {\n margin-left: 8px;\n}\n.paraui-v4-upload-list-text .upload-list-item-info .upload-list-text .upload-list-text-item .upload-list-text-name {\n color: rgb(29, 33, 38);\n text-decoration: none;\n}\n.paraui-v4-upload-list-text .upload-list-item-info .upload-list-text .upload-list-text-item .upload-list-text-name:hover {\n color: rgb(46, 101, 230);\n}\n.paraui-v4-upload-list-text .upload-list-item-info .upload-list-text .upload-list-text-item-error {\n color: rgb(244, 66, 66);\n cursor: pointer;\n}\n.paraui-v4-upload-list-text .upload-list-item-info .upload-list-text .upload-list-text-item-error .upload-list-text-name,\n.paraui-v4-upload-list-text .upload-list-item-info .upload-list-text .upload-list-text-item-error .upload-list-text-name:hover {\n color: rgb(244, 66, 66);\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: 18px;\n}\n.paraui-v4-upload-list-text .upload-list-item-info .upload-list-text .upload-list-actions svg {\n font-size: 18px;\n}\n.paraui-v4-upload-list-text .upload-list-item-info .upload-list-text .upload-list-actions svg:hover {\n background-color: rgb(234, 236, 241);\n border-radius: 2px;\n}\n.paraui-v4-upload-list-text .upload-list-item .upload-list-actions {\n margin-left: auto;\n margin-right: 10px;\n}\n.paraui-v4-upload-list-text .upload-list-item .upload-list-actions > span {\n display: flex;\n align-items: center;\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-error {\n width: 100%;\n height: 100%;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n background: rgb(247, 248, 250);\n border: 1px dashed rgb(246, 103, 103);\n border-radius: 4px;\n color: rgb(246, 103, 103);\n}\n.paraui-v4-upload-list-picture .upload-list-picture-error > svg {\n font-size: 30px;\n color: rgb(244, 66, 66);\n margin-bottom: 6px;\n}\n.paraui-v4-upload-list-picture .upload-list-picture-error-name {\n font-size: 14px;\n color: rgb(244, 66, 66);\n padding: 0 10px;\n width: 100%;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n text-align: 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 overflow: hidden;\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: rgba(29, 33, 38, 0.9);\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-file {\n font-size: 100px;\n}\n.paraui-v4-upload-list-picture .upload-list-picture-item .upload-list-picture-filea {\n fill: none;\n}\n.paraui-v4-upload-list-picture .upload-list-picture-item .upload-list-picture-fileb {\n opacity: 0.4;\n}\n.paraui-v4-upload-list-picture .upload-list-picture-item .upload-list-picture-filec {\n fill: #2e65e6;\n}\n.paraui-v4-upload-list-picture .upload-list-picture-item .upload-list-picture-filed {\n fill: #5783eb;\n}\n.paraui-v4-upload-list-picture .upload-list-picture-item .upload-list-picture-filee {\n fill: #ffb900;\n}\n.paraui-v4-upload-list-picture .upload-list-picture-item .upload-list-picture-filef {\n fill: #fff;\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: rgba(29, 33, 38, 0.9);\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 transition: all 0.3s;\n}\n.paraui-v4-upload-list-picture .upload-list-picture-item .upload-list-actions svg:hover {\n background-color: rgba(255, 255, 255, 0.3);\n border-radius: 2px;\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}\n\n.paraui-v4-upload-drag .paraui-v4-upload-list-text .upload-list-item-info .upload-list-text {\n width: 590px;\n}";
|
|
92
94
|
styleInject(css_248z$4);
|
|
93
95
|
|
|
94
|
-
|
|
96
|
+
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; } } }; }
|
|
97
|
+
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); }
|
|
98
|
+
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; }
|
|
99
|
+
var FileIcon = function FileIcon(props) {
|
|
100
|
+
props.className;
|
|
95
101
|
return jsxs("svg", Object.assign({
|
|
96
102
|
viewBox: "0 0 180 180",
|
|
97
103
|
className: 'upload-list-picture-file'
|
|
@@ -176,59 +182,104 @@ const FileIcon = props => {
|
|
|
176
182
|
}));
|
|
177
183
|
};
|
|
178
184
|
//UploadList
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
listType = 'text',
|
|
182
|
-
items =
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
185
|
+
var UploadList = function UploadList(props) {
|
|
186
|
+
var _props$listType = props.listType,
|
|
187
|
+
listType = _props$listType === void 0 ? 'text' : _props$listType,
|
|
188
|
+
_props$items = props.items,
|
|
189
|
+
items = _props$items === void 0 ? [] : _props$items,
|
|
190
|
+
_onRemove = props.onRemove,
|
|
191
|
+
_props$showRemoveIcon = props.showRemoveIcon,
|
|
192
|
+
showRemoveIcon = _props$showRemoveIcon === void 0 ? true : _props$showRemoveIcon,
|
|
193
|
+
_props$showPreviewIco = props.showPreviewIcon,
|
|
194
|
+
showPreviewIcon = _props$showPreviewIco === void 0 ? true : _props$showPreviewIco,
|
|
195
|
+
previewIcon = props.previewIcon,
|
|
196
|
+
removeIcon = props.removeIcon,
|
|
197
|
+
itemRender = props.itemRender,
|
|
198
|
+
readonly = props.readonly,
|
|
199
|
+
operateBtnProps = props.operateBtnProps,
|
|
200
|
+
actionRender = props.actionRender,
|
|
201
|
+
onPreview = props.onPreview;
|
|
202
|
+
var _useState = useState([]),
|
|
203
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
204
|
+
uploadList = _useState2[0],
|
|
205
|
+
setUploadList = _useState2[1];
|
|
206
|
+
var _useState3 = useState(false),
|
|
207
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
208
|
+
visible = _useState4[0],
|
|
209
|
+
setVisible = _useState4[1];
|
|
210
|
+
var _useState5 = useState(0),
|
|
211
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
212
|
+
current = _useState6[0],
|
|
213
|
+
setCurrent = _useState6[1];
|
|
197
214
|
useRef(null);
|
|
198
215
|
//处理删除
|
|
199
|
-
|
|
216
|
+
var handleRemove = function handleRemove(file, evt) {
|
|
200
217
|
evt.stopPropagation();
|
|
201
|
-
|
|
218
|
+
_onRemove === null || _onRemove === void 0 ? void 0 : _onRemove(file);
|
|
202
219
|
};
|
|
203
|
-
|
|
204
|
-
|
|
220
|
+
var isError = function isError(file) {
|
|
221
|
+
return file.status === 'error';
|
|
222
|
+
};
|
|
223
|
+
var onImageError = function onImageError(file) {
|
|
205
224
|
if (file.status === 'error') return;
|
|
206
225
|
file.status = 'error';
|
|
207
|
-
setUploadList(
|
|
226
|
+
setUploadList(_toConsumableArray(uploadList));
|
|
208
227
|
};
|
|
209
|
-
|
|
228
|
+
var previewItems = useMemo(function () {
|
|
210
229
|
var _a;
|
|
211
|
-
|
|
230
|
+
var originItems = items === null || items === void 0 ? void 0 : items.filter(function (item) {
|
|
231
|
+
return isImageUrl(item) && !isError(item);
|
|
232
|
+
});
|
|
212
233
|
return {
|
|
213
|
-
items: ((_a = originItems === null || originItems === void 0 ? void 0 : originItems.map(
|
|
234
|
+
items: ((_a = originItems === null || originItems === void 0 ? void 0 : originItems.map(function (i) {
|
|
235
|
+
return i.url || i.thumbUrl;
|
|
236
|
+
})) === null || _a === void 0 ? void 0 : _a.filter(function (i) {
|
|
237
|
+
return !!i;
|
|
238
|
+
})) || [],
|
|
214
239
|
originItems: originItems
|
|
215
240
|
};
|
|
216
241
|
}, [items]);
|
|
217
|
-
|
|
218
|
-
return previewItems.originItems.findIndex(
|
|
242
|
+
var getCurrent = function getCurrent(file) {
|
|
243
|
+
return previewItems.originItems.findIndex(function (i) {
|
|
244
|
+
return i.uid === file.uid;
|
|
245
|
+
});
|
|
219
246
|
};
|
|
220
247
|
// 处理预览
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
248
|
+
var handlePreview = function handlePreview(file, e) {
|
|
249
|
+
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
|
|
250
|
+
var shouldPreview, currentIndex;
|
|
251
|
+
return regenerator.wrap(function _callee$(_context) {
|
|
252
|
+
while (1) switch (_context.prev = _context.next) {
|
|
253
|
+
case 0:
|
|
254
|
+
_context.next = 2;
|
|
255
|
+
return onPreview === null || onPreview === void 0 ? void 0 : onPreview(file, e);
|
|
256
|
+
case 2:
|
|
257
|
+
shouldPreview = _context.sent;
|
|
258
|
+
if (!(shouldPreview === false)) {
|
|
259
|
+
_context.next = 5;
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
return _context.abrupt("return");
|
|
263
|
+
case 5:
|
|
264
|
+
currentIndex = getCurrent(file);
|
|
265
|
+
if (!(currentIndex === -1)) {
|
|
266
|
+
_context.next = 8;
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
return _context.abrupt("return");
|
|
270
|
+
case 8:
|
|
271
|
+
setCurrent(currentIndex);
|
|
272
|
+
setVisible(true);
|
|
273
|
+
case 10:
|
|
274
|
+
case "end":
|
|
275
|
+
return _context.stop();
|
|
276
|
+
}
|
|
277
|
+
}, _callee);
|
|
278
|
+
}));
|
|
279
|
+
};
|
|
229
280
|
// 图片墙操作按钮
|
|
230
|
-
|
|
231
|
-
|
|
281
|
+
var pictureCardAction = function pictureCardAction(file) {
|
|
282
|
+
var list = [];
|
|
232
283
|
if (isImageUrl(file) && !isError(file) && showPreviewIcon) list.push({
|
|
233
284
|
icon: previewIcon || jsx(PreviewOpen, {}),
|
|
234
285
|
key: 'view'
|
|
@@ -238,7 +289,7 @@ const UploadList = props => {
|
|
|
238
289
|
key: 'delete'
|
|
239
290
|
});
|
|
240
291
|
if (!list.length) return null;
|
|
241
|
-
|
|
292
|
+
var onClick = function onClick(item, e) {
|
|
242
293
|
if (item.key === 'view') handlePreview(file, e);
|
|
243
294
|
if (item.key === 'delete') handleRemove(file, e);
|
|
244
295
|
};
|
|
@@ -250,10 +301,14 @@ const UploadList = props => {
|
|
|
250
301
|
});
|
|
251
302
|
};
|
|
252
303
|
//渲染列表actions
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
onRemove:
|
|
256
|
-
|
|
304
|
+
var renderActions = function renderActions(file) {
|
|
305
|
+
var actions = {
|
|
306
|
+
onRemove: function onRemove() {
|
|
307
|
+
return _onRemove === null || _onRemove === void 0 ? void 0 : _onRemove(file);
|
|
308
|
+
},
|
|
309
|
+
onPreview: function onPreview() {
|
|
310
|
+
return handlePreview(file);
|
|
311
|
+
}
|
|
257
312
|
};
|
|
258
313
|
if (actionRender) return actionRender(file, actions);
|
|
259
314
|
if (operateBtnProps) return jsx(OperateBtn, Object.assign({
|
|
@@ -265,37 +320,43 @@ const UploadList = props => {
|
|
|
265
320
|
className: 'upload-list-actions'
|
|
266
321
|
}, {
|
|
267
322
|
children: showRemoveIcon && jsx("span", Object.assign({
|
|
268
|
-
onClick:
|
|
323
|
+
onClick: function onClick(evt) {
|
|
324
|
+
return handleRemove(file, evt);
|
|
325
|
+
}
|
|
269
326
|
}, {
|
|
270
327
|
children: removeIcon || jsx(Delete, {})
|
|
271
328
|
}))
|
|
272
329
|
}));
|
|
273
330
|
};
|
|
274
331
|
// 渲染图标
|
|
275
|
-
|
|
276
|
-
|
|
332
|
+
var renderIcon = function renderIcon(file) {
|
|
333
|
+
var isImage = isImageUrl(file);
|
|
277
334
|
if (file.status === 'error') return jsx(InfoOutlined, {});
|
|
278
335
|
return isImage ? jsx(PhotoIcon, {}) : jsx(FileOutlined, {});
|
|
279
336
|
};
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
337
|
+
var renderTextItem = function renderTextItem(file) {
|
|
338
|
+
var listItemNameClass = 'upload-list-text-name';
|
|
339
|
+
var fileName = file.url && !isError(file) ? jsx("a", Object.assign({
|
|
283
340
|
target: "_blank",
|
|
284
341
|
rel: "noopener noreferrer",
|
|
285
342
|
className: listItemNameClass,
|
|
286
343
|
// title={file.name}
|
|
287
344
|
href: file.url,
|
|
288
|
-
onClick:
|
|
345
|
+
onClick: function onClick(e) {
|
|
346
|
+
return onPreview === null || onPreview === void 0 ? void 0 : onPreview(file, e);
|
|
347
|
+
}
|
|
289
348
|
}, {
|
|
290
349
|
children: file.name
|
|
291
350
|
}), "view") : jsx("div", Object.assign({
|
|
292
351
|
className: listItemNameClass,
|
|
293
|
-
onClick:
|
|
352
|
+
onClick: function onClick(e) {
|
|
353
|
+
return onPreview === null || onPreview === void 0 ? void 0 : onPreview(file, e);
|
|
354
|
+
},
|
|
294
355
|
title: file.name
|
|
295
356
|
}, {
|
|
296
357
|
children: file.name
|
|
297
358
|
}), "view");
|
|
298
|
-
|
|
359
|
+
var listItem = jsxs("div", Object.assign({
|
|
299
360
|
className: clsx('upload-list-text-item', isError(file) && 'upload-list-text-item-error')
|
|
300
361
|
}, {
|
|
301
362
|
children: [jsx("div", Object.assign({
|
|
@@ -316,9 +377,9 @@ const UploadList = props => {
|
|
|
316
377
|
return listItem;
|
|
317
378
|
};
|
|
318
379
|
//文件列表 text
|
|
319
|
-
|
|
380
|
+
var renderFileListText = function renderFileListText() {
|
|
320
381
|
if (!(uploadList === null || uploadList === void 0 ? void 0 : uploadList.length)) return null;
|
|
321
|
-
return uploadList.map((file, idx)
|
|
382
|
+
return uploadList.map(function (file, idx) {
|
|
322
383
|
var _a;
|
|
323
384
|
if (itemRender)
|
|
324
385
|
//自定义渲染
|
|
@@ -340,17 +401,19 @@ const UploadList = props => {
|
|
|
340
401
|
});
|
|
341
402
|
};
|
|
342
403
|
//文件列表 picture-card
|
|
343
|
-
|
|
404
|
+
var renderFileListPicture = function renderFileListPicture() {
|
|
344
405
|
if (!(uploadList === null || uploadList === void 0 ? void 0 : uploadList.length)) return null;
|
|
345
|
-
return uploadList.map((file, idx)
|
|
406
|
+
return uploadList.map(function (file, idx) {
|
|
346
407
|
/*自定义渲染*/
|
|
347
408
|
if (itemRender) return itemRender(file, uploadList);
|
|
348
|
-
|
|
349
|
-
|
|
409
|
+
var isImage = isImageUrl(file);
|
|
410
|
+
var pictureItem = jsxs(Fragment, {
|
|
350
411
|
children: [isImage ? jsx("img", {
|
|
351
412
|
src: file.thumbUrl || file.dataUrl || file.url,
|
|
352
413
|
alt: file.name,
|
|
353
|
-
onError: ()
|
|
414
|
+
onError: function onError() {
|
|
415
|
+
return onImageError(file);
|
|
416
|
+
}
|
|
354
417
|
}) : jsx(FileIcon, {
|
|
355
418
|
className: 'upload-list-picture-file'
|
|
356
419
|
})
|
|
@@ -381,31 +444,84 @@ const UploadList = props => {
|
|
|
381
444
|
});
|
|
382
445
|
};
|
|
383
446
|
//处理文件
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
447
|
+
var handleFileFormat = function handleFileFormat() {
|
|
448
|
+
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee3() {
|
|
449
|
+
var readerFileAsDataUrl, _iterator, _step, file, dataUrl;
|
|
450
|
+
return regenerator.wrap(function _callee3$(_context3) {
|
|
451
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
452
|
+
case 0:
|
|
453
|
+
if (items === null || items === void 0 ? void 0 : items.length) {
|
|
454
|
+
_context3.next = 2;
|
|
455
|
+
break;
|
|
456
|
+
}
|
|
457
|
+
return _context3.abrupt("return", setUploadList([]));
|
|
458
|
+
case 2:
|
|
459
|
+
//读取file as DataUrl
|
|
460
|
+
readerFileAsDataUrl = function readerFileAsDataUrl(file) {
|
|
461
|
+
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee2() {
|
|
462
|
+
return regenerator.wrap(function _callee2$(_context2) {
|
|
463
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
464
|
+
case 0:
|
|
465
|
+
return _context2.abrupt("return", new Promise(function (resolve) {
|
|
466
|
+
var fileReader = new FileReader();
|
|
467
|
+
if (file.originFileObj) {
|
|
468
|
+
fileReader.onload = function () {
|
|
469
|
+
resolve(fileReader.result);
|
|
470
|
+
};
|
|
471
|
+
fileReader.readAsDataURL(file.originFileObj);
|
|
472
|
+
} else resolve('');
|
|
473
|
+
}));
|
|
474
|
+
case 1:
|
|
475
|
+
case "end":
|
|
476
|
+
return _context2.stop();
|
|
477
|
+
}
|
|
478
|
+
}, _callee2);
|
|
479
|
+
}));
|
|
480
|
+
};
|
|
481
|
+
_iterator = _createForOfIteratorHelper(items);
|
|
482
|
+
_context3.prev = 4;
|
|
483
|
+
_iterator.s();
|
|
484
|
+
case 6:
|
|
485
|
+
if ((_step = _iterator.n()).done) {
|
|
486
|
+
_context3.next = 15;
|
|
487
|
+
break;
|
|
488
|
+
}
|
|
489
|
+
file = _step.value;
|
|
490
|
+
if (!file.originFileObj) {
|
|
491
|
+
_context3.next = 13;
|
|
492
|
+
break;
|
|
493
|
+
}
|
|
494
|
+
_context3.next = 11;
|
|
495
|
+
return readerFileAsDataUrl(file);
|
|
496
|
+
case 11:
|
|
497
|
+
dataUrl = _context3.sent;
|
|
498
|
+
file.dataUrl = dataUrl;
|
|
499
|
+
case 13:
|
|
500
|
+
_context3.next = 6;
|
|
501
|
+
break;
|
|
502
|
+
case 15:
|
|
503
|
+
_context3.next = 20;
|
|
504
|
+
break;
|
|
505
|
+
case 17:
|
|
506
|
+
_context3.prev = 17;
|
|
507
|
+
_context3.t0 = _context3["catch"](4);
|
|
508
|
+
_iterator.e(_context3.t0);
|
|
509
|
+
case 20:
|
|
510
|
+
_context3.prev = 20;
|
|
511
|
+
_iterator.f();
|
|
512
|
+
return _context3.finish(20);
|
|
513
|
+
case 23:
|
|
514
|
+
setUploadList(_toConsumableArray(items));
|
|
515
|
+
case 24:
|
|
516
|
+
case "end":
|
|
517
|
+
return _context3.stop();
|
|
518
|
+
}
|
|
519
|
+
}, _callee3, null, [[4, 17, 20, 23]]);
|
|
520
|
+
}));
|
|
521
|
+
};
|
|
522
|
+
useEffect(function () {
|
|
523
|
+
if (listType === 'picture-card') handleFileFormat();else setUploadList(function (pre) {
|
|
524
|
+
if (items) return _toConsumableArray(items);
|
|
409
525
|
return pre;
|
|
410
526
|
});
|
|
411
527
|
}, [items]);
|
|
@@ -420,14 +536,14 @@ const UploadList = props => {
|
|
|
420
536
|
children: renderFileListPicture()
|
|
421
537
|
})), jsx(Image$1.PreviewGroup, {
|
|
422
538
|
preview: {
|
|
423
|
-
visible,
|
|
424
|
-
onVisibleChange: value
|
|
539
|
+
visible: visible,
|
|
540
|
+
onVisibleChange: function onVisibleChange(value) {
|
|
425
541
|
setVisible(value);
|
|
426
542
|
},
|
|
427
|
-
onChange: value
|
|
543
|
+
onChange: function onChange(value) {
|
|
428
544
|
setCurrent(value);
|
|
429
545
|
},
|
|
430
|
-
current
|
|
546
|
+
current: current
|
|
431
547
|
},
|
|
432
548
|
items: previewItems.items
|
|
433
549
|
})]
|
|
@@ -438,7 +554,7 @@ var css_248z$3 = "@charset \"UTF-8\";\n/**\n* @author Hanz\n* @date 2021/11/15
|
|
|
438
554
|
styleInject(css_248z$3);
|
|
439
555
|
|
|
440
556
|
//error tip
|
|
441
|
-
|
|
557
|
+
var ErrorTip = function ErrorTip(props) {
|
|
442
558
|
return jsxs("div", Object.assign({
|
|
443
559
|
className: clsx("".concat($prefixCls, "-upload-error"), props.className)
|
|
444
560
|
}, {
|
|
@@ -471,113 +587,160 @@ var zh = {
|
|
|
471
587
|
};
|
|
472
588
|
|
|
473
589
|
var localeJson = {
|
|
474
|
-
zh,
|
|
475
|
-
en
|
|
590
|
+
zh: zh,
|
|
591
|
+
en: en
|
|
476
592
|
};
|
|
477
593
|
|
|
478
594
|
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}\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 .component-upload-disabled {\n color: rgb(92, 101, 115);\n cursor: not-allowed;\n}\n.paraui-v4-upload-image .upload-image-select .component-upload-disabled svg {\n color: rgb(92, 101, 115);\n}\n.paraui-v4-upload-image .upload-image-select .component-upload-disabled .upload-image-picture-card {\n color: rgb(92, 101, 115);\n}\n.paraui-v4-upload-image .upload-image-select:hover .component-upload:not(.component-upload-disabled) .upload-image-picture-card {\n color: rgb(46, 101, 230);\n border-color: rgb(87, 131, 235);\n}\n.paraui-v4-upload-image .upload-image-select:hover .component-upload:not(.component-upload-disabled) .upload-image-picture-card .upload-image-text {\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 border: 1px dashed rgb(212, 218, 227);\n border-radius: 4px;\n}\n.paraui-v4-upload-image .upload-image-picture-card.is-avatar {\n border: none;\n}\n.paraui-v4-upload-image .upload-image-picture-card .upload-image-select-tooltip-wrapper {\n display: inline-flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n width: 100%;\n height: 100%;\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}";
|
|
479
595
|
styleInject(css_248z$2);
|
|
480
596
|
|
|
481
597
|
//ImageUpload
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
598
|
+
var ImageUpload = function ImageUpload(props) {
|
|
599
|
+
var className = props.className,
|
|
600
|
+
style = props.style,
|
|
601
|
+
_onStart = props.onStart,
|
|
602
|
+
_onSuccess = props.onSuccess,
|
|
603
|
+
_onError = props.onError,
|
|
604
|
+
_onProgress = props.onProgress,
|
|
605
|
+
onRemove = props.onRemove,
|
|
606
|
+
_beforeUpload = props.beforeUpload,
|
|
607
|
+
onChange = props.onChange,
|
|
608
|
+
_props$defaultFileLis = props.defaultFileList,
|
|
609
|
+
defaultFileList = _props$defaultFileLis === void 0 ? [] : _props$defaultFileLis,
|
|
610
|
+
fileList = props.fileList,
|
|
611
|
+
_props$showUploadList = props.showUploadList,
|
|
612
|
+
showUploadList = _props$showUploadList === void 0 ? true : _props$showUploadList,
|
|
613
|
+
maxCount = props.maxCount,
|
|
614
|
+
_props$children = props.children,
|
|
615
|
+
children = _props$children === void 0 ? null : _props$children,
|
|
616
|
+
itemRender = props.itemRender,
|
|
617
|
+
_props$showUploadErro = props.showUploadError,
|
|
618
|
+
showUploadError = _props$showUploadErro === void 0 ? false : _props$showUploadErro,
|
|
619
|
+
_props$stash = props.stash,
|
|
620
|
+
stash = _props$stash === void 0 ? false : _props$stash,
|
|
621
|
+
_props$uploading = props.uploading,
|
|
622
|
+
uploading = _props$uploading === void 0 ? true : _props$uploading,
|
|
623
|
+
_props$loading = props.loading,
|
|
624
|
+
loading = _props$loading === void 0 ? false : _props$loading,
|
|
625
|
+
_props$showLoading = props.showLoading,
|
|
626
|
+
showLoadingProp = _props$showLoading === void 0 ? false : _props$showLoading,
|
|
627
|
+
defaultImage = props.defaultImage,
|
|
628
|
+
readonly = props.readonly,
|
|
629
|
+
onPreview = props.onPreview,
|
|
630
|
+
actionRender = props.actionRender,
|
|
631
|
+
operateBtnProps = props.operateBtnProps,
|
|
632
|
+
disabledTooltip = props.disabledTooltip,
|
|
633
|
+
removeErrorTip = props.removeErrorTip,
|
|
512
634
|
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", "onPreview", "actionRender", "operateBtnProps", "disabledTooltip", "removeErrorTip"]);
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
id: 'uploadError'
|
|
635
|
+
var intl = useFormatMessage('Upload', localeJson);
|
|
636
|
+
var _useState = useState(defaultFileList),
|
|
637
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
638
|
+
uploadFileList = _useState2[0],
|
|
639
|
+
setUploadFileList = _useState2[1]; //文件列表
|
|
640
|
+
var _useState3 = useState(false),
|
|
641
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
642
|
+
showLoading = _useState4[0],
|
|
643
|
+
setShowLoading = _useState4[1]; //upload loading
|
|
644
|
+
var _useState5 = useState(false),
|
|
645
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
646
|
+
errTip = _useState6[0],
|
|
647
|
+
setErrTip = _useState6[1]; //upload error tip
|
|
648
|
+
var _useState7 = useState({
|
|
649
|
+
imageUrl: ''
|
|
529
650
|
}),
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
651
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
652
|
+
avatar = _useState8[0],
|
|
653
|
+
setAvatar = _useState8[1]; //不显示列表时上传头像
|
|
654
|
+
var _ref = typeof showUploadList === 'boolean' ? {} : showUploadList,
|
|
655
|
+
showRemoveIcon = _ref.showRemoveIcon,
|
|
656
|
+
removeIcon = _ref.removeIcon,
|
|
657
|
+
showPreviewIcon = _ref.showPreviewIcon,
|
|
658
|
+
previewIcon = _ref.previewIcon; //显示上传列表
|
|
659
|
+
var _ref2 = typeof showUploadError === 'boolean' ? {} : showUploadError,
|
|
660
|
+
_ref2$uploadErrorMsg = _ref2.uploadErrorMsg,
|
|
661
|
+
uploadErrorMsg = _ref2$uploadErrorMsg === void 0 ? intl({
|
|
662
|
+
id: 'uploadError'
|
|
663
|
+
}) : _ref2$uploadErrorMsg,
|
|
664
|
+
_ref2$leaveDelay = _ref2.leaveDelay,
|
|
665
|
+
leaveDelay = _ref2$leaveDelay === void 0 ? 2000 : _ref2$leaveDelay; //错误信息提示
|
|
666
|
+
var cropFileRef = useRef(); //裁剪文件
|
|
667
|
+
var isAvatarMode = useMemo(function () {
|
|
668
|
+
return !showUploadList && avatar.imageUrl && !showLoading;
|
|
669
|
+
}, [showUploadList, avatar.imageUrl, showLoading]);
|
|
670
|
+
useEffect(function () {
|
|
535
671
|
setShowLoading(loading);
|
|
536
672
|
}, [loading]);
|
|
537
673
|
//复写属性
|
|
538
|
-
|
|
674
|
+
var overrideProps = Object.assign(Object.assign({
|
|
539
675
|
accept: 'image/*'
|
|
540
676
|
}, restProps), {
|
|
541
|
-
beforeUpload: (file, fileList)
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
677
|
+
beforeUpload: function beforeUpload(file, fileList) {
|
|
678
|
+
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
|
|
679
|
+
var result;
|
|
680
|
+
return regenerator.wrap(function _callee$(_context) {
|
|
681
|
+
while (1) switch (_context.prev = _context.next) {
|
|
682
|
+
case 0:
|
|
683
|
+
if (restProps.action && showLoadingProp && uploading) setShowLoading(true);
|
|
684
|
+
_context.next = 3;
|
|
685
|
+
return _beforeUpload === null || _beforeUpload === void 0 ? void 0 : _beforeUpload(file, fileList);
|
|
686
|
+
case 3:
|
|
687
|
+
result = _context.sent;
|
|
688
|
+
if (!(result === false)) {
|
|
689
|
+
_context.next = 9;
|
|
690
|
+
break;
|
|
691
|
+
}
|
|
692
|
+
setShowLoading(false);
|
|
693
|
+
return _context.abrupt("return", false);
|
|
694
|
+
case 9:
|
|
695
|
+
if (!(_typeof(result) === 'object' && result)) {
|
|
696
|
+
_context.next = 16;
|
|
697
|
+
break;
|
|
698
|
+
}
|
|
699
|
+
if (!(result instanceof File || result instanceof Blob)) {
|
|
700
|
+
_context.next = 12;
|
|
701
|
+
break;
|
|
702
|
+
}
|
|
703
|
+
return _context.abrupt("return", result);
|
|
704
|
+
case 12:
|
|
705
|
+
cropFileRef.current = result.cropFile;
|
|
706
|
+
return _context.abrupt("return", result.isUpload);
|
|
707
|
+
case 16:
|
|
708
|
+
return _context.abrupt("return", true);
|
|
709
|
+
case 17:
|
|
710
|
+
case "end":
|
|
711
|
+
return _context.stop();
|
|
712
|
+
}
|
|
713
|
+
}, _callee);
|
|
714
|
+
}));
|
|
555
715
|
},
|
|
556
|
-
|
|
716
|
+
onStart: function onStart(file) {
|
|
717
|
+
_onStart === null || _onStart === void 0 ? void 0 : _onStart(file);
|
|
718
|
+
},
|
|
719
|
+
onSuccess: function onSuccess(response, file, xhr) {
|
|
557
720
|
setShowLoading(false);
|
|
558
721
|
errTip && showErrTip(false);
|
|
559
|
-
|
|
722
|
+
var nextFileList = updateFileList(file);
|
|
560
723
|
onInternalChange(nextFileList);
|
|
561
|
-
|
|
724
|
+
_onSuccess === null || _onSuccess === void 0 ? void 0 : _onSuccess(response, file, xhr);
|
|
562
725
|
},
|
|
563
|
-
onError(error, response, file) {
|
|
726
|
+
onError: function onError(error, response, file) {
|
|
564
727
|
setShowLoading(false);
|
|
565
728
|
showErrTip(!!showUploadError);
|
|
566
729
|
if (!showUploadError) {
|
|
567
730
|
file.status = 'error';
|
|
568
731
|
file.response = (error === null || error === void 0 ? void 0 : error.message) || uploadErrorMsg;
|
|
569
|
-
|
|
732
|
+
var nextFileList = updateFileList(file);
|
|
570
733
|
onInternalChange(nextFileList);
|
|
571
734
|
}
|
|
572
|
-
|
|
735
|
+
_onError === null || _onError === void 0 ? void 0 : _onError(error, response, file);
|
|
573
736
|
},
|
|
574
|
-
onProgress(e, file) {
|
|
575
|
-
|
|
737
|
+
onProgress: function onProgress(e, file) {
|
|
738
|
+
_onProgress === null || _onProgress === void 0 ? void 0 : _onProgress(e, file);
|
|
576
739
|
},
|
|
577
|
-
onBatchStart(fileList) {
|
|
740
|
+
onBatchStart: function onBatchStart(fileList) {
|
|
578
741
|
if (stash) {
|
|
579
742
|
if (cropFileRef.current) {
|
|
580
|
-
|
|
743
|
+
var idx = fileList.findIndex(function (_) {
|
|
581
744
|
var _a;
|
|
582
745
|
return _.file.uid === ((_a = cropFileRef.current) === null || _a === void 0 ? void 0 : _a.uid);
|
|
583
746
|
});
|
|
@@ -588,40 +751,62 @@ const ImageUpload = props => {
|
|
|
588
751
|
});
|
|
589
752
|
}
|
|
590
753
|
}
|
|
591
|
-
|
|
592
|
-
|
|
754
|
+
var arr = fileList.map(function (_) {
|
|
755
|
+
return _.parsedFile || _.file;
|
|
756
|
+
});
|
|
757
|
+
var mList = mergedFileList(arr);
|
|
593
758
|
onInternalChange(mList);
|
|
594
759
|
}
|
|
595
760
|
}
|
|
596
761
|
});
|
|
597
762
|
//内部变化
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
763
|
+
var onInternalChange = function onInternalChange(changedFileList) {
|
|
764
|
+
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee2() {
|
|
765
|
+
var cloneList, file, imageUrl;
|
|
766
|
+
return regenerator.wrap(function _callee2$(_context2) {
|
|
767
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
768
|
+
case 0:
|
|
769
|
+
cloneList = _toConsumableArray(changedFileList);
|
|
770
|
+
if (showUploadList) {
|
|
771
|
+
_context2.next = 13;
|
|
772
|
+
break;
|
|
773
|
+
}
|
|
774
|
+
//不显示上传列表
|
|
775
|
+
file = cloneList.slice(-1)[0];
|
|
776
|
+
if (!file) {
|
|
777
|
+
_context2.next = 11;
|
|
778
|
+
break;
|
|
779
|
+
}
|
|
780
|
+
_context2.next = 6;
|
|
781
|
+
return readerFileAsDataUrl(file);
|
|
782
|
+
case 6:
|
|
783
|
+
imageUrl = _context2.sent;
|
|
784
|
+
file.dataUrl = imageUrl;
|
|
785
|
+
avatar.imageUrl = imageUrl;
|
|
786
|
+
avatar.imageName = file.name;
|
|
787
|
+
setAvatar(Object.assign({}, avatar));
|
|
788
|
+
case 11:
|
|
789
|
+
onChange === null || onChange === void 0 ? void 0 : onChange([file]);
|
|
790
|
+
return _context2.abrupt("return");
|
|
791
|
+
case 13:
|
|
792
|
+
if (maxCount === 1) {
|
|
793
|
+
cloneList = cloneList.slice(-1);
|
|
794
|
+
} else if (maxCount) {
|
|
795
|
+
cloneList = cloneList.slice(0, maxCount);
|
|
796
|
+
}
|
|
797
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(cloneList);
|
|
798
|
+
setUploadFileList(cloneList);
|
|
799
|
+
case 16:
|
|
800
|
+
case "end":
|
|
801
|
+
return _context2.stop();
|
|
802
|
+
}
|
|
803
|
+
}, _callee2);
|
|
804
|
+
}));
|
|
805
|
+
};
|
|
621
806
|
//更新文件列表
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
807
|
+
var updateFileList = function updateFileList(file) {
|
|
808
|
+
var cloneList = _toConsumableArray(uploadFileList);
|
|
809
|
+
var fileObj = Object.assign(Object.assign({}, file), {
|
|
625
810
|
lastModified: file.lastModified,
|
|
626
811
|
lastModifiedDate: file.lastModifiedDate,
|
|
627
812
|
name: file.name,
|
|
@@ -633,9 +818,9 @@ const ImageUpload = props => {
|
|
|
633
818
|
return cloneList.concat(fileObj);
|
|
634
819
|
};
|
|
635
820
|
//合并文件列表
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
821
|
+
var mergedFileList = function mergedFileList(fileList) {
|
|
822
|
+
var cloneList = _toConsumableArray(uploadFileList);
|
|
823
|
+
var newFileList = fileList.map(function (file) {
|
|
639
824
|
return Object.assign(Object.assign({}, file), {
|
|
640
825
|
lastModified: file.lastModified,
|
|
641
826
|
lastModifiedDate: file.lastModifiedDate,
|
|
@@ -649,64 +834,78 @@ const ImageUpload = props => {
|
|
|
649
834
|
return cloneList.concat(newFileList);
|
|
650
835
|
};
|
|
651
836
|
//删除文件
|
|
652
|
-
|
|
653
|
-
Promise.resolve(typeof onRemove === 'function' ? onRemove(file) : onRemove).then(ret
|
|
837
|
+
var handleRemove = function handleRemove(file) {
|
|
838
|
+
Promise.resolve(typeof onRemove === 'function' ? onRemove(file) : onRemove).then(function (ret) {
|
|
654
839
|
// Prevent removing file
|
|
655
840
|
if (ret === false) return;
|
|
656
|
-
|
|
841
|
+
var idx = uploadFileList.findIndex(function (_) {
|
|
842
|
+
return _.uid === file.uid;
|
|
843
|
+
});
|
|
657
844
|
if (idx > -1) uploadFileList.splice(idx, 1);
|
|
658
845
|
onInternalChange(uploadFileList);
|
|
659
846
|
});
|
|
660
847
|
};
|
|
661
848
|
//读取dataUrl
|
|
662
|
-
|
|
663
|
-
return
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
849
|
+
var readerFileAsDataUrl = function readerFileAsDataUrl(file) {
|
|
850
|
+
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee3() {
|
|
851
|
+
return regenerator.wrap(function _callee3$(_context3) {
|
|
852
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
853
|
+
case 0:
|
|
854
|
+
return _context3.abrupt("return", new Promise(function (resolve) {
|
|
855
|
+
var fileReader = new FileReader();
|
|
856
|
+
if (file.originFileObj) {
|
|
857
|
+
fileReader.onload = function () {
|
|
858
|
+
resolve(fileReader.result);
|
|
859
|
+
};
|
|
860
|
+
fileReader.readAsDataURL(file.originFileObj);
|
|
861
|
+
} else resolve('');
|
|
862
|
+
}));
|
|
863
|
+
case 1:
|
|
864
|
+
case "end":
|
|
865
|
+
return _context3.stop();
|
|
866
|
+
}
|
|
867
|
+
}, _callee3);
|
|
868
|
+
}));
|
|
869
|
+
};
|
|
673
870
|
//显示错误提示
|
|
674
|
-
|
|
871
|
+
var showErrTip = function showErrTip(flag) {
|
|
675
872
|
setErrTip(flag);
|
|
676
873
|
if (leaveDelay < 0) return;
|
|
677
|
-
setTimeout(()
|
|
874
|
+
setTimeout(function () {
|
|
678
875
|
setErrTip(false);
|
|
679
876
|
}, leaveDelay);
|
|
680
877
|
};
|
|
681
|
-
useEffect(()
|
|
878
|
+
useEffect(function () {
|
|
682
879
|
if (fileList) {
|
|
683
|
-
setUploadFileList(
|
|
880
|
+
setUploadFileList(_toConsumableArray(fileList));
|
|
684
881
|
}
|
|
685
882
|
}, [fileList]);
|
|
686
|
-
useEffect(()
|
|
883
|
+
useEffect(function () {
|
|
687
884
|
if (defaultImage) {
|
|
688
885
|
setAvatar(Object.assign({}, defaultImage));
|
|
689
886
|
}
|
|
690
887
|
}, [defaultImage]);
|
|
691
888
|
//渲染上传列表
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
889
|
+
var renderUploadList = function renderUploadList() {
|
|
890
|
+
return showUploadList && jsx(UploadList, {
|
|
891
|
+
listType: 'picture-card',
|
|
892
|
+
readonly: readonly,
|
|
893
|
+
items: uploadFileList,
|
|
894
|
+
showRemoveIcon: showRemoveIcon,
|
|
895
|
+
removeIcon: removeIcon,
|
|
896
|
+
showPreviewIcon: showPreviewIcon,
|
|
897
|
+
previewIcon: previewIcon,
|
|
898
|
+
onRemove: handleRemove,
|
|
899
|
+
itemRender: itemRender,
|
|
900
|
+
onPreview: onPreview,
|
|
901
|
+
actionRender: actionRender,
|
|
902
|
+
operateBtnProps: operateBtnProps
|
|
903
|
+
});
|
|
904
|
+
};
|
|
706
905
|
//渲染内容 avatar
|
|
707
|
-
|
|
906
|
+
var renderUploadContent = function renderUploadContent() {
|
|
708
907
|
var _a;
|
|
709
|
-
|
|
908
|
+
var avatarUploadNode = jsxs("div", Object.assign({
|
|
710
909
|
className: 'upload-img-wrapper'
|
|
711
910
|
}, {
|
|
712
911
|
children: [jsx("img", {
|
|
@@ -722,7 +921,7 @@ const ImageUpload = props => {
|
|
|
722
921
|
children: jsx(EditOutline, {})
|
|
723
922
|
}))]
|
|
724
923
|
}));
|
|
725
|
-
|
|
924
|
+
var uploadNode = jsxs(Fragment, {
|
|
726
925
|
children: [showLoading ? jsx(LoadingIcon, {
|
|
727
926
|
className: 'upload-image-loading'
|
|
728
927
|
}) : jsx(UploadIcon, {
|
|
@@ -754,7 +953,7 @@ const ImageUpload = props => {
|
|
|
754
953
|
});
|
|
755
954
|
};
|
|
756
955
|
//渲染上传控件
|
|
757
|
-
|
|
956
|
+
var renderUploadSelector = function renderUploadSelector() {
|
|
758
957
|
if (readonly) return null;
|
|
759
958
|
return jsxs("div", Object.assign({
|
|
760
959
|
className: clsx('upload-image-select', showLoading && 'upload-image-select-loading')
|
|
@@ -782,7 +981,7 @@ const ImageUpload = props => {
|
|
|
782
981
|
};
|
|
783
982
|
|
|
784
983
|
//Dragger upload
|
|
785
|
-
|
|
984
|
+
var Dragger = function Dragger(props) {
|
|
786
985
|
return jsx(Upload, Object.assign({}, props, {
|
|
787
986
|
type: 'drag'
|
|
788
987
|
}));
|
|
@@ -981,274 +1180,352 @@ var css_248z$1 = "@charset \"UTF-8\";\n/**\n* @author Hanz\n* @date 2022/4/20
|
|
|
981
1180
|
styleInject(css_248z$1);
|
|
982
1181
|
|
|
983
1182
|
//图片裁剪组件
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
aspect = 1,
|
|
987
|
-
shape =
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1183
|
+
var ImgCrop = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
1184
|
+
var _props$aspect = props.aspect,
|
|
1185
|
+
aspect = _props$aspect === void 0 ? 1 : _props$aspect,
|
|
1186
|
+
_props$shape = props.shape,
|
|
1187
|
+
shape = _props$shape === void 0 ? 'rect' : _props$shape,
|
|
1188
|
+
_props$grid = props.grid,
|
|
1189
|
+
grid = _props$grid === void 0 ? false : _props$grid,
|
|
1190
|
+
_props$quality = props.quality,
|
|
1191
|
+
quality = _props$quality === void 0 ? 0.4 : _props$quality,
|
|
1192
|
+
_props$fillColor = props.fillColor,
|
|
1193
|
+
fillColor = _props$fillColor === void 0 ? 'transparent' : _props$fillColor,
|
|
1194
|
+
_props$zoom = props.zoom,
|
|
1195
|
+
zoom = _props$zoom === void 0 ? true : _props$zoom,
|
|
1196
|
+
_props$rotate = props.rotate,
|
|
1197
|
+
rotate = _props$rotate === void 0 ? false : _props$rotate,
|
|
1198
|
+
_props$minZoom = props.minZoom,
|
|
1199
|
+
minZoom = _props$minZoom === void 0 ? 1 : _props$minZoom,
|
|
1200
|
+
_props$maxZoom = props.maxZoom,
|
|
1201
|
+
maxZoom = _props$maxZoom === void 0 ? 3 : _props$maxZoom,
|
|
1202
|
+
modalTitle = props.modalTitle,
|
|
1203
|
+
modalWidth = props.modalWidth,
|
|
1204
|
+
modalOk = props.modalOk,
|
|
1205
|
+
modalCancel = props.modalCancel,
|
|
1206
|
+
onModalOk = props.onModalOk,
|
|
1207
|
+
onModalCancel = props.onModalCancel,
|
|
1208
|
+
beforeCrop = props.beforeCrop,
|
|
1209
|
+
onUploadFail = props.onUploadFail,
|
|
1210
|
+
cropperProps = props.cropperProps,
|
|
1211
|
+
children = props.children,
|
|
1212
|
+
_props$fixedCropSize = props.fixedCropSize,
|
|
1213
|
+
fixedCropSize = _props$fixedCropSize === void 0 ? {
|
|
1006
1214
|
width: 120,
|
|
1007
1215
|
height: 120
|
|
1008
|
-
},
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1216
|
+
} : _props$fixedCropSize,
|
|
1217
|
+
_props$zoomTipFormatt = props.zoomTipFormatter,
|
|
1218
|
+
zoomTipFormatter = _props$zoomTipFormatt === void 0 ? function (val) {
|
|
1219
|
+
return "".concat(Number(val) * 10 * 10);
|
|
1220
|
+
} : _props$zoomTipFormatt,
|
|
1221
|
+
_props$zoomMarks = props.zoomMarks,
|
|
1222
|
+
zoomMarks = _props$zoomMarks === void 0 ? true : _props$zoomMarks,
|
|
1223
|
+
_props$rotateMarks = props.rotateMarks,
|
|
1224
|
+
rotateMarks = _props$rotateMarks === void 0 ? true : _props$rotateMarks,
|
|
1225
|
+
_props$rotateTipForma = props.rotateTipFormatter,
|
|
1226
|
+
rotateTipFormatter = _props$rotateTipForma === void 0 ? function (val) {
|
|
1227
|
+
return "".concat(val);
|
|
1228
|
+
} : _props$rotateTipForma;
|
|
1229
|
+
var intl = useFormatMessage('Upload', localeJson);
|
|
1230
|
+
var _useState = useState(''),
|
|
1231
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1232
|
+
image = _useState2[0],
|
|
1233
|
+
setImage = _useState2[1];
|
|
1234
|
+
var fileRef = useRef();
|
|
1235
|
+
var beforeUploadRef = useRef();
|
|
1236
|
+
var resolveRef = useRef();
|
|
1237
|
+
var rejectRef = useRef();
|
|
1020
1238
|
//存储回调
|
|
1021
|
-
|
|
1239
|
+
var cbRef = useRef({});
|
|
1022
1240
|
cbRef.current.onModalOk = onModalOk;
|
|
1023
1241
|
cbRef.current.onModalCancel = onModalCancel;
|
|
1024
1242
|
cbRef.current.beforeCrop = beforeCrop;
|
|
1025
1243
|
cbRef.current.onUploadFail = onUploadFail;
|
|
1026
|
-
|
|
1244
|
+
var easyCropRef = useRef({});
|
|
1027
1245
|
//上传组件
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
accept
|
|
1034
|
-
} = _a,
|
|
1246
|
+
var uploadComponent = useMemo(function () {
|
|
1247
|
+
var upload = Array.isArray(children) ? children[0] : children;
|
|
1248
|
+
var _a = upload.props,
|
|
1249
|
+
beforeUpload = _a.beforeUpload,
|
|
1250
|
+
accept = _a.accept,
|
|
1035
1251
|
restUploadProps = __rest(_a, ["beforeUpload", "accept"]);
|
|
1036
1252
|
beforeUploadRef.current = beforeUpload;
|
|
1037
1253
|
return Object.assign(Object.assign({}, upload), {
|
|
1038
1254
|
props: Object.assign(Object.assign({}, restUploadProps), {
|
|
1039
1255
|
accept: accept || 'image/*',
|
|
1040
|
-
beforeUpload: (file, fileList)
|
|
1041
|
-
return new Promise((resolve, reject)
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
return
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1256
|
+
beforeUpload: function beforeUpload(file, fileList) {
|
|
1257
|
+
return new Promise(function (resolve, reject) {
|
|
1258
|
+
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
|
|
1259
|
+
var reader;
|
|
1260
|
+
return regenerator.wrap(function _callee$(_context) {
|
|
1261
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1262
|
+
case 0:
|
|
1263
|
+
_context.t0 = cbRef.current.beforeCrop;
|
|
1264
|
+
if (!_context.t0) {
|
|
1265
|
+
_context.next = 5;
|
|
1266
|
+
break;
|
|
1267
|
+
}
|
|
1268
|
+
_context.next = 4;
|
|
1269
|
+
return cbRef.current.beforeCrop(file, fileList);
|
|
1270
|
+
case 4:
|
|
1271
|
+
_context.t0 = !_context.sent;
|
|
1272
|
+
case 5:
|
|
1273
|
+
if (!_context.t0) {
|
|
1274
|
+
_context.next = 8;
|
|
1275
|
+
break;
|
|
1276
|
+
}
|
|
1277
|
+
reject();
|
|
1278
|
+
return _context.abrupt("return");
|
|
1279
|
+
case 8:
|
|
1280
|
+
fileRef.current = file;
|
|
1281
|
+
resolveRef.current = function (newFile) {
|
|
1282
|
+
var flag = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
1283
|
+
var _a, _b;
|
|
1284
|
+
(_b = (_a = cbRef.current).onModalOk) === null || _b === void 0 ? void 0 : _b.call(_a, newFile);
|
|
1285
|
+
if (!flag) return resolve({
|
|
1286
|
+
cropFile: newFile,
|
|
1287
|
+
isUpload: flag
|
|
1288
|
+
});
|
|
1289
|
+
resolve(newFile);
|
|
1290
|
+
};
|
|
1291
|
+
rejectRef.current = function (uploadErr) {
|
|
1292
|
+
var _a, _b;
|
|
1293
|
+
(_b = (_a = cbRef.current).onUploadFail) === null || _b === void 0 ? void 0 : _b.call(_a, uploadErr);
|
|
1294
|
+
reject(uploadErr);
|
|
1295
|
+
};
|
|
1296
|
+
reader = new FileReader();
|
|
1297
|
+
reader.addEventListener('load', function () {
|
|
1298
|
+
return typeof reader.result === 'string' && setImage(reader.result);
|
|
1299
|
+
});
|
|
1300
|
+
reader.readAsDataURL(file);
|
|
1301
|
+
case 14:
|
|
1302
|
+
case "end":
|
|
1303
|
+
return _context.stop();
|
|
1304
|
+
}
|
|
1305
|
+
}, _callee);
|
|
1306
|
+
}));
|
|
1307
|
+
});
|
|
1066
1308
|
}
|
|
1067
1309
|
})
|
|
1068
1310
|
});
|
|
1069
1311
|
}, [children]);
|
|
1070
1312
|
//modal 关闭后操作
|
|
1071
|
-
|
|
1313
|
+
var onClose = function onClose() {
|
|
1072
1314
|
setImage('');
|
|
1073
1315
|
easyCropRef.current.setZoomVal(INIT_ZOOM);
|
|
1074
1316
|
easyCropRef.current.setRotateVal(INIT_ROTATE);
|
|
1075
1317
|
};
|
|
1076
1318
|
//modal cancel
|
|
1077
|
-
|
|
1319
|
+
var onCancel = useCallback(function () {
|
|
1078
1320
|
var _a, _b;
|
|
1079
1321
|
(_b = (_a = cbRef.current).onModalCancel) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
1080
1322
|
onClose();
|
|
1081
1323
|
}, []);
|
|
1082
1324
|
//modal ok
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1325
|
+
var onOk = useCallback(function () {
|
|
1326
|
+
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee3() {
|
|
1327
|
+
var canvas, ctx, imgSource, _easyCropRef$current$, cropWidth, cropHeight, cropX, cropY, imgWidth, imgHeight, angle, sine, cosine, squareWidth, squareHeight, squareHalfWidth, squareHalfHeight, imgX, imgY, imgData, changeImageSizeAfterCrop, _fileRef$current, type, name, uid, idx, onBlob;
|
|
1328
|
+
return regenerator.wrap(function _callee3$(_context3) {
|
|
1329
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
1330
|
+
case 0:
|
|
1331
|
+
onClose();
|
|
1332
|
+
canvas = document.createElement('canvas');
|
|
1333
|
+
ctx = canvas.getContext('2d');
|
|
1334
|
+
imgSource = document.querySelector(".".concat(PREFIX, "-media"));
|
|
1335
|
+
_easyCropRef$current$ = easyCropRef.current.cropPixelsRef.current, cropWidth = _easyCropRef$current$.width, cropHeight = _easyCropRef$current$.height, cropX = _easyCropRef$current$.x, cropY = _easyCropRef$current$.y;
|
|
1336
|
+
if (rotate && easyCropRef.current.rotateVal !== INIT_ROTATE) {
|
|
1337
|
+
imgWidth = imgSource.naturalWidth, imgHeight = imgSource.naturalHeight;
|
|
1338
|
+
angle = easyCropRef.current.rotateVal * (Math.PI / 180); // get container for rotated image
|
|
1339
|
+
sine = Math.abs(Math.sin(angle));
|
|
1340
|
+
cosine = Math.abs(Math.cos(angle));
|
|
1341
|
+
squareWidth = imgWidth * cosine + imgHeight * sine;
|
|
1342
|
+
squareHeight = imgHeight * cosine + imgWidth * sine;
|
|
1343
|
+
canvas.width = squareWidth;
|
|
1344
|
+
canvas.height = squareHeight;
|
|
1345
|
+
ctx.fillStyle = fillColor;
|
|
1346
|
+
ctx.fillRect(0, 0, squareWidth, squareHeight);
|
|
1347
|
+
// rotate container
|
|
1348
|
+
squareHalfWidth = squareWidth / 2;
|
|
1349
|
+
squareHalfHeight = squareHeight / 2;
|
|
1350
|
+
ctx.translate(squareHalfWidth, squareHalfHeight);
|
|
1351
|
+
ctx.rotate(angle);
|
|
1352
|
+
ctx.translate(-squareHalfWidth, -squareHalfHeight);
|
|
1353
|
+
// draw rotated image
|
|
1354
|
+
imgX = (squareWidth - imgWidth) / 2;
|
|
1355
|
+
imgY = (squareHeight - imgHeight) / 2;
|
|
1356
|
+
ctx.drawImage(imgSource, 0, 0, imgWidth, imgHeight, imgX, imgY, imgWidth, imgHeight);
|
|
1357
|
+
// crop rotated image
|
|
1358
|
+
imgData = ctx.getImageData(0, 0, squareWidth, squareHeight);
|
|
1359
|
+
canvas.width = cropWidth;
|
|
1360
|
+
canvas.height = cropHeight;
|
|
1361
|
+
ctx.putImageData(imgData, -cropX, -cropY);
|
|
1362
|
+
} else {
|
|
1363
|
+
canvas.width = cropWidth;
|
|
1364
|
+
canvas.height = cropHeight;
|
|
1365
|
+
ctx.fillStyle = fillColor;
|
|
1366
|
+
ctx.fillRect(0, 0, cropWidth, cropHeight);
|
|
1367
|
+
ctx.drawImage(imgSource, cropX, cropY, cropWidth, cropHeight, 0, 0, cropWidth, cropHeight);
|
|
1368
|
+
}
|
|
1369
|
+
//裁剪之后改变图片大小
|
|
1370
|
+
changeImageSizeAfterCrop = function changeImageSizeAfterCrop(newFile) {
|
|
1371
|
+
return new Promise(function (resolve) {
|
|
1372
|
+
var name = newFile.name,
|
|
1373
|
+
type = newFile.type,
|
|
1374
|
+
uid = newFile.uid;
|
|
1375
|
+
var width = fixedCropSize.width,
|
|
1376
|
+
height = fixedCropSize.height; //固定裁剪大小
|
|
1377
|
+
var changeCanvas = document.createElement('canvas');
|
|
1378
|
+
var changeCtx = changeCanvas.getContext('2d');
|
|
1379
|
+
var img = new Image();
|
|
1380
|
+
img.onload = function () {
|
|
1381
|
+
changeCanvas.width = width;
|
|
1382
|
+
changeCanvas.height = height;
|
|
1383
|
+
changeCtx.drawImage(img, 0, 0, width, height);
|
|
1384
|
+
changeCanvas.toBlob(function (cBlob) {
|
|
1385
|
+
var changeFile = Object.assign(new File([cBlob], name, {
|
|
1386
|
+
type: type
|
|
1387
|
+
}), {
|
|
1388
|
+
uid: uid
|
|
1389
|
+
});
|
|
1390
|
+
resolve(changeFile);
|
|
1391
|
+
}, type, quality);
|
|
1392
|
+
};
|
|
1393
|
+
img.onerror = function () {
|
|
1394
|
+
resolve(newFile);
|
|
1395
|
+
};
|
|
1396
|
+
var fileReader = new FileReader();
|
|
1397
|
+
fileReader.onload = function () {
|
|
1398
|
+
img.src = fileReader.result;
|
|
1399
|
+
};
|
|
1400
|
+
fileReader.onerror = function () {
|
|
1401
|
+
resolve(newFile);
|
|
1402
|
+
};
|
|
1403
|
+
fileReader.readAsDataURL(newFile);
|
|
1404
|
+
});
|
|
1405
|
+
}; // get the new image
|
|
1406
|
+
_fileRef$current = fileRef.current, type = _fileRef$current.type, name = _fileRef$current.name, uid = _fileRef$current.uid;
|
|
1407
|
+
if (/svg/gi.test(type)) {
|
|
1408
|
+
//svg 转为 png
|
|
1409
|
+
type = 'image/png';
|
|
1410
|
+
idx = name.lastIndexOf('.');
|
|
1411
|
+
if (idx > -1) name = "".concat(name.substring(0, idx), ".png");
|
|
1412
|
+
}
|
|
1413
|
+
//转为blob
|
|
1414
|
+
onBlob = function onBlob(blob) {
|
|
1415
|
+
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee2() {
|
|
1416
|
+
var _a, _b, _c, _d, _e, _f, newFile, changeFile, res, passedFile;
|
|
1417
|
+
return regenerator.wrap(function _callee2$(_context2) {
|
|
1418
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
1419
|
+
case 0:
|
|
1420
|
+
newFile = Object.assign(new File([blob], name, {
|
|
1421
|
+
type: type
|
|
1422
|
+
}), {
|
|
1423
|
+
uid: uid
|
|
1424
|
+
});
|
|
1425
|
+
_context2.next = 3;
|
|
1426
|
+
return changeImageSizeAfterCrop(newFile);
|
|
1427
|
+
case 3:
|
|
1428
|
+
changeFile = _context2.sent;
|
|
1429
|
+
if (!(typeof beforeUploadRef.current !== 'function')) {
|
|
1430
|
+
_context2.next = 6;
|
|
1431
|
+
break;
|
|
1432
|
+
}
|
|
1433
|
+
return _context2.abrupt("return", (_a = resolveRef.current) === null || _a === void 0 ? void 0 : _a.call(resolveRef, changeFile));
|
|
1434
|
+
case 6:
|
|
1435
|
+
res = beforeUploadRef.current(changeFile, [changeFile]);
|
|
1436
|
+
if (!(typeof res !== 'boolean' && !res)) {
|
|
1437
|
+
_context2.next = 10;
|
|
1438
|
+
break;
|
|
1439
|
+
}
|
|
1440
|
+
console.error('beforeUpload must return a boolean or Promise');
|
|
1441
|
+
return _context2.abrupt("return");
|
|
1442
|
+
case 10:
|
|
1443
|
+
if (!(res === true)) {
|
|
1444
|
+
_context2.next = 12;
|
|
1445
|
+
break;
|
|
1446
|
+
}
|
|
1447
|
+
return _context2.abrupt("return", (_b = resolveRef.current) === null || _b === void 0 ? void 0 : _b.call(resolveRef, changeFile));
|
|
1448
|
+
case 12:
|
|
1449
|
+
if (!(res === false)) {
|
|
1450
|
+
_context2.next = 14;
|
|
1451
|
+
break;
|
|
1452
|
+
}
|
|
1453
|
+
return _context2.abrupt("return", (_c = resolveRef.current) === null || _c === void 0 ? void 0 : _c.call(resolveRef, changeFile, false));
|
|
1454
|
+
case 14:
|
|
1455
|
+
if (!(res && res instanceof Promise)) {
|
|
1456
|
+
_context2.next = 27;
|
|
1457
|
+
break;
|
|
1458
|
+
}
|
|
1459
|
+
_context2.prev = 15;
|
|
1460
|
+
_context2.next = 18;
|
|
1461
|
+
return res;
|
|
1462
|
+
case 18:
|
|
1463
|
+
passedFile = _context2.sent;
|
|
1464
|
+
if (!(passedFile instanceof File || passedFile instanceof Blob)) {
|
|
1465
|
+
_context2.next = 21;
|
|
1466
|
+
break;
|
|
1467
|
+
}
|
|
1468
|
+
return _context2.abrupt("return", (_d = resolveRef.current) === null || _d === void 0 ? void 0 : _d.call(resolveRef, passedFile));
|
|
1469
|
+
case 21:
|
|
1470
|
+
(_e = resolveRef.current) === null || _e === void 0 ? void 0 : _e.call(resolveRef, changeFile, passedFile);
|
|
1471
|
+
_context2.next = 27;
|
|
1472
|
+
break;
|
|
1473
|
+
case 24:
|
|
1474
|
+
_context2.prev = 24;
|
|
1475
|
+
_context2.t0 = _context2["catch"](15);
|
|
1476
|
+
(_f = rejectRef.current) === null || _f === void 0 ? void 0 : _f.call(rejectRef, _context2.t0);
|
|
1477
|
+
case 27:
|
|
1478
|
+
case "end":
|
|
1479
|
+
return _context2.stop();
|
|
1480
|
+
}
|
|
1481
|
+
}, _callee2, null, [[15, 24]]);
|
|
1482
|
+
}));
|
|
1483
|
+
};
|
|
1484
|
+
canvas.toBlob(onBlob, type, quality);
|
|
1485
|
+
case 11:
|
|
1486
|
+
case "end":
|
|
1487
|
+
return _context3.stop();
|
|
1212
1488
|
}
|
|
1213
|
-
}
|
|
1214
|
-
});
|
|
1215
|
-
|
|
1216
|
-
}), [fillColor, quality, rotate]);
|
|
1489
|
+
}, _callee3);
|
|
1490
|
+
}));
|
|
1491
|
+
}, [fillColor, quality, rotate]);
|
|
1217
1492
|
//img crop 组件
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1493
|
+
var getComponent = function getComponent(titleOfModal) {
|
|
1494
|
+
return jsxs(Fragment, {
|
|
1495
|
+
children: [uploadComponent, image && jsx(Modal, Object.assign({
|
|
1496
|
+
open: true,
|
|
1497
|
+
className: "".concat(PREFIX, "-modal"),
|
|
1498
|
+
size: 'md',
|
|
1499
|
+
title: titleOfModal !== null && titleOfModal !== void 0 ? titleOfModal : intl({
|
|
1500
|
+
id: 'editImage'
|
|
1501
|
+
}),
|
|
1502
|
+
onOk: onOk,
|
|
1503
|
+
onCancel: onCancel,
|
|
1504
|
+
okText: modalOk,
|
|
1505
|
+
cancelText: modalCancel,
|
|
1506
|
+
contentWidth: modalWidth
|
|
1507
|
+
}, {
|
|
1508
|
+
children: jsx(EasyCrop$1, {
|
|
1509
|
+
ref: easyCropRef,
|
|
1510
|
+
cropperRef: ref,
|
|
1511
|
+
image: image,
|
|
1512
|
+
aspect: aspect,
|
|
1513
|
+
shape: shape,
|
|
1514
|
+
grid: grid,
|
|
1515
|
+
zoom: zoom,
|
|
1516
|
+
rotate: rotate,
|
|
1517
|
+
minZoom: minZoom,
|
|
1518
|
+
maxZoom: maxZoom,
|
|
1519
|
+
fixedCropSize: fixedCropSize,
|
|
1520
|
+
cropperProps: cropperProps,
|
|
1521
|
+
zoomTipFormatter: zoomTipFormatter,
|
|
1522
|
+
zoomMarks: zoomMarks,
|
|
1523
|
+
rotateMarks: rotateMarks,
|
|
1524
|
+
rotateTipFormatter: rotateTipFormatter
|
|
1525
|
+
})
|
|
1526
|
+
}))]
|
|
1527
|
+
});
|
|
1528
|
+
};
|
|
1252
1529
|
return jsx(Fragment, {
|
|
1253
1530
|
children: getComponent(modalTitle)
|
|
1254
1531
|
});
|