From 8e66a9880c978f6b6d930ae5c7d8a574217f9972 Mon Sep 17 00:00:00 2001
From: tyjctl <419999127@qq.com>
Date: Tue, 24 Sep 2024 14:44:06 +0800
Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85pure=E7=94=A8=E6=88=B7?=
=?UTF-8?q?=E5=A4=B4=E5=83=8F=E4=B8=8A=E4=BC=A0=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Dtos/Account/UpdateIconDto.cs | 1 +
.../Services/AccountService.cs | 16 +++++++++--
Yi.Pure.Vue3/src/api/file.ts | 18 ++++++++-----
Yi.Pure.Vue3/src/api/system/user.ts | 2 +-
.../src/views/system/user/utils/hook.tsx | 27 ++++++++++++++++---
5 files changed, 50 insertions(+), 14 deletions(-)
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()
});