import React from "react"; import { Upload, Icon, Modal, message, Spin } from "antd"; import intl from "react-intl-universal"; import { DRIVER_LICENSE_PATH, ERROR_DEFAULT } from "../../constant"; import Comment from "../../Comment"; import "./Upload.css"; class App extends React.Component { constructor(props) { super(props); this.state = { previewVisible: false, previewImage: "", loading: false }; this.handleCancel = this.handleCancel.bind(this); this.handlePreview = this.handlePreview.bind(this); this.handleChange = this.handleChange.bind(this); this.customRequest = this.customRequest.bind(this); this.handleCloseClick = this.handleCloseClick.bind(this); this.onImgLoad = this.onImgLoad.bind(this); } componentDidMount() { this.props.app.sOssSts(); if (this.props.onRef) { this.props.onRef(this); } } onImgLoad() { this.setState({ loading: false }); } handleCancel() { this.setState({ previewVisible: false }); } handlePreview(file) { this.setState({ previewImage: file.url || file.thumbUrl, previewVisible: true }); } handleChange({ fileList }) { this.props.onChangeFileList(fileList); } customRequest(info) { const { file } = info; info.onProgress({ percent: 10 }); let reader = new FileReader(); reader.readAsDataURL(info.file); reader.onloadend = () => { info.onProgress({ percent: 20 }); // DRIVER_LICENSE_PATH oss 的存储路径位置 this.props.app .UploadToOss(this.props.app.oss, DRIVER_LICENSE_PATH, file) .then(data => { info.onProgress({ percent: 100 }); info.onSuccess(data); this.props.onUpload({ path: data.name, uid: file.uid }); }) .catch(e => { const msg = e.message || ERROR_DEFAULT; if (this.props.showError) { message.error(msg); } if (this.props.onError) { this.props.onError(msg, { response: e.response }); } info.onError(e); }); }; } handleCloseClick(index) { let newFileList = this.props.fileList; newFileList.splice(index, 1); this.props.onChangeFileList(newFileList); } render() { const { previewVisible, previewImage } = this.state; const { fileList, maxUpload, multiple } = this.props; const uploadButton = (
{intl.get("editor.uploadBtn")}
); return (
{fileList.length >= maxUpload ? null : uploadButton} {fileList.map((file, index) => { return (
); })} upload
); } } export default Comment(App);