@para-ui/core 4.0.24 → 4.0.25

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