@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.
- package/AutoTips/index.js +14 -14
- package/Cascader/index.js +2 -2
- package/ComboSelect/index.js +1 -1
- package/CycleSelector/index.d.ts +14 -2
- package/CycleSelector/index.js +42 -3
- package/DynamicMultiBox/index.js +1 -1
- package/Form/index.js +2 -2
- package/FormItem/index.js +2 -2
- package/FunctionModal/index.js +2 -2
- package/README.md +7 -0
- package/Selector/index.js +325 -2
- package/SelectorPicker/index.js +0 -1
- package/Transfer/index.js +49 -43
- package/Tree/index.js +2 -2
- package/Upload/index.js +479 -756
- package/index.js +4 -5
- package/package.json +1 -1
- package/umd/AutoTips.js +1 -1
- package/umd/Breadcrumbs.js +1 -1
- package/umd/Button.js +1 -1
- package/umd/ButtonGroup.js +1 -1
- package/umd/Cascader.js +1 -1
- package/umd/ComboSelect.js +1 -1
- package/umd/CopyText.js +1 -1
- package/umd/CycleSelector.js +2 -2
- package/umd/DatePicker.js +1 -1
- package/umd/Descriptions.js +1 -1
- package/umd/Desktop.js +1 -1
- package/umd/Drawer.js +1 -1
- package/umd/DynamicMultiBox.js +1 -1
- package/umd/Form.js +1 -1
- package/umd/FormItem.js +1 -1
- package/umd/FunctionModal.js +1 -1
- package/umd/InputLang.js +1 -1
- package/umd/Menu.js +1 -1
- package/umd/Modal.js +1 -1
- package/umd/MultiBox.js +1 -1
- package/umd/OperateBtn.js +1 -1
- package/umd/PageHeader.js +1 -1
- package/umd/Pagination.js +1 -1
- package/umd/PopConfirm.js +1 -1
- package/umd/PopMenu.js +1 -1
- package/umd/QuickReply.js +1 -1
- package/umd/Search.js +1 -1
- package/umd/Select.js +1 -1
- package/umd/SelectInput.js +1 -1
- package/umd/Selector.js +1 -1
- package/umd/SelectorPicker.js +1 -1
- package/umd/SingleBox.js +1 -1
- package/umd/Stepper.js +1 -1
- package/umd/Table.js +1 -1
- package/umd/Tabs.js +1 -1
- package/umd/Tag.js +1 -1
- package/umd/TextField.js +1 -1
- package/umd/TimePicker.js +1 -1
- package/umd/Title.js +1 -1
- package/umd/ToggleButton.js +1 -1
- package/umd/Transfer.js +1 -1
- package/umd/Tree.js +1 -1
- package/umd/Upload.js +1 -1
- package/_verture/index-8ac46bd9.js +0 -327
- /package/_verture/{index-8cfd01fd.js → index-0eca82dc.js} +0 -0
- /package/_verture/{index-2a6adf4d.js → index-5f205d87.js} +0 -0
- /package/_verture/{index-bbe5660a.js → index-93662604.js} +0 -0
- /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
|
-
|
|
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
|
-
|
|
187
|
-
|
|
188
|
-
listType =
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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
|
-
|
|
200
|
+
const handleRemove = (file, evt) => {
|
|
218
201
|
evt.stopPropagation();
|
|
219
|
-
|
|
202
|
+
onRemove === null || onRemove === void 0 ? void 0 : onRemove(file);
|
|
220
203
|
};
|
|
221
|
-
|
|
222
|
-
|
|
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(
|
|
208
|
+
setUploadList([...uploadList]);
|
|
228
209
|
};
|
|
229
|
-
|
|
210
|
+
const previewItems = useMemo(() => {
|
|
230
211
|
var _a;
|
|
231
|
-
|
|
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(
|
|
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
|
-
|
|
244
|
-
return previewItems.originItems.findIndex(
|
|
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
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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
|
-
|
|
283
|
-
|
|
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
|
-
|
|
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
|
-
|
|
306
|
-
|
|
307
|
-
onRemove:
|
|
308
|
-
|
|
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:
|
|
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
|
-
|
|
334
|
-
|
|
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
|
-
|
|
339
|
-
|
|
340
|
-
|
|
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:
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
320
|
+
const renderFileListText = () => {
|
|
382
321
|
if (!(uploadList === null || uploadList === void 0 ? void 0 : uploadList.length)) return null;
|
|
383
|
-
return uploadList.map(
|
|
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
|
-
|
|
344
|
+
const renderFileListPicture = () => {
|
|
406
345
|
if (!(uploadList === null || uploadList === void 0 ? void 0 : uploadList.length)) return null;
|
|
407
|
-
return uploadList.map(
|
|
346
|
+
return uploadList.map((file, idx) => {
|
|
408
347
|
/*自定义渲染*/
|
|
409
348
|
if (itemRender) return itemRender(file, uploadList);
|
|
410
|
-
|
|
411
|
-
|
|
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:
|
|
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
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
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
|
|
541
|
-
onVisibleChange:
|
|
424
|
+
visible,
|
|
425
|
+
onVisibleChange: value => {
|
|
542
426
|
setVisible(value);
|
|
543
427
|
},
|
|
544
|
-
onChange:
|
|
428
|
+
onChange: value => {
|
|
545
429
|
setCurrent(value);
|
|
546
430
|
},
|
|
547
|
-
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
|
-
|
|
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
|
|
592
|
-
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
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
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
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
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
|
-
})
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
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
|
-
|
|
539
|
+
const overrideProps = Object.assign(Object.assign({
|
|
676
540
|
accept: 'image/*'
|
|
677
541
|
}, restProps), {
|
|
678
|
-
beforeUpload:
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
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
|
|
557
|
+
onSuccess(response, file, xhr) {
|
|
721
558
|
setShowLoading(false);
|
|
722
559
|
errTip && showErrTip(false);
|
|
723
|
-
|
|
560
|
+
const nextFileList = updateFileList(file);
|
|
724
561
|
onInternalChange(nextFileList);
|
|
725
|
-
|
|
562
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response, file, xhr);
|
|
726
563
|
},
|
|
727
|
-
onError
|
|
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
|
-
|
|
570
|
+
const nextFileList = updateFileList(file);
|
|
734
571
|
onInternalChange(nextFileList);
|
|
735
572
|
}
|
|
736
|
-
|
|
573
|
+
onError === null || onError === void 0 ? void 0 : onError(error, response, file);
|
|
737
574
|
},
|
|
738
|
-
onProgress
|
|
739
|
-
|
|
575
|
+
onProgress(e, file) {
|
|
576
|
+
onProgress === null || onProgress === void 0 ? void 0 : onProgress(e, file);
|
|
740
577
|
},
|
|
741
|
-
onBatchStart
|
|
578
|
+
onBatchStart(fileList) {
|
|
742
579
|
if (stash) {
|
|
743
580
|
if (cropFileRef.current) {
|
|
744
|
-
|
|
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
|
-
|
|
756
|
-
|
|
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
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
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
|
-
|
|
809
|
-
|
|
810
|
-
|
|
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
|
-
|
|
823
|
-
|
|
824
|
-
|
|
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
|
-
|
|
839
|
-
Promise.resolve(typeof onRemove === 'function' ? onRemove(file) : onRemove).then(
|
|
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
|
-
|
|
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
|
-
|
|
851
|
-
return
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
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
|
-
|
|
675
|
+
const showErrTip = flag => {
|
|
873
676
|
setErrTip(flag);
|
|
874
677
|
if (leaveDelay < 0) return;
|
|
875
|
-
setTimeout(
|
|
678
|
+
setTimeout(() => {
|
|
876
679
|
setErrTip(false);
|
|
877
680
|
}, leaveDelay);
|
|
878
681
|
};
|
|
879
|
-
useEffect(
|
|
682
|
+
useEffect(() => {
|
|
880
683
|
if (fileList) {
|
|
881
|
-
setUploadFileList(
|
|
684
|
+
setUploadFileList([...fileList]);
|
|
882
685
|
}
|
|
883
686
|
}, [fileList]);
|
|
884
|
-
useEffect(
|
|
687
|
+
useEffect(() => {
|
|
885
688
|
if (defaultImage) {
|
|
886
689
|
setAvatar(Object.assign({}, defaultImage));
|
|
887
690
|
}
|
|
888
691
|
}, [defaultImage]);
|
|
889
692
|
//渲染上传列表
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
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
|
-
|
|
708
|
+
const renderUploadContent = () => {
|
|
908
709
|
var _a;
|
|
909
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1185
|
-
|
|
1186
|
-
aspect =
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
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
|
-
}
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1027
|
+
const easyCropRef = useRef({});
|
|
1246
1028
|
//上传组件
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
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:
|
|
1258
|
-
return new Promise(
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
return
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
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
|
-
}
|
|
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
|
});
|