@para-ui/core 4.0.29 → 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,15 +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
- import '../_verture/Portal-5bd49559.js';
39
+ import '../_verture/Portal-5bf66fed.js';
35
40
  import 'react-dom';
36
- import '../_verture/typeof-adeedc13.js';
37
- import '../_verture/toConsumableArray-8f4c9589.js';
38
- import '../_verture/unsupportedIterableToArray-cb478f24.js';
39
- import '../_verture/defineProperty-6f62bb2a.js';
40
41
  import 'rc-dialog';
41
42
  import 'rc-motion';
42
43
  import '@para-ui/icons/Sort';
@@ -92,7 +93,11 @@ var isImageUrl = function isImageUrl(file) {
92
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}";
93
94
  styleInject(css_248z$4);
94
95
 
95
- 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;
96
101
  return jsxs("svg", Object.assign({
97
102
  viewBox: "0 0 180 180",
98
103
  className: 'upload-list-picture-file'
@@ -177,59 +182,104 @@ const FileIcon = props => {
177
182
  }));
178
183
  };
179
184
  //UploadList
180
- const UploadList = props => {
181
- const {
182
- listType = 'text',
183
- items = [],
184
- onRemove,
185
- showRemoveIcon = true,
186
- showPreviewIcon = true,
187
- previewIcon,
188
- removeIcon,
189
- itemRender,
190
- readonly,
191
- operateBtnProps,
192
- actionRender,
193
- onPreview
194
- } = props;
195
- const [uploadList, setUploadList] = useState([]);
196
- const [visible, setVisible] = useState(false);
197
- 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];
198
214
  useRef(null);
199
215
  //处理删除
200
- const handleRemove = (file, evt) => {
216
+ var handleRemove = function handleRemove(file, evt) {
201
217
  evt.stopPropagation();
202
- onRemove === null || onRemove === void 0 ? void 0 : onRemove(file);
218
+ _onRemove === null || _onRemove === void 0 ? void 0 : _onRemove(file);
203
219
  };
204
- const isError = file => file.status === 'error';
205
- const onImageError = file => {
220
+ var isError = function isError(file) {
221
+ return file.status === 'error';
222
+ };
223
+ var onImageError = function onImageError(file) {
206
224
  if (file.status === 'error') return;
207
225
  file.status = 'error';
208
- setUploadList([...uploadList]);
226
+ setUploadList(_toConsumableArray(uploadList));
209
227
  };
210
- const previewItems = useMemo(() => {
228
+ var previewItems = useMemo(function () {
211
229
  var _a;
212
- 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
+ });
213
233
  return {
214
- 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
+ })) || [],
215
239
  originItems: originItems
216
240
  };
217
241
  }, [items]);
218
- const getCurrent = file => {
219
- 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
+ });
220
246
  };
221
247
  // 处理预览
222
- const handlePreview = (file, e) => __awaiter(void 0, void 0, void 0, function* () {
223
- const shouldPreview = yield onPreview === null || onPreview === void 0 ? void 0 : onPreview(file, e);
224
- if (shouldPreview === false) return;
225
- const currentIndex = getCurrent(file);
226
- if (currentIndex === -1) return;
227
- setCurrent(currentIndex);
228
- setVisible(true);
229
- });
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
+ };
230
280
  // 图片墙操作按钮
231
- const pictureCardAction = file => {
232
- const list = [];
281
+ var pictureCardAction = function pictureCardAction(file) {
282
+ var list = [];
233
283
  if (isImageUrl(file) && !isError(file) && showPreviewIcon) list.push({
234
284
  icon: previewIcon || jsx(PreviewOpen, {}),
235
285
  key: 'view'
@@ -239,7 +289,7 @@ const UploadList = props => {
239
289
  key: 'delete'
240
290
  });
241
291
  if (!list.length) return null;
242
- const onClick = (item, e) => {
292
+ var onClick = function onClick(item, e) {
243
293
  if (item.key === 'view') handlePreview(file, e);
244
294
  if (item.key === 'delete') handleRemove(file, e);
245
295
  };
@@ -251,10 +301,14 @@ const UploadList = props => {
251
301
  });
252
302
  };
253
303
  //渲染列表actions
254
- const renderActions = file => {
255
- const actions = {
256
- onRemove: () => onRemove === null || onRemove === void 0 ? void 0 : onRemove(file),
257
- 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
+ }
258
312
  };
259
313
  if (actionRender) return actionRender(file, actions);
260
314
  if (operateBtnProps) return jsx(OperateBtn, Object.assign({
@@ -266,37 +320,43 @@ const UploadList = props => {
266
320
  className: 'upload-list-actions'
267
321
  }, {
268
322
  children: showRemoveIcon && jsx("span", Object.assign({
269
- onClick: evt => handleRemove(file, evt)
323
+ onClick: function onClick(evt) {
324
+ return handleRemove(file, evt);
325
+ }
270
326
  }, {
271
327
  children: removeIcon || jsx(Delete, {})
272
328
  }))
273
329
  }));
274
330
  };
275
331
  // 渲染图标
276
- const renderIcon = file => {
277
- const isImage = isImageUrl(file);
332
+ var renderIcon = function renderIcon(file) {
333
+ var isImage = isImageUrl(file);
278
334
  if (file.status === 'error') return jsx(InfoOutlined, {});
279
335
  return isImage ? jsx(PhotoIcon, {}) : jsx(FileOutlined, {});
280
336
  };
281
- const renderTextItem = file => {
282
- const listItemNameClass = 'upload-list-text-name';
283
- 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({
284
340
  target: "_blank",
285
341
  rel: "noopener noreferrer",
286
342
  className: listItemNameClass,
287
343
  // title={file.name}
288
344
  href: file.url,
289
- 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
+ }
290
348
  }, {
291
349
  children: file.name
292
350
  }), "view") : jsx("div", Object.assign({
293
351
  className: listItemNameClass,
294
- 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
+ },
295
355
  title: file.name
296
356
  }, {
297
357
  children: file.name
298
358
  }), "view");
299
- const listItem = jsxs("div", Object.assign({
359
+ var listItem = jsxs("div", Object.assign({
300
360
  className: clsx('upload-list-text-item', isError(file) && 'upload-list-text-item-error')
301
361
  }, {
302
362
  children: [jsx("div", Object.assign({
@@ -317,9 +377,9 @@ const UploadList = props => {
317
377
  return listItem;
318
378
  };
319
379
  //文件列表 text
320
- const renderFileListText = () => {
380
+ var renderFileListText = function renderFileListText() {
321
381
  if (!(uploadList === null || uploadList === void 0 ? void 0 : uploadList.length)) return null;
322
- return uploadList.map((file, idx) => {
382
+ return uploadList.map(function (file, idx) {
323
383
  var _a;
324
384
  if (itemRender)
325
385
  //自定义渲染
@@ -341,17 +401,19 @@ const UploadList = props => {
341
401
  });
342
402
  };
343
403
  //文件列表 picture-card
344
- const renderFileListPicture = () => {
404
+ var renderFileListPicture = function renderFileListPicture() {
345
405
  if (!(uploadList === null || uploadList === void 0 ? void 0 : uploadList.length)) return null;
346
- return uploadList.map((file, idx) => {
406
+ return uploadList.map(function (file, idx) {
347
407
  /*自定义渲染*/
348
408
  if (itemRender) return itemRender(file, uploadList);
349
- let isImage = isImageUrl(file);
350
- let pictureItem = jsxs(Fragment, {
409
+ var isImage = isImageUrl(file);
410
+ var pictureItem = jsxs(Fragment, {
351
411
  children: [isImage ? jsx("img", {
352
412
  src: file.thumbUrl || file.dataUrl || file.url,
353
413
  alt: file.name,
354
- onError: () => onImageError(file)
414
+ onError: function onError() {
415
+ return onImageError(file);
416
+ }
355
417
  }) : jsx(FileIcon, {
356
418
  className: 'upload-list-picture-file'
357
419
  })
@@ -382,31 +444,84 @@ const UploadList = props => {
382
444
  });
383
445
  };
384
446
  //处理文件
385
- const handleFileFormat = () => __awaiter(void 0, void 0, void 0, function* () {
386
- if (!(items === null || items === void 0 ? void 0 : items.length)) return setUploadList([]);
387
- //读取file as DataUrl
388
- const readerFileAsDataUrl = file => __awaiter(void 0, void 0, void 0, function* () {
389
- return new Promise(resolve => {
390
- const fileReader = new FileReader();
391
- if (file.originFileObj) {
392
- fileReader.onload = () => {
393
- resolve(fileReader.result);
394
- };
395
- fileReader.readAsDataURL(file.originFileObj);
396
- } else resolve('');
397
- });
398
- });
399
- for (const file of items) {
400
- if (file.originFileObj) {
401
- const dataUrl = yield readerFileAsDataUrl(file);
402
- file.dataUrl = dataUrl;
403
- }
404
- }
405
- setUploadList([...items]);
406
- });
407
- useEffect(() => {
408
- if (listType === 'picture-card') handleFileFormat();else setUploadList(pre => {
409
- 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);
410
525
  return pre;
411
526
  });
412
527
  }, [items]);
@@ -421,14 +536,14 @@ const UploadList = props => {
421
536
  children: renderFileListPicture()
422
537
  })), jsx(Image$1.PreviewGroup, {
423
538
  preview: {
424
- visible,
425
- onVisibleChange: value => {
539
+ visible: visible,
540
+ onVisibleChange: function onVisibleChange(value) {
426
541
  setVisible(value);
427
542
  },
428
- onChange: value => {
543
+ onChange: function onChange(value) {
429
544
  setCurrent(value);
430
545
  },
431
- current
546
+ current: current
432
547
  },
433
548
  items: previewItems.items
434
549
  })]
@@ -439,7 +554,7 @@ var css_248z$3 = "@charset \"UTF-8\";\n/**\n* @author Hanz\n* @date 2021/11/15
439
554
  styleInject(css_248z$3);
440
555
 
441
556
  //error tip
442
- const ErrorTip = props => {
557
+ var ErrorTip = function ErrorTip(props) {
443
558
  return jsxs("div", Object.assign({
444
559
  className: clsx("".concat($prefixCls, "-upload-error"), props.className)
445
560
  }, {
@@ -472,113 +587,160 @@ var zh = {
472
587
  };
473
588
 
474
589
  var localeJson = {
475
- zh,
476
- en
590
+ zh: zh,
591
+ en: en
477
592
  };
478
593
 
479
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}";
480
595
  styleInject(css_248z$2);
481
596
 
482
597
  //ImageUpload
483
- const ImageUpload = props => {
484
- const {
485
- className,
486
- style,
487
- onStart,
488
- onSuccess,
489
- onError,
490
- onProgress,
491
- onRemove,
492
- beforeUpload,
493
- onChange,
494
- defaultFileList = [],
495
- fileList,
496
- showUploadList = true,
497
- maxCount,
498
- children = null,
499
- itemRender,
500
- showUploadError = false,
501
- stash = false,
502
- uploading = true,
503
- loading = false,
504
- showLoading: showLoadingProp = false,
505
- defaultImage,
506
- readonly,
507
- onPreview,
508
- actionRender,
509
- operateBtnProps,
510
- disabledTooltip,
511
- removeErrorTip
512
- } = 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,
513
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"]);
514
- const intl = useFormatMessage('Upload', localeJson);
515
- const [uploadFileList, setUploadFileList] = useState(defaultFileList); //文件列表
516
- const [showLoading, setShowLoading] = useState(false); //upload loading
517
- const [errTip, setErrTip] = useState(false); //upload error tip
518
- const [avatar, setAvatar] = useState({
519
- imageUrl: ''
520
- }); //不显示列表时上传头像
521
- const {
522
- showRemoveIcon,
523
- removeIcon,
524
- showPreviewIcon,
525
- previewIcon
526
- } = typeof showUploadList === 'boolean' ? {} : showUploadList; //显示上传列表
527
- const {
528
- uploadErrorMsg = intl({
529
- 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: ''
530
650
  }),
531
- leaveDelay = 2000
532
- } = typeof showUploadError === 'boolean' ? {} : showUploadError; //错误信息提示
533
- const cropFileRef = useRef(); //裁剪文件
534
- const isAvatarMode = useMemo(() => !showUploadList && avatar.imageUrl && !showLoading, [showUploadList, avatar.imageUrl, showLoading]);
535
- 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 () {
536
671
  setShowLoading(loading);
537
672
  }, [loading]);
538
673
  //复写属性
539
- const overrideProps = Object.assign(Object.assign({
674
+ var overrideProps = Object.assign(Object.assign({
540
675
  accept: 'image/*'
541
676
  }, restProps), {
542
- beforeUpload: (file, fileList) => __awaiter(void 0, void 0, void 0, function* () {
543
- if (restProps.action && showLoadingProp && uploading) setShowLoading(true);
544
- const result = yield beforeUpload === null || beforeUpload === void 0 ? void 0 : beforeUpload(file, fileList);
545
- if (result === false) {
546
- setShowLoading(false);
547
- return false;
548
- } else if (typeof result === 'object' && result) {
549
- if (result instanceof File || result instanceof Blob) return result;
550
- cropFileRef.current = result.cropFile;
551
- return result.isUpload;
552
- } else return true;
553
- }),
554
- onStart(file) {
555
- 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
+ }));
556
715
  },
557
- 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) {
558
720
  setShowLoading(false);
559
721
  errTip && showErrTip(false);
560
- const nextFileList = updateFileList(file);
722
+ var nextFileList = updateFileList(file);
561
723
  onInternalChange(nextFileList);
562
- onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response, file, xhr);
724
+ _onSuccess === null || _onSuccess === void 0 ? void 0 : _onSuccess(response, file, xhr);
563
725
  },
564
- onError(error, response, file) {
726
+ onError: function onError(error, response, file) {
565
727
  setShowLoading(false);
566
728
  showErrTip(!!showUploadError);
567
729
  if (!showUploadError) {
568
730
  file.status = 'error';
569
731
  file.response = (error === null || error === void 0 ? void 0 : error.message) || uploadErrorMsg;
570
- const nextFileList = updateFileList(file);
732
+ var nextFileList = updateFileList(file);
571
733
  onInternalChange(nextFileList);
572
734
  }
573
- onError === null || onError === void 0 ? void 0 : onError(error, response, file);
735
+ _onError === null || _onError === void 0 ? void 0 : _onError(error, response, file);
574
736
  },
575
- onProgress(e, file) {
576
- 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);
577
739
  },
578
- onBatchStart(fileList) {
740
+ onBatchStart: function onBatchStart(fileList) {
579
741
  if (stash) {
580
742
  if (cropFileRef.current) {
581
- const idx = fileList.findIndex(_ => {
743
+ var idx = fileList.findIndex(function (_) {
582
744
  var _a;
583
745
  return _.file.uid === ((_a = cropFileRef.current) === null || _a === void 0 ? void 0 : _a.uid);
584
746
  });
@@ -589,40 +751,62 @@ const ImageUpload = props => {
589
751
  });
590
752
  }
591
753
  }
592
- const arr = fileList.map(_ => _.parsedFile || _.file);
593
- const mList = mergedFileList(arr);
754
+ var arr = fileList.map(function (_) {
755
+ return _.parsedFile || _.file;
756
+ });
757
+ var mList = mergedFileList(arr);
594
758
  onInternalChange(mList);
595
759
  }
596
760
  }
597
761
  });
598
762
  //内部变化
599
- const onInternalChange = changedFileList => __awaiter(void 0, void 0, void 0, function* () {
600
- let cloneList = [...changedFileList];
601
- if (!showUploadList) {
602
- //不显示上传列表
603
- const file = cloneList.slice(-1)[0];
604
- if (file) {
605
- const imageUrl = yield readerFileAsDataUrl(file);
606
- file.dataUrl = imageUrl;
607
- avatar.imageUrl = imageUrl;
608
- avatar.imageName = file.name;
609
- setAvatar(Object.assign({}, avatar));
610
- }
611
- onChange === null || onChange === void 0 ? void 0 : onChange([file]);
612
- return;
613
- }
614
- if (maxCount === 1) {
615
- cloneList = cloneList.slice(-1);
616
- } else if (maxCount) {
617
- cloneList = cloneList.slice(0, maxCount);
618
- }
619
- onChange === null || onChange === void 0 ? void 0 : onChange(cloneList);
620
- setUploadFileList(cloneList);
621
- });
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
+ };
622
806
  //更新文件列表
623
- const updateFileList = file => {
624
- const cloneList = [...uploadFileList];
625
- 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), {
626
810
  lastModified: file.lastModified,
627
811
  lastModifiedDate: file.lastModifiedDate,
628
812
  name: file.name,
@@ -634,9 +818,9 @@ const ImageUpload = props => {
634
818
  return cloneList.concat(fileObj);
635
819
  };
636
820
  //合并文件列表
637
- const mergedFileList = fileList => {
638
- const cloneList = [...uploadFileList];
639
- const newFileList = fileList.map(file => {
821
+ var mergedFileList = function mergedFileList(fileList) {
822
+ var cloneList = _toConsumableArray(uploadFileList);
823
+ var newFileList = fileList.map(function (file) {
640
824
  return Object.assign(Object.assign({}, file), {
641
825
  lastModified: file.lastModified,
642
826
  lastModifiedDate: file.lastModifiedDate,
@@ -650,64 +834,78 @@ const ImageUpload = props => {
650
834
  return cloneList.concat(newFileList);
651
835
  };
652
836
  //删除文件
653
- const handleRemove = file => {
654
- 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) {
655
839
  // Prevent removing file
656
840
  if (ret === false) return;
657
- const idx = uploadFileList.findIndex(_ => _.uid === file.uid);
841
+ var idx = uploadFileList.findIndex(function (_) {
842
+ return _.uid === file.uid;
843
+ });
658
844
  if (idx > -1) uploadFileList.splice(idx, 1);
659
845
  onInternalChange(uploadFileList);
660
846
  });
661
847
  };
662
848
  //读取dataUrl
663
- const readerFileAsDataUrl = file => __awaiter(void 0, void 0, void 0, function* () {
664
- return new Promise(resolve => {
665
- const fileReader = new FileReader();
666
- if (file.originFileObj) {
667
- fileReader.onload = () => {
668
- resolve(fileReader.result);
669
- };
670
- fileReader.readAsDataURL(file.originFileObj);
671
- } else resolve('');
672
- });
673
- });
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
+ };
674
870
  //显示错误提示
675
- const showErrTip = flag => {
871
+ var showErrTip = function showErrTip(flag) {
676
872
  setErrTip(flag);
677
873
  if (leaveDelay < 0) return;
678
- setTimeout(() => {
874
+ setTimeout(function () {
679
875
  setErrTip(false);
680
876
  }, leaveDelay);
681
877
  };
682
- useEffect(() => {
878
+ useEffect(function () {
683
879
  if (fileList) {
684
- setUploadFileList([...fileList]);
880
+ setUploadFileList(_toConsumableArray(fileList));
685
881
  }
686
882
  }, [fileList]);
687
- useEffect(() => {
883
+ useEffect(function () {
688
884
  if (defaultImage) {
689
885
  setAvatar(Object.assign({}, defaultImage));
690
886
  }
691
887
  }, [defaultImage]);
692
888
  //渲染上传列表
693
- const renderUploadList = () => showUploadList && jsx(UploadList, {
694
- listType: 'picture-card',
695
- readonly: readonly,
696
- items: uploadFileList,
697
- showRemoveIcon: showRemoveIcon,
698
- removeIcon: removeIcon,
699
- showPreviewIcon: showPreviewIcon,
700
- previewIcon: previewIcon,
701
- onRemove: handleRemove,
702
- itemRender: itemRender,
703
- onPreview: onPreview,
704
- actionRender: actionRender,
705
- operateBtnProps: operateBtnProps
706
- });
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
+ };
707
905
  //渲染内容 avatar
708
- const renderUploadContent = () => {
906
+ var renderUploadContent = function renderUploadContent() {
709
907
  var _a;
710
- const avatarUploadNode = jsxs("div", Object.assign({
908
+ var avatarUploadNode = jsxs("div", Object.assign({
711
909
  className: 'upload-img-wrapper'
712
910
  }, {
713
911
  children: [jsx("img", {
@@ -723,7 +921,7 @@ const ImageUpload = props => {
723
921
  children: jsx(EditOutline, {})
724
922
  }))]
725
923
  }));
726
- const uploadNode = jsxs(Fragment, {
924
+ var uploadNode = jsxs(Fragment, {
727
925
  children: [showLoading ? jsx(LoadingIcon, {
728
926
  className: 'upload-image-loading'
729
927
  }) : jsx(UploadIcon, {
@@ -755,7 +953,7 @@ const ImageUpload = props => {
755
953
  });
756
954
  };
757
955
  //渲染上传控件
758
- const renderUploadSelector = () => {
956
+ var renderUploadSelector = function renderUploadSelector() {
759
957
  if (readonly) return null;
760
958
  return jsxs("div", Object.assign({
761
959
  className: clsx('upload-image-select', showLoading && 'upload-image-select-loading')
@@ -783,7 +981,7 @@ const ImageUpload = props => {
783
981
  };
784
982
 
785
983
  //Dragger upload
786
- const Dragger = props => {
984
+ var Dragger = function Dragger(props) {
787
985
  return jsx(Upload, Object.assign({}, props, {
788
986
  type: 'drag'
789
987
  }));
@@ -982,274 +1180,352 @@ var css_248z$1 = "@charset \"UTF-8\";\n/**\n* @author Hanz\n* @date 2022/4/20
982
1180
  styleInject(css_248z$1);
983
1181
 
984
1182
  //图片裁剪组件
985
- const ImgCrop = /*#__PURE__*/forwardRef((props, ref) => {
986
- const {
987
- aspect = 1,
988
- shape = 'rect',
989
- grid = false,
990
- quality = 0.4,
991
- fillColor = 'transparent',
992
- zoom = true,
993
- rotate = false,
994
- minZoom = 1,
995
- maxZoom = 3,
996
- modalTitle,
997
- modalWidth,
998
- modalOk,
999
- modalCancel,
1000
- onModalOk,
1001
- onModalCancel,
1002
- beforeCrop,
1003
- onUploadFail,
1004
- cropperProps,
1005
- children,
1006
- 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 ? {
1007
1214
  width: 120,
1008
1215
  height: 120
1009
- },
1010
- zoomTipFormatter = val => "".concat(Number(val) * 10 * 10),
1011
- zoomMarks = true,
1012
- rotateMarks = true,
1013
- rotateTipFormatter = val => "".concat(val)
1014
- } = props;
1015
- const intl = useFormatMessage('Upload', localeJson);
1016
- const [image, setImage] = useState('');
1017
- const fileRef = useRef();
1018
- const beforeUploadRef = useRef();
1019
- const resolveRef = useRef();
1020
- 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();
1021
1238
  //存储回调
1022
- const cbRef = useRef({});
1239
+ var cbRef = useRef({});
1023
1240
  cbRef.current.onModalOk = onModalOk;
1024
1241
  cbRef.current.onModalCancel = onModalCancel;
1025
1242
  cbRef.current.beforeCrop = beforeCrop;
1026
1243
  cbRef.current.onUploadFail = onUploadFail;
1027
- const easyCropRef = useRef({});
1244
+ var easyCropRef = useRef({});
1028
1245
  //上传组件
1029
- const uploadComponent = useMemo(() => {
1030
- const upload = Array.isArray(children) ? children[0] : children;
1031
- const _a = upload.props,
1032
- {
1033
- beforeUpload,
1034
- accept
1035
- } = _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,
1036
1251
  restUploadProps = __rest(_a, ["beforeUpload", "accept"]);
1037
1252
  beforeUploadRef.current = beforeUpload;
1038
1253
  return Object.assign(Object.assign({}, upload), {
1039
1254
  props: Object.assign(Object.assign({}, restUploadProps), {
1040
1255
  accept: accept || 'image/*',
1041
- beforeUpload: (file, fileList) => {
1042
- return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
1043
- if (cbRef.current.beforeCrop && !(yield cbRef.current.beforeCrop(file, fileList))) {
1044
- reject();
1045
- return;
1046
- }
1047
- fileRef.current = file;
1048
- resolveRef.current = function (newFile) {
1049
- let flag = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
1050
- var _a, _b;
1051
- (_b = (_a = cbRef.current).onModalOk) === null || _b === void 0 ? void 0 : _b.call(_a, newFile);
1052
- if (!flag) return resolve({
1053
- cropFile: newFile,
1054
- isUpload: flag
1055
- });
1056
- resolve(newFile);
1057
- };
1058
- rejectRef.current = uploadErr => {
1059
- var _a, _b;
1060
- (_b = (_a = cbRef.current).onUploadFail) === null || _b === void 0 ? void 0 : _b.call(_a, uploadErr);
1061
- reject(uploadErr);
1062
- };
1063
- const reader = new FileReader();
1064
- reader.addEventListener('load', () => typeof reader.result === 'string' && setImage(reader.result));
1065
- reader.readAsDataURL(file);
1066
- }));
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
+ });
1067
1308
  }
1068
1309
  })
1069
1310
  });
1070
1311
  }, [children]);
1071
1312
  //modal 关闭后操作
1072
- const onClose = () => {
1313
+ var onClose = function onClose() {
1073
1314
  setImage('');
1074
1315
  easyCropRef.current.setZoomVal(INIT_ZOOM);
1075
1316
  easyCropRef.current.setRotateVal(INIT_ROTATE);
1076
1317
  };
1077
1318
  //modal cancel
1078
- const onCancel = useCallback(() => {
1319
+ var onCancel = useCallback(function () {
1079
1320
  var _a, _b;
1080
1321
  (_b = (_a = cbRef.current).onModalCancel) === null || _b === void 0 ? void 0 : _b.call(_a);
1081
1322
  onClose();
1082
1323
  }, []);
1083
1324
  //modal ok
1084
- const onOk = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
1085
- onClose();
1086
- const canvas = document.createElement('canvas');
1087
- const ctx = canvas.getContext('2d');
1088
- const imgSource = document.querySelector(".".concat(PREFIX, "-media"));
1089
- const {
1090
- width: cropWidth,
1091
- height: cropHeight,
1092
- x: cropX,
1093
- y: cropY
1094
- } = easyCropRef.current.cropPixelsRef.current;
1095
- if (rotate && easyCropRef.current.rotateVal !== INIT_ROTATE) {
1096
- const {
1097
- naturalWidth: imgWidth,
1098
- naturalHeight: imgHeight
1099
- } = imgSource;
1100
- const angle = easyCropRef.current.rotateVal * (Math.PI / 180);
1101
- // get container for rotated image
1102
- const sine = Math.abs(Math.sin(angle));
1103
- const cosine = Math.abs(Math.cos(angle));
1104
- const squareWidth = imgWidth * cosine + imgHeight * sine;
1105
- const squareHeight = imgHeight * cosine + imgWidth * sine;
1106
- canvas.width = squareWidth;
1107
- canvas.height = squareHeight;
1108
- ctx.fillStyle = fillColor;
1109
- ctx.fillRect(0, 0, squareWidth, squareHeight);
1110
- // rotate container
1111
- const squareHalfWidth = squareWidth / 2;
1112
- const squareHalfHeight = squareHeight / 2;
1113
- ctx.translate(squareHalfWidth, squareHalfHeight);
1114
- ctx.rotate(angle);
1115
- ctx.translate(-squareHalfWidth, -squareHalfHeight);
1116
- // draw rotated image
1117
- const imgX = (squareWidth - imgWidth) / 2;
1118
- const imgY = (squareHeight - imgHeight) / 2;
1119
- ctx.drawImage(imgSource, 0, 0, imgWidth, imgHeight, imgX, imgY, imgWidth, imgHeight);
1120
- // crop rotated image
1121
- const imgData = ctx.getImageData(0, 0, squareWidth, squareHeight);
1122
- canvas.width = cropWidth;
1123
- canvas.height = cropHeight;
1124
- ctx.putImageData(imgData, -cropX, -cropY);
1125
- } else {
1126
- canvas.width = cropWidth;
1127
- canvas.height = cropHeight;
1128
- ctx.fillStyle = fillColor;
1129
- ctx.fillRect(0, 0, cropWidth, cropHeight);
1130
- ctx.drawImage(imgSource, cropX, cropY, cropWidth, cropHeight, 0, 0, cropWidth, cropHeight);
1131
- }
1132
- //裁剪之后改变图片大小
1133
- const changeImageSizeAfterCrop = newFile => {
1134
- return new Promise(resolve => {
1135
- const {
1136
- name,
1137
- type,
1138
- uid
1139
- } = newFile;
1140
- const {
1141
- width,
1142
- height
1143
- } = fixedCropSize; //固定裁剪大小
1144
- const changeCanvas = document.createElement('canvas');
1145
- const changeCtx = changeCanvas.getContext('2d');
1146
- const img = new Image();
1147
- img.onload = () => {
1148
- changeCanvas.width = width;
1149
- changeCanvas.height = height;
1150
- changeCtx.drawImage(img, 0, 0, width, height);
1151
- changeCanvas.toBlob(cBlob => {
1152
- const changeFile = Object.assign(new File([cBlob], name, {
1153
- type
1154
- }), {
1155
- uid
1156
- });
1157
- resolve(changeFile);
1158
- }, type, quality);
1159
- };
1160
- img.onerror = () => {
1161
- resolve(newFile);
1162
- };
1163
- const fileReader = new FileReader();
1164
- fileReader.onload = () => {
1165
- img.src = fileReader.result;
1166
- };
1167
- fileReader.onerror = () => {
1168
- resolve(newFile);
1169
- };
1170
- fileReader.readAsDataURL(newFile);
1171
- });
1172
- };
1173
- // get the new image
1174
- let {
1175
- type,
1176
- name,
1177
- uid
1178
- } = fileRef.current;
1179
- if (/svg/gi.test(type)) {
1180
- //svg 转为 png
1181
- type = 'image/png';
1182
- const idx = name.lastIndexOf('.');
1183
- if (idx > -1) name = "".concat(name.substring(0, idx), ".png");
1184
- }
1185
- //转为blob
1186
- const onBlob = blob => __awaiter(void 0, void 0, void 0, function* () {
1187
- var _a, _b, _c, _d, _e, _f;
1188
- const newFile = Object.assign(new File([blob], name, {
1189
- type
1190
- }), {
1191
- uid
1192
- });
1193
- const changeFile = yield changeImageSizeAfterCrop(newFile);
1194
- if (typeof beforeUploadRef.current !== 'function') {
1195
- return (_a = resolveRef.current) === null || _a === void 0 ? void 0 : _a.call(resolveRef, changeFile);
1196
- }
1197
- const res = beforeUploadRef.current(changeFile, [changeFile]);
1198
- if (typeof res !== 'boolean' && !res) {
1199
- console.error('beforeUpload must return a boolean or Promise');
1200
- return;
1201
- }
1202
- if (res === true) return (_b = resolveRef.current) === null || _b === void 0 ? void 0 : _b.call(resolveRef, changeFile);
1203
- if (res === false) return (_c = resolveRef.current) === null || _c === void 0 ? void 0 : _c.call(resolveRef, changeFile, false);
1204
- if (res && res instanceof Promise) {
1205
- try {
1206
- const passedFile = yield res;
1207
- if (passedFile instanceof File || passedFile instanceof Blob) {
1208
- return (_d = resolveRef.current) === null || _d === void 0 ? void 0 : _d.call(resolveRef, passedFile);
1209
- }
1210
- (_e = resolveRef.current) === null || _e === void 0 ? void 0 : _e.call(resolveRef, changeFile, passedFile);
1211
- } catch (err) {
1212
- (_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();
1213
1488
  }
1214
- }
1215
- });
1216
- canvas.toBlob(onBlob, type, quality);
1217
- }), [fillColor, quality, rotate]);
1489
+ }, _callee3);
1490
+ }));
1491
+ }, [fillColor, quality, rotate]);
1218
1492
  //img crop 组件
1219
- const getComponent = titleOfModal => jsxs(Fragment, {
1220
- children: [uploadComponent, image && jsx(Modal, Object.assign({
1221
- open: true,
1222
- className: "".concat(PREFIX, "-modal"),
1223
- size: 'md',
1224
- title: titleOfModal !== null && titleOfModal !== void 0 ? titleOfModal : intl({
1225
- id: 'editImage'
1226
- }),
1227
- onOk: onOk,
1228
- onCancel: onCancel,
1229
- okText: modalOk,
1230
- cancelText: modalCancel,
1231
- contentWidth: modalWidth
1232
- }, {
1233
- children: jsx(EasyCrop$1, {
1234
- ref: easyCropRef,
1235
- cropperRef: ref,
1236
- image: image,
1237
- aspect: aspect,
1238
- shape: shape,
1239
- grid: grid,
1240
- zoom: zoom,
1241
- rotate: rotate,
1242
- minZoom: minZoom,
1243
- maxZoom: maxZoom,
1244
- fixedCropSize: fixedCropSize,
1245
- cropperProps: cropperProps,
1246
- zoomTipFormatter: zoomTipFormatter,
1247
- zoomMarks: zoomMarks,
1248
- rotateMarks: rotateMarks,
1249
- rotateTipFormatter: rotateTipFormatter
1250
- })
1251
- }))]
1252
- });
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
+ };
1253
1529
  return jsx(Fragment, {
1254
1530
  children: getComponent(modalTitle)
1255
1531
  });