|
|
|
import * as React from 'react';
|
|
|
|
import Animate from 'rc-animate';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import {
|
|
|
|
LoadingOutlined,
|
|
|
|
PaperClipOutlined,
|
|
|
|
PictureTwoTone,
|
|
|
|
FileTwoTone,
|
|
|
|
EyeOutlined,
|
|
|
|
DeleteOutlined,
|
|
|
|
DownloadOutlined,
|
|
|
|
} from '@ant-design/icons';
|
|
|
|
|
|
|
|
import { UploadListProps, UploadFile, UploadListType } from './interface';
|
|
|
|
import { previewImage, isImageUrl } from './utils';
|
|
|
|
import Tooltip from '../tooltip';
|
|
|
|
import Progress from '../progress';
|
|
|
|
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
|
|
|
|
|
|
|
|
export default class UploadList extends React.Component<UploadListProps, any> {
|
|
|
|
static defaultProps = {
|
|
|
|
listType: 'text' as UploadListType, // or picture
|
|
|
|
progressAttr: {
|
|
|
|
strokeWidth: 2,
|
|
|
|
showInfo: false,
|
|
|
|
},
|
|
|
|
showRemoveIcon: true,
|
|
|
|
showDownloadIcon: true,
|
|
|
|
showPreviewIcon: true,
|
|
|
|
previewFile: previewImage,
|
|
|
|
};
|
|
|
|
|
|
|
|
componentDidUpdate() {
|
|
|
|
const { listType, items, previewFile } = this.props;
|
|
|
|
if (listType !== 'picture' && listType !== 'picture-card') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
(items || []).forEach(file => {
|
|
|
|
if (
|
|
|
|
typeof document === 'undefined' ||
|
|
|
|
typeof window === 'undefined' ||
|
|
|
|
!(window as any).FileReader ||
|
|
|
|
!(window as any).File ||
|
|
|
|
!(file.originFileObj instanceof File || file.originFileObj instanceof Blob) ||
|
|
|
|
file.thumbUrl !== undefined
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
file.thumbUrl = '';
|
|
|
|
if (previewFile) {
|
|
|
|
previewFile(file.originFileObj as File).then((previewDataUrl: string) => {
|
|
|
|
// Need append '' to avoid dead loop
|
|
|
|
file.thumbUrl = previewDataUrl || '';
|
|
|
|
this.forceUpdate();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
handlePreview = (file: UploadFile, e: React.SyntheticEvent<HTMLElement>) => {
|
|
|
|
const { onPreview } = this.props;
|
|
|
|
if (!onPreview) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|