|
|
|
@ -28,6 +28,10 @@ class ChangeHeaderPicModal extends Component{
|
|
|
|
|
file = files[0];
|
|
|
|
|
|
|
|
|
|
if (/^image\/\w+/.test(file.type)) {
|
|
|
|
|
if (file.size > 2 * 1024 * 1024) {
|
|
|
|
|
this.props.showNotification && this.props.showNotification("仅支持文件大小小于2M的文件")
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
uploadedImageType = file.type;
|
|
|
|
|
uploadedImageName = file.name;
|
|
|
|
|
|
|
|
|
@ -41,7 +45,6 @@ class ChangeHeaderPicModal extends Component{
|
|
|
|
|
// cropper = new Cropper(image, options);
|
|
|
|
|
inputImage.value = null;
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
this.props.showNotification && this.props.showNotification("请选择一个图片格式的文件")
|
|
|
|
|
// window.alert('Please choose an image file.');
|
|
|
|
|
}
|
|
|
|
@ -72,14 +75,16 @@ class ChangeHeaderPicModal extends Component{
|
|
|
|
|
var dataUrl = canvas.toDataURL("image/jpeg");
|
|
|
|
|
console.log(dataUrl)
|
|
|
|
|
|
|
|
|
|
const url = `/users/accounts/${this.props.userLogin || 'kosasa'}/avatar.json`
|
|
|
|
|
const url = `/users/accounts/${this.props.userLogin}/avatar.json`
|
|
|
|
|
axios.put(url, {
|
|
|
|
|
image: dataUrl
|
|
|
|
|
})
|
|
|
|
|
.then((response) => {
|
|
|
|
|
// {"status":0,"message":"success","avatar_url":"avatars/User/15739"}
|
|
|
|
|
if (response.data.status == 0) {
|
|
|
|
|
|
|
|
|
|
// this.props.getBasicInfo()
|
|
|
|
|
this.props.fetchUser()
|
|
|
|
|
// 头像更新后会触发AccountPage的DidUpdate,然后会调用getBasicInfo
|
|
|
|
|
this.props.showNotification && this.props.showNotification("修改头像成功")
|
|
|
|
|
this.setVisible(false)
|
|
|
|
|
}
|
|
|
|
@ -111,6 +116,7 @@ class ChangeHeaderPicModal extends Component{
|
|
|
|
|
text-align: center;
|
|
|
|
|
width: 120px;
|
|
|
|
|
height: 120px;
|
|
|
|
|
border: 1px solid #eee;
|
|
|
|
|
}
|
|
|
|
|
.previewWrap {
|
|
|
|
|
flex-direction: column;
|
|
|
|
@ -121,10 +127,14 @@ class ChangeHeaderPicModal extends Component{
|
|
|
|
|
}
|
|
|
|
|
.changeHeaderModal .tip {
|
|
|
|
|
color: #9B9B9B;
|
|
|
|
|
margin-top: 4px;
|
|
|
|
|
}
|
|
|
|
|
.changeHeaderModal .cropperWrap .tip {
|
|
|
|
|
display: inline-block;
|
|
|
|
|
}
|
|
|
|
|
.previewWrap .tip {
|
|
|
|
|
text-align: center;
|
|
|
|
|
margin-top: 2px;
|
|
|
|
|
margin-top: 4px;
|
|
|
|
|
}
|
|
|
|
|
#uploadBtn {
|
|
|
|
|
color: #4CACFF;
|
|
|
|
@ -134,8 +144,9 @@ class ChangeHeaderPicModal extends Component{
|
|
|
|
|
}
|
|
|
|
|
`}</style>
|
|
|
|
|
<div className="df">
|
|
|
|
|
<div>
|
|
|
|
|
<div className="cropperWrap">
|
|
|
|
|
<Cropper
|
|
|
|
|
imageSrc={''}
|
|
|
|
|
ref="cropper"
|
|
|
|
|
imageId={imageId}
|
|
|
|
|
previewId="changeHeader_imagePreview"
|
|
|
|
|