|
|
@ -27,15 +27,15 @@ function getBase64(img, callback) { |
|
|
|
} |
|
|
|
|
|
|
|
function beforeUpload(file) { |
|
|
|
const isJPG = file.type === 'image/jpeg'; |
|
|
|
if (!isJPG) { |
|
|
|
message.error('You can only upload JPG file!'); |
|
|
|
const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png'; |
|
|
|
if (!isJpgOrPng) { |
|
|
|
message.error('You can only upload JPG/PNG file!'); |
|
|
|
} |
|
|
|
const isLt2M = file.size / 1024 / 1024 < 2; |
|
|
|
if (!isLt2M) { |
|
|
|
message.error('Image must smaller than 2MB!'); |
|
|
|
} |
|
|
|
return isJPG && isLt2M; |
|
|
|
return isJpgOrPng && isLt2M; |
|
|
|
} |
|
|
|
|
|
|
|
class Avatar extends React.Component { |
|
|
@ -68,19 +68,17 @@ class Avatar extends React.Component { |
|
|
|
); |
|
|
|
const { imageUrl } = this.state; |
|
|
|
return ( |
|
|
|
<div className="clearfix"> |
|
|
|
<Upload |
|
|
|
name="avatar" |
|
|
|
listType="picture-card" |
|
|
|
className="avatar-uploader" |
|
|
|
showUploadList={false} |
|
|
|
action="https://www.mocky.io/v2/5cc8019d300000980a055e76" |
|
|
|
beforeUpload={beforeUpload} |
|
|
|
onChange={this.handleChange} |
|
|
|
> |
|
|
|
{imageUrl ? <img src={imageUrl} alt="avatar" /> : uploadButton} |
|
|
|
</Upload> |
|
|
|
</div> |
|
|
|
<Upload |
|
|
|
name="avatar" |
|
|
|
listType="picture-card" |
|
|
|
className="avatar-uploader" |
|
|
|
showUploadList={false} |
|
|
|
action="https://www.mocky.io/v2/5cc8019d300000980a055e76" |
|
|
|
beforeUpload={beforeUpload} |
|
|
|
onChange={this.handleChange} |
|
|
|
> |
|
|
|
{imageUrl ? <img src={imageUrl} alt="avatar" style={{ width: '100%' }} /> : uploadButton} |
|
|
|
</Upload> |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|