diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/Dtos/Account/UpdateIconDto.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/Dtos/Account/UpdateIconDto.cs index 5342b7eb..0c686648 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/Dtos/Account/UpdateIconDto.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/Dtos/Account/UpdateIconDto.cs @@ -3,5 +3,6 @@ public class UpdateIconDto { public string? Icon { get; set; } + public Guid? UserId { get; set; } } } diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/AccountService.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/AccountService.cs index 0882a965..1cd3182e 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/AccountService.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/AccountService.cs @@ -379,7 +379,19 @@ namespace Yi.Framework.Rbac.Application.Services /// public async Task UpdateIconAsync(UpdateIconDto input) { - var entity = await _userRepository.GetByIdAsync(_currentUser.Id); + Guid userId; + + if (input.UserId == null) + { + userId = _currentUser.GetId(); + } + else + { + userId = input.UserId.Value; + } + + var entity = await _userRepository.GetByIdAsync(userId); + if (entity.Icon == input.Icon) { return false; @@ -390,7 +402,7 @@ namespace Yi.Framework.Rbac.Application.Services //发布更新头像任务事件 await this.LocalEventBus.PublishAsync( - new AssignmentEventArgs(AssignmentRequirementTypeEnum.UpdateIcon, _currentUser.GetId()), false); + new AssignmentEventArgs(AssignmentRequirementTypeEnum.UpdateIcon, userId), false); return true; } } diff --git a/Yi.Pure.Vue3/src/api/file.ts b/Yi.Pure.Vue3/src/api/file.ts index d0c43d6d..87c87beb 100644 --- a/Yi.Pure.Vue3/src/api/file.ts +++ b/Yi.Pure.Vue3/src/api/file.ts @@ -2,11 +2,15 @@ import type { ResultFile } from "@/api/result"; /** 上传文件*/ -export const uploadFile = (data?: object) => { - return http.request("post", "/file", { - headers: { - "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" - }, - data - }); +export const uploadFile = data => { + return http.request( + "post", + "/file", + { data }, + { + headers: { + "Content-Type": "multipart/form-data" + } + } + ); }; diff --git a/Yi.Pure.Vue3/src/api/system/user.ts b/Yi.Pure.Vue3/src/api/system/user.ts index 6d7ae78d..04723e3b 100644 --- a/Yi.Pure.Vue3/src/api/system/user.ts +++ b/Yi.Pure.Vue3/src/api/system/user.ts @@ -52,7 +52,7 @@ export const updateUserProfile = data => { /** 只修改用户头像 */ export const updateUserIcon = data => { - return http.request("put", `/account/icon`, { data: { icon: data } }); + return http.request("put", `/account/icon`, { data }); }; /** 用户密码重置 */ diff --git a/Yi.Pure.Vue3/src/views/system/user/utils/hook.tsx b/Yi.Pure.Vue3/src/views/system/user/utils/hook.tsx index f1ca112b..0a36e58e 100644 --- a/Yi.Pure.Vue3/src/views/system/user/utils/hook.tsx +++ b/Yi.Pure.Vue3/src/views/system/user/utils/hook.tsx @@ -11,6 +11,7 @@ import { addDialog } from "@/components/ReDialog"; import type { PaginationProps } from "@pureadmin/table"; import ReCropperPreview from "@/components/ReCropperPreview"; import type { FormItemProps } from "../utils/types"; +import { createFormData } from "@pureadmin/utils"; import { getKeyList, isAllEmpty, @@ -24,10 +25,12 @@ import { resetUserPwd, changeUserStatus, updateUser, - getUserList + getUserList, + updateUserIcon } from "@/api/system/user"; import { getRoleOption } from "@/api/system/role"; import { getDeptList } from "@/api/system/dept"; +import { uploadFile } from "@/api/file"; import { ElForm, ElInput, @@ -93,7 +96,7 @@ export function useUser(tableRef: Ref, treeRef: Ref) { @@ -402,8 +405,24 @@ export function useUser(tableRef: Ref, treeRef: Ref) { beforeSure: done => { console.log("裁剪后的图片信息:", avatarInfo.value); // 根据实际业务使用avatarInfo.value和row里的某些字段去调用上传头像接口即可 - done(); // 关闭弹框 - onSearch(); // 刷新表格数据 + const formData = createFormData({ + file: avatarInfo.value // file 文件 + }); + uploadFile(formData) + .then(async response => { + let data = { + userId: row.id, + icon: response.data[0]["id"] + }; + updateUserIcon(data).then(_response2 => { + message(`头像更新成功`, { type: "success" }); + done(); // 关闭弹框 + onSearch(); // 刷新表格数据 + }); + }) + .catch(error => { + message(`头像更新异常 ${error}`, { type: "error" }); + }); }, closeCallBack: () => cropRef.value.hidePopover() });