修复头像的 bug

This commit is contained in:
YunaiV 2021-10-06 01:21:18 +08:00
parent 79f9f7b93d
commit e8e6024a2b
5 changed files with 13 additions and 12 deletions

View File

@ -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);
}
}

View File

@ -63,7 +63,7 @@ public interface SysUserService {
* @param id 用户 id
* @param avatarFile 头像文件
*/
void updateUserAvatar(Long id, InputStream avatarFile);
String updateUserAvatar(Long id, InputStream avatarFile);
/**
* 修改密码

View File

@ -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

View File

@ -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
})

View File

@ -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;
});