修复头像的 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); return success(true);
} }
@PutMapping("/upload-avatar") @PutMapping("/update-avatar")
@ApiOperation("上传用户个人头像") @ApiOperation("上传用户个人头像")
public CommonResult<Boolean> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws IOException { public CommonResult<String> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws IOException {
if (file.isEmpty()) { if (file.isEmpty()) {
throw ServiceExceptionUtil.exception(FILE_IS_EMPTY); throw ServiceExceptionUtil.exception(FILE_IS_EMPTY);
} }
userService.updateUserAvatar(getLoginUserId(), file.getInputStream()); String avatar = userService.updateUserAvatar(getLoginUserId(), file.getInputStream());
return success(true); return success(avatar);
} }
} }

View File

@ -63,7 +63,7 @@ public interface SysUserService {
* @param id 用户 id * @param id 用户 id
* @param avatarFile 头像文件 * @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 @Override
public void updateUserAvatar(Long id, InputStream avatarFile) { public String updateUserAvatar(Long id, InputStream avatarFile) {
this.checkUserExists(id); this.checkUserExists(id);
// 存储文件 // 存储文件
String avatar = fileService.createFile(IdUtil.fastUUID(), IoUtil.readBytes(avatarFile)); String avatar = fileService.createFile(IdUtil.fastUUID(), IoUtil.readBytes(avatarFile));
@ -114,6 +114,7 @@ public class SysUserServiceImpl implements SysUserService {
sysUserDO.setId(id); sysUserDO.setId(id);
sysUserDO.setAvatar(avatar); sysUserDO.setAvatar(avatar);
userMapper.updateById(sysUserDO); userMapper.updateById(sysUserDO);
return avatar;
} }
@Override @Override

View File

@ -113,7 +113,7 @@ export function updateUserPwd(oldPassword, newPassword) {
// 用户头像上传 // 用户头像上传
export function uploadAvatar(data) { export function uploadAvatar(data) {
return request({ return request({
url: '/system/user/profile/avatar', url: '/system/user/profile/update-avatar',
method: 'put', method: 'put',
data: data data: data
}) })

View File

@ -123,11 +123,11 @@ export default {
uploadImg() { uploadImg() {
this.$refs.cropper.getCropBlob(data => { this.$refs.cropper.getCropBlob(data => {
let formData = new FormData(); let formData = new FormData();
formData.append("avatarfile", data); formData.append("avatarFile", data);
uploadAvatar(formData).then(response => { uploadAvatar(formData).then(resp => {
this.open = false; this.open = false;
this.options.img = process.env.VUE_APP_BASE_API + response.imgUrl; // this.options.img = process.env.VUE_APP_BASE_API + response.imgUrl;
store.commit('SET_AVATAR', this.options.img); store.commit('SET_AVATAR', resp.data);
this.msgSuccess("修改成功"); this.msgSuccess("修改成功");
this.visible = false; this.visible = false;
}); });
@ -164,4 +164,4 @@ export default {
line-height: 110px; line-height: 110px;
border-radius: 50%; border-radius: 50%;
} }
</style> </style>