import { Component } from 'react'; import { Upload, message, Icon, Modal,Spin } from 'antd'; class VideoComponent extends Component { constructor(props) { super(props); this.state = { previewVisible: false, previewImage: '', loading:false, fileList: [], fileListUrl:'' }; } handleCancel() { this.setState({ previewVisible: false }); } handlePreview(file) { this.setState({ previewImage: file.url , previewVisible: true }); } handleChange(info) { this.props.loadState(true); this.setState({loading:true}) let fileList = info.fileList; this.setState({ fileList }); if (info.file.status !== 'uploading') { } if (info.file.status === 'done') { message.success(`上传成功`); this.props.fileList(fileList); this.props.loadState(false); this.setState({ loading:false, fileListUrl:fileList[0].response.data, }) } else if (info.file.status === 'error') { message.error(`上传失败`); this.props.loadState(false); } } beforeUpload(info){ if(this.props.dataUrl.type.indexOf('video')>-1){ if(info.type.indexOf('video')<0){ message.warning('请上传MP4格式视频文件.'); return false; }; let sizeMb = info.size/(1024*1024),size=100; if(sizeMb>size){ //100Mb之内 message.warning(`视频大小不超过${size}`); return false; }; }; if(this.props.dataUrl.type.indexOf('image')>-1){ if(info.type.indexOf('image')<0){ message.warning('请上传图片.'); return false; }; let sizeMb = info.size/(1024*1024),size=1; if(sizeMb>size){ //1Mb之内 message.warning(`图片大小不超过${size}MB.`); return false; }; } } componentWillReceiveProps(nextProps) { this.state.fileList = nextProps.videoUrl; } render() { const { previewVisible, previewImage, fileList } = this.state; const uploadButton = (