mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 15:21:53 +08:00
修复头像的 bug
This commit is contained in:
parent
79f9f7b93d
commit
e8e6024a2b
@ -89,14 +89,14 @@ public class SysUserProfileController {
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PutMapping("/upload-avatar")
|
||||
@PutMapping("/update-avatar")
|
||||
@ApiOperation("上传用户个人头像")
|
||||
public CommonResult<Boolean> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws IOException {
|
||||
public CommonResult<String> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws IOException {
|
||||
if (file.isEmpty()) {
|
||||
throw ServiceExceptionUtil.exception(FILE_IS_EMPTY);
|
||||
}
|
||||
userService.updateUserAvatar(getLoginUserId(), file.getInputStream());
|
||||
return success(true);
|
||||
String avatar = userService.updateUserAvatar(getLoginUserId(), file.getInputStream());
|
||||
return success(avatar);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ public interface SysUserService {
|
||||
* @param id 用户 id
|
||||
* @param avatarFile 头像文件
|
||||
*/
|
||||
void updateUserAvatar(Long id, InputStream avatarFile);
|
||||
String updateUserAvatar(Long id, InputStream avatarFile);
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
|
@ -105,7 +105,7 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUserAvatar(Long id, InputStream avatarFile) {
|
||||
public String updateUserAvatar(Long id, InputStream avatarFile) {
|
||||
this.checkUserExists(id);
|
||||
// 存储文件
|
||||
String avatar = fileService.createFile(IdUtil.fastUUID(), IoUtil.readBytes(avatarFile));
|
||||
@ -114,6 +114,7 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
sysUserDO.setId(id);
|
||||
sysUserDO.setAvatar(avatar);
|
||||
userMapper.updateById(sysUserDO);
|
||||
return avatar;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -113,7 +113,7 @@ export function updateUserPwd(oldPassword, newPassword) {
|
||||
// 用户头像上传
|
||||
export function uploadAvatar(data) {
|
||||
return request({
|
||||
url: '/system/user/profile/avatar',
|
||||
url: '/system/user/profile/update-avatar',
|
||||
method: 'put',
|
||||
data: data
|
||||
})
|
||||
|
@ -123,11 +123,11 @@ export default {
|
||||
uploadImg() {
|
||||
this.$refs.cropper.getCropBlob(data => {
|
||||
let formData = new FormData();
|
||||
formData.append("avatarfile", data);
|
||||
uploadAvatar(formData).then(response => {
|
||||
formData.append("avatarFile", data);
|
||||
uploadAvatar(formData).then(resp => {
|
||||
this.open = false;
|
||||
this.options.img = process.env.VUE_APP_BASE_API + response.imgUrl;
|
||||
store.commit('SET_AVATAR', this.options.img);
|
||||
// this.options.img = process.env.VUE_APP_BASE_API + response.imgUrl;
|
||||
store.commit('SET_AVATAR', resp.data);
|
||||
this.msgSuccess("修改成功");
|
||||
this.visible = false;
|
||||
});
|
||||
@ -164,4 +164,4 @@ export default {
|
||||
line-height: 110px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
Loading…
Reference in New Issue
Block a user