From e8e6024a2bd387b1b05c0dc6013284cccacf9295 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 6 Oct 2021 01:21:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=B4=E5=83=8F=E7=9A=84?= =?UTF-8?q?=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/user/SysUserProfileController.java | 8 ++++---- .../modules/system/service/user/SysUserService.java | 2 +- .../system/service/user/impl/SysUserServiceImpl.java | 3 ++- yudao-admin-ui/src/api/system/user.js | 2 +- .../src/views/system/user/profile/userAvatar.vue | 10 +++++----- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserProfileController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserProfileController.java index 8fb29bbed..10640ace7 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserProfileController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserProfileController.java @@ -89,14 +89,14 @@ public class SysUserProfileController { return success(true); } - @PutMapping("/upload-avatar") + @PutMapping("/update-avatar") @ApiOperation("上传用户个人头像") - public CommonResult updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws IOException { + public CommonResult 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); } } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/SysUserService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/SysUserService.java index 78071d246..792ea9038 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/SysUserService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/SysUserService.java @@ -63,7 +63,7 @@ public interface SysUserService { * @param id 用户 id * @param avatarFile 头像文件 */ - void updateUserAvatar(Long id, InputStream avatarFile); + String updateUserAvatar(Long id, InputStream avatarFile); /** * 修改密码 diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/impl/SysUserServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/impl/SysUserServiceImpl.java index 01a70f9bf..ff3e098dc 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/impl/SysUserServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/impl/SysUserServiceImpl.java @@ -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 diff --git a/yudao-admin-ui/src/api/system/user.js b/yudao-admin-ui/src/api/system/user.js index e06530c92..0243454d7 100644 --- a/yudao-admin-ui/src/api/system/user.js +++ b/yudao-admin-ui/src/api/system/user.js @@ -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 }) diff --git a/yudao-admin-ui/src/views/system/user/profile/userAvatar.vue b/yudao-admin-ui/src/views/system/user/profile/userAvatar.vue index edc15e36e..60f068931 100644 --- a/yudao-admin-ui/src/views/system/user/profile/userAvatar.vue +++ b/yudao-admin-ui/src/views/system/user/profile/userAvatar.vue @@ -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%; } - \ No newline at end of file +