import React from "react"; import { Icon, message, Modal, Upload } from "antd"; import "./index.less"; function getBase64(img, callback) { const reader = new FileReader(); reader.addEventListener("load", () => callback(reader.result)); reader.readAsDataURL(img); } function beforeUpload(file) { const isJPG = file.type === "image/jpeg" || file.type === "image/png"; if (!isJPG) { message.error("只允许上传jpg、png类型的图片!"); } const isLt2M = file.size / 1024 / 1024 < 2; if (!isLt2M) { message.error("图片大小限制2MB!"); } return isJPG && isLt2M; } export default class BackgroundUpload extends React.Component { constructor(props) { super(props); this.state = { showOperate: false, visible: false }; } // 上传完成监听 handleChange = (info) => { if (info.file.status === "done") { this.props.onChange && this.props.onChange(info.file.response.data.acclink); getBase64(info.file.originFileObj, imageUrl => this.setState({ imageUrl })); } }; // 删除 handleDelete = () => { this.props.onChange && this.props.onChange(null); }; // 预览 handlePreview = () => { this.setState({ visible: true }); }; render() { const props = { action: "/api/doc/upload/uploadFile", multiple: false, listType: "picture-card", showUploadList: false, onChange: this.handleChange.bind(this) }; const { imageUrl } = this.props; return (