import React, { useState } from 'react'; import { LoadingOutlined, PlusOutlined } from '@ant-design/icons'; import Upload from './Upload'; function beforeUpload(file) { const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png'||file.type==='image/gif'; if (!isJpgOrPng) { message.error('请上传 JPG , PNG或GIF 图片!'); } const isLt10M = file.size / 1024 / 1024 < 10; if (!isLt10M) { message.error('图片大小必须小于 10MB!'); } return isJpgOrPng && isLt10M; } const UploadButton = (props) => (
{props.loading ? : }
上传
); export default (props) => { const { value, onChange } = props; const [loading, setLoading] = useState(false); const handleChange = info => { if (info.file.status === 'uploading') { setLoading(true); return; } if (info.file.status === 'error') { setLoading(false); return; } if (info.file.status === 'done') { setLoading(false); onChange(info.file.response); } }; return ( {value ? avatar : } ); }