@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/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
- const FileIcon = props => {
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
- const UploadList = props => {
180
- const {
181
- listType = 'text',
182
- items = [],
183
- onRemove,
184
- showRemoveIcon = true,
185
- showPreviewIcon = true,
186
- previewIcon,
187
- removeIcon,
188
- itemRender,
189
- readonly,
190
- operateBtnProps,
191
- actionRender,
192
- onPreview
193
- } = props;
194
- const [uploadList, setUploadList] = useState([]);
195
- const [visible, setVisible] = useState(false);
196
- const [current, setCurrent] = useState(0);
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
- const handleRemove = (file, evt) => {
216
+ var handleRemove = function handleRemove(file, evt) {
200
217
  evt.stopPropagation();
201
- onRemove === null || onRemove === void 0 ? void 0 : onRemove(file);
218
+ _onRemove === null || _onRemove === void 0 ? void 0 : _onRemove(file);
202
219
  };
203
- const isError = file => file.status === 'error';
204
- const onImageError = file => {
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([...uploadList]);
226
+ setUploadList(_toConsumableArray(uploadList));
208
227
  };
209
- const previewItems = useMemo(() => {
228
+ var previewItems = useMemo(function () {
210
229
  var _a;
211
- const originItems = items === null || items === void 0 ? void 0 : items.filter(item => isImageUrl(item) && !isError(item));
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(i => i.url || i.thumbUrl)) === null || _a === void 0 ? void 0 : _a.filter(i => !!i)) || [],
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
- const getCurrent = file => {
218
- return previewItems.originItems.findIndex(i => i.uid === file.uid);
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
- const handlePreview = (file, e) => __awaiter(void 0, void 0, void 0, function* () {
222
- const shouldPreview = yield onPreview === null || onPreview === void 0 ? void 0 : onPreview(file, e);
223
- if (shouldPreview === false) return;
224
- const currentIndex = getCurrent(file);
225
- if (currentIndex === -1) return;
226
- setCurrent(currentIndex);
227
- setVisible(true);
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
- const pictureCardAction = file => {
231
- const list = [];
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
- const onClick = (item, e) => {
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
- const renderActions = file => {
254
- const actions = {
255
- onRemove: () => onRemove === null || onRemove === void 0 ? void 0 : onRemove(file),
256
- onPreview: () => handlePreview(file)
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: evt => handleRemove(file, evt)
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
- const renderIcon = file => {
276
- const isImage = isImageUrl(file);
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
- const renderTextItem = file => {
281
- const listItemNameClass = 'upload-list-text-name';
282
- const fileName = file.url && !isError(file) ? jsx("a", Object.assign({
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: e => onPreview === null || onPreview === void 0 ? void 0 : onPreview(file, e)
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: e => onPreview === null || onPreview === void 0 ? void 0 : onPreview(file, e),
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
- const listItem = jsxs("div", Object.assign({
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
- const renderFileListText = () => {
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
- const renderFileListPicture = () => {
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
- let isImage = isImageUrl(file);
349
- let pictureItem = jsxs(Fragment, {
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: () => onImageError(file)
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
- const handleFileFormat = () => __awaiter(void 0, void 0, void 0, function* () {
385
- if (!(items === null || items === void 0 ? void 0 : items.length)) return setUploadList([]);
386
- //读取file as DataUrl
387
- const readerFileAsDataUrl = file => __awaiter(void 0, void 0, void 0, function* () {
388
- return new Promise(resolve => {
389
- const fileReader = new FileReader();
390
- if (file.originFileObj) {
391
- fileReader.onload = () => {
392
- resolve(fileReader.result);
393
- };
394
- fileReader.readAsDataURL(file.originFileObj);
395
- } else resolve('');
396
- });
397
- });
398
- for (const file of items) {
399
- if (file.originFileObj) {
400
- const dataUrl = yield readerFileAsDataUrl(file);
401
- file.dataUrl = dataUrl;
402
- }
403
- }
404
- setUploadList([...items]);
405
- });
406
- useEffect(() => {
407
- if (listType === 'picture-card') handleFileFormat();else setUploadList(pre => {
408
- if (items) return [...items];
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
- const ErrorTip = props => {
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
- const ImageUpload = props => {
483
- const {
484
- className,
485
- style,
486
- onStart,
487
- onSuccess,
488
- onError,
489
- onProgress,
490
- onRemove,
491
- beforeUpload,
492
- onChange,
493
- defaultFileList = [],
494
- fileList,
495
- showUploadList = true,
496
- maxCount,
497
- children = null,
498
- itemRender,
499
- showUploadError = false,
500
- stash = false,
501
- uploading = true,
502
- loading = false,
503
- showLoading: showLoadingProp = false,
504
- defaultImage,
505
- readonly,
506
- onPreview,
507
- actionRender,
508
- operateBtnProps,
509
- disabledTooltip,
510
- removeErrorTip
511
- } = props,
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
- const intl = useFormatMessage('Upload', localeJson);
514
- const [uploadFileList, setUploadFileList] = useState(defaultFileList); //文件列表
515
- const [showLoading, setShowLoading] = useState(false); //upload loading
516
- const [errTip, setErrTip] = useState(false); //upload error tip
517
- const [avatar, setAvatar] = useState({
518
- imageUrl: ''
519
- }); //不显示列表时上传头像
520
- const {
521
- showRemoveIcon,
522
- removeIcon,
523
- showPreviewIcon,
524
- previewIcon
525
- } = typeof showUploadList === 'boolean' ? {} : showUploadList; //显示上传列表
526
- const {
527
- uploadErrorMsg = intl({
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
- leaveDelay = 2000
531
- } = typeof showUploadError === 'boolean' ? {} : showUploadError; //错误信息提示
532
- const cropFileRef = useRef(); //裁剪文件
533
- const isAvatarMode = useMemo(() => !showUploadList && avatar.imageUrl && !showLoading, [showUploadList, avatar.imageUrl, showLoading]);
534
- useEffect(() => {
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
- const overrideProps = Object.assign(Object.assign({
674
+ var overrideProps = Object.assign(Object.assign({
539
675
  accept: 'image/*'
540
676
  }, restProps), {
541
- beforeUpload: (file, fileList) => __awaiter(void 0, void 0, void 0, function* () {
542
- if (restProps.action && showLoadingProp && uploading) setShowLoading(true);
543
- const result = yield beforeUpload === null || beforeUpload === void 0 ? void 0 : beforeUpload(file, fileList);
544
- if (result === false) {
545
- setShowLoading(false);
546
- return false;
547
- } else if (typeof result === 'object' && result) {
548
- if (result instanceof File || result instanceof Blob) return result;
549
- cropFileRef.current = result.cropFile;
550
- return result.isUpload;
551
- } else return true;
552
- }),
553
- onStart(file) {
554
- onStart === null || onStart === void 0 ? void 0 : onStart(file);
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
- onSuccess(response, file, xhr) {
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
- const nextFileList = updateFileList(file);
722
+ var nextFileList = updateFileList(file);
560
723
  onInternalChange(nextFileList);
561
- onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response, file, xhr);
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
- const nextFileList = updateFileList(file);
732
+ var nextFileList = updateFileList(file);
570
733
  onInternalChange(nextFileList);
571
734
  }
572
- onError === null || onError === void 0 ? void 0 : onError(error, response, file);
735
+ _onError === null || _onError === void 0 ? void 0 : _onError(error, response, file);
573
736
  },
574
- onProgress(e, file) {
575
- onProgress === null || onProgress === void 0 ? void 0 : onProgress(e, file);
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
- const idx = fileList.findIndex(_ => {
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
- const arr = fileList.map(_ => _.parsedFile || _.file);
592
- const mList = mergedFileList(arr);
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
- const onInternalChange = changedFileList => __awaiter(void 0, void 0, void 0, function* () {
599
- let cloneList = [...changedFileList];
600
- if (!showUploadList) {
601
- //不显示上传列表
602
- const file = cloneList.slice(-1)[0];
603
- if (file) {
604
- const imageUrl = yield readerFileAsDataUrl(file);
605
- file.dataUrl = imageUrl;
606
- avatar.imageUrl = imageUrl;
607
- avatar.imageName = file.name;
608
- setAvatar(Object.assign({}, avatar));
609
- }
610
- onChange === null || onChange === void 0 ? void 0 : onChange([file]);
611
- return;
612
- }
613
- if (maxCount === 1) {
614
- cloneList = cloneList.slice(-1);
615
- } else if (maxCount) {
616
- cloneList = cloneList.slice(0, maxCount);
617
- }
618
- onChange === null || onChange === void 0 ? void 0 : onChange(cloneList);
619
- setUploadFileList(cloneList);
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
- const updateFileList = file => {
623
- const cloneList = [...uploadFileList];
624
- const fileObj = Object.assign(Object.assign({}, file), {
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
- const mergedFileList = fileList => {
637
- const cloneList = [...uploadFileList];
638
- const newFileList = fileList.map(file => {
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
- const handleRemove = file => {
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
- const idx = uploadFileList.findIndex(_ => _.uid === file.uid);
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
- const readerFileAsDataUrl = file => __awaiter(void 0, void 0, void 0, function* () {
663
- return new Promise(resolve => {
664
- const fileReader = new FileReader();
665
- if (file.originFileObj) {
666
- fileReader.onload = () => {
667
- resolve(fileReader.result);
668
- };
669
- fileReader.readAsDataURL(file.originFileObj);
670
- } else resolve('');
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
- const showErrTip = flag => {
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([...fileList]);
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
- const renderUploadList = () => showUploadList && jsx(UploadList, {
693
- listType: 'picture-card',
694
- readonly: readonly,
695
- items: uploadFileList,
696
- showRemoveIcon: showRemoveIcon,
697
- removeIcon: removeIcon,
698
- showPreviewIcon: showPreviewIcon,
699
- previewIcon: previewIcon,
700
- onRemove: handleRemove,
701
- itemRender: itemRender,
702
- onPreview: onPreview,
703
- actionRender: actionRender,
704
- operateBtnProps: operateBtnProps
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
- const renderUploadContent = () => {
906
+ var renderUploadContent = function renderUploadContent() {
708
907
  var _a;
709
- const avatarUploadNode = jsxs("div", Object.assign({
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
- const uploadNode = jsxs(Fragment, {
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
- const renderUploadSelector = () => {
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
- const Dragger = props => {
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
- const ImgCrop = /*#__PURE__*/forwardRef((props, ref) => {
985
- const {
986
- aspect = 1,
987
- shape = 'rect',
988
- grid = false,
989
- quality = 0.4,
990
- fillColor = 'transparent',
991
- zoom = true,
992
- rotate = false,
993
- minZoom = 1,
994
- maxZoom = 3,
995
- modalTitle,
996
- modalWidth,
997
- modalOk,
998
- modalCancel,
999
- onModalOk,
1000
- onModalCancel,
1001
- beforeCrop,
1002
- onUploadFail,
1003
- cropperProps,
1004
- children,
1005
- fixedCropSize = {
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
- zoomTipFormatter = val => "".concat(Number(val) * 10 * 10),
1010
- zoomMarks = true,
1011
- rotateMarks = true,
1012
- rotateTipFormatter = val => "".concat(val)
1013
- } = props;
1014
- const intl = useFormatMessage('Upload', localeJson);
1015
- const [image, setImage] = useState('');
1016
- const fileRef = useRef();
1017
- const beforeUploadRef = useRef();
1018
- const resolveRef = useRef();
1019
- const rejectRef = useRef();
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
- const cbRef = useRef({});
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
- const easyCropRef = useRef({});
1244
+ var easyCropRef = useRef({});
1027
1245
  //上传组件
1028
- const uploadComponent = useMemo(() => {
1029
- const upload = Array.isArray(children) ? children[0] : children;
1030
- const _a = upload.props,
1031
- {
1032
- beforeUpload,
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) => __awaiter(void 0, void 0, void 0, function* () {
1042
- if (cbRef.current.beforeCrop && !(yield cbRef.current.beforeCrop(file, fileList))) {
1043
- reject();
1044
- return;
1045
- }
1046
- fileRef.current = file;
1047
- resolveRef.current = function (newFile) {
1048
- let flag = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
1049
- var _a, _b;
1050
- (_b = (_a = cbRef.current).onModalOk) === null || _b === void 0 ? void 0 : _b.call(_a, newFile);
1051
- if (!flag) return resolve({
1052
- cropFile: newFile,
1053
- isUpload: flag
1054
- });
1055
- resolve(newFile);
1056
- };
1057
- rejectRef.current = uploadErr => {
1058
- var _a, _b;
1059
- (_b = (_a = cbRef.current).onUploadFail) === null || _b === void 0 ? void 0 : _b.call(_a, uploadErr);
1060
- reject(uploadErr);
1061
- };
1062
- const reader = new FileReader();
1063
- reader.addEventListener('load', () => typeof reader.result === 'string' && setImage(reader.result));
1064
- reader.readAsDataURL(file);
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
- const onClose = () => {
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
- const onCancel = useCallback(() => {
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
- const onOk = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
1084
- onClose();
1085
- const canvas = document.createElement('canvas');
1086
- const ctx = canvas.getContext('2d');
1087
- const imgSource = document.querySelector(".".concat(PREFIX, "-media"));
1088
- const {
1089
- width: cropWidth,
1090
- height: cropHeight,
1091
- x: cropX,
1092
- y: cropY
1093
- } = easyCropRef.current.cropPixelsRef.current;
1094
- if (rotate && easyCropRef.current.rotateVal !== INIT_ROTATE) {
1095
- const {
1096
- naturalWidth: imgWidth,
1097
- naturalHeight: imgHeight
1098
- } = imgSource;
1099
- const angle = easyCropRef.current.rotateVal * (Math.PI / 180);
1100
- // get container for rotated image
1101
- const sine = Math.abs(Math.sin(angle));
1102
- const cosine = Math.abs(Math.cos(angle));
1103
- const squareWidth = imgWidth * cosine + imgHeight * sine;
1104
- const squareHeight = imgHeight * cosine + imgWidth * sine;
1105
- canvas.width = squareWidth;
1106
- canvas.height = squareHeight;
1107
- ctx.fillStyle = fillColor;
1108
- ctx.fillRect(0, 0, squareWidth, squareHeight);
1109
- // rotate container
1110
- const squareHalfWidth = squareWidth / 2;
1111
- const squareHalfHeight = squareHeight / 2;
1112
- ctx.translate(squareHalfWidth, squareHalfHeight);
1113
- ctx.rotate(angle);
1114
- ctx.translate(-squareHalfWidth, -squareHalfHeight);
1115
- // draw rotated image
1116
- const imgX = (squareWidth - imgWidth) / 2;
1117
- const imgY = (squareHeight - imgHeight) / 2;
1118
- ctx.drawImage(imgSource, 0, 0, imgWidth, imgHeight, imgX, imgY, imgWidth, imgHeight);
1119
- // crop rotated image
1120
- const imgData = ctx.getImageData(0, 0, squareWidth, squareHeight);
1121
- canvas.width = cropWidth;
1122
- canvas.height = cropHeight;
1123
- ctx.putImageData(imgData, -cropX, -cropY);
1124
- } else {
1125
- canvas.width = cropWidth;
1126
- canvas.height = cropHeight;
1127
- ctx.fillStyle = fillColor;
1128
- ctx.fillRect(0, 0, cropWidth, cropHeight);
1129
- ctx.drawImage(imgSource, cropX, cropY, cropWidth, cropHeight, 0, 0, cropWidth, cropHeight);
1130
- }
1131
- //裁剪之后改变图片大小
1132
- const changeImageSizeAfterCrop = newFile => {
1133
- return new Promise(resolve => {
1134
- const {
1135
- name,
1136
- type,
1137
- uid
1138
- } = newFile;
1139
- const {
1140
- width,
1141
- height
1142
- } = fixedCropSize; //固定裁剪大小
1143
- const changeCanvas = document.createElement('canvas');
1144
- const changeCtx = changeCanvas.getContext('2d');
1145
- const img = new Image();
1146
- img.onload = () => {
1147
- changeCanvas.width = width;
1148
- changeCanvas.height = height;
1149
- changeCtx.drawImage(img, 0, 0, width, height);
1150
- changeCanvas.toBlob(cBlob => {
1151
- const changeFile = Object.assign(new File([cBlob], name, {
1152
- type
1153
- }), {
1154
- uid
1155
- });
1156
- resolve(changeFile);
1157
- }, type, quality);
1158
- };
1159
- img.onerror = () => {
1160
- resolve(newFile);
1161
- };
1162
- const fileReader = new FileReader();
1163
- fileReader.onload = () => {
1164
- img.src = fileReader.result;
1165
- };
1166
- fileReader.onerror = () => {
1167
- resolve(newFile);
1168
- };
1169
- fileReader.readAsDataURL(newFile);
1170
- });
1171
- };
1172
- // get the new image
1173
- let {
1174
- type,
1175
- name,
1176
- uid
1177
- } = fileRef.current;
1178
- if (/svg/gi.test(type)) {
1179
- //svg 转为 png
1180
- type = 'image/png';
1181
- const idx = name.lastIndexOf('.');
1182
- if (idx > -1) name = "".concat(name.substring(0, idx), ".png");
1183
- }
1184
- //转为blob
1185
- const onBlob = blob => __awaiter(void 0, void 0, void 0, function* () {
1186
- var _a, _b, _c, _d, _e, _f;
1187
- const newFile = Object.assign(new File([blob], name, {
1188
- type
1189
- }), {
1190
- uid
1191
- });
1192
- const changeFile = yield changeImageSizeAfterCrop(newFile);
1193
- if (typeof beforeUploadRef.current !== 'function') {
1194
- return (_a = resolveRef.current) === null || _a === void 0 ? void 0 : _a.call(resolveRef, changeFile);
1195
- }
1196
- const res = beforeUploadRef.current(changeFile, [changeFile]);
1197
- if (typeof res !== 'boolean' && !res) {
1198
- console.error('beforeUpload must return a boolean or Promise');
1199
- return;
1200
- }
1201
- if (res === true) return (_b = resolveRef.current) === null || _b === void 0 ? void 0 : _b.call(resolveRef, changeFile);
1202
- if (res === false) return (_c = resolveRef.current) === null || _c === void 0 ? void 0 : _c.call(resolveRef, changeFile, false);
1203
- if (res && res instanceof Promise) {
1204
- try {
1205
- const passedFile = yield res;
1206
- if (passedFile instanceof File || passedFile instanceof Blob) {
1207
- return (_d = resolveRef.current) === null || _d === void 0 ? void 0 : _d.call(resolveRef, passedFile);
1208
- }
1209
- (_e = resolveRef.current) === null || _e === void 0 ? void 0 : _e.call(resolveRef, changeFile, passedFile);
1210
- } catch (err) {
1211
- (_f = rejectRef.current) === null || _f === void 0 ? void 0 : _f.call(rejectRef, err);
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
- canvas.toBlob(onBlob, type, quality);
1216
- }), [fillColor, quality, rotate]);
1489
+ }, _callee3);
1490
+ }));
1491
+ }, [fillColor, quality, rotate]);
1217
1492
  //img crop 组件
1218
- const getComponent = titleOfModal => jsxs(Fragment, {
1219
- children: [uploadComponent, image && jsx(Modal, Object.assign({
1220
- open: true,
1221
- className: "".concat(PREFIX, "-modal"),
1222
- size: 'md',
1223
- title: titleOfModal !== null && titleOfModal !== void 0 ? titleOfModal : intl({
1224
- id: 'editImage'
1225
- }),
1226
- onOk: onOk,
1227
- onCancel: onCancel,
1228
- okText: modalOk,
1229
- cancelText: modalCancel,
1230
- contentWidth: modalWidth
1231
- }, {
1232
- children: jsx(EasyCrop$1, {
1233
- ref: easyCropRef,
1234
- cropperRef: ref,
1235
- image: image,
1236
- aspect: aspect,
1237
- shape: shape,
1238
- grid: grid,
1239
- zoom: zoom,
1240
- rotate: rotate,
1241
- minZoom: minZoom,
1242
- maxZoom: maxZoom,
1243
- fixedCropSize: fixedCropSize,
1244
- cropperProps: cropperProps,
1245
- zoomTipFormatter: zoomTipFormatter,
1246
- zoomMarks: zoomMarks,
1247
- rotateMarks: rotateMarks,
1248
- rotateTipFormatter: rotateTipFormatter
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
  });