Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Commit

Permalink
fix: failed to update user avatar
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Wang <[email protected]>
  • Loading branch information
ruibaby committed Oct 12, 2022
1 parent a7399e8 commit 9639bef
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions src/views/user/Profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,16 @@
</a-form>

<template #footer>
<a-button type="primary" @click="handleUpdateAvatar">确定</a-button>
<ReactiveButton
:errored="updateAvatarForm.errored"
:loading="updateAvatarForm.saving"
erroredText="保存失败"
loadedText="保存成功"
text="保存"
type="primary"
@callback="handleUpdateAvatarCallback"
@click="handleUpdateAvatar"
></ReactiveButton>
<a-button @click="updateAvatarForm.visible = false">关闭</a-button>
</template>
</a-modal>
Expand Down Expand Up @@ -521,20 +530,27 @@ export default {
})
},
async handleUpdateAvatar() {
const { updateAvatarData } = await apiClient.user.getProfile()
updateAvatarData.avatar = this.updateAvatarForm.avatar
const { data: userToUpdate } = await apiClient.user.getProfile()
userToUpdate.avatar = this.updateAvatarForm.avatar
this.updateAvatarForm.saving = true
apiClient.user
.updateProfile(updateAvatarData)
.then(response => {
this.$message.success('更新头像成功!')
this.updateAvatarForm.visible = false
this.userForm.model.avatar = response.data.avatar
this.setUser(Object.assign({}, this.userForm.model))
})
.updateProfile(userToUpdate)
.catch(() => {
this.$message.error('更新头像失败!')
this.updateAvatarForm.visible = true
this.updateAvatarForm.saveErrored = true
})
.finally(() => {
setTimeout(() => {
this.updateAvatarForm.saving = false
}, 400)
this.handleLoadStatistics()
})
},
handleUpdateAvatarCallback() {
if (this.updateAvatarForm.saveErrored) {
this.updateAvatarForm.saveErrored = false
return
}
this.updateAvatarForm.visible = false
}
}
}
Expand Down

0 comments on commit 9639bef

Please sign in to comment.