!49 pure补充头像上传逻辑

Merge pull request !49 from tyjctl/abp
This commit is contained in:
橙子
2024-10-07 07:02:36 +00:00
committed by Gitee
5 changed files with 42 additions and 15 deletions

View File

@@ -3,5 +3,6 @@
public class UpdateIconDto public class UpdateIconDto
{ {
public string? Icon { get; set; } public string? Icon { get; set; }
public Guid? UserId { get; set; }
} }
} }

View File

@@ -1,4 +1,4 @@
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Lazy.Captcha.Core; using Lazy.Captcha.Core;
using Mapster; using Mapster;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
@@ -427,7 +427,10 @@ namespace Yi.Framework.Rbac.Application.Services
/// <returns></returns> /// <returns></returns>
public async Task<bool> UpdateIconAsync(UpdateIconDto input) public async Task<bool> UpdateIconAsync(UpdateIconDto input)
{ {
var entity = await _userRepository.GetByIdAsync(_currentUser.Id); Guid userId=input.UserId == null?_currentUser.GetId():input.UserId.Value;
var entity = await _userRepository.GetByIdAsync(userId);
if (entity.Icon == input.Icon) if (entity.Icon == input.Icon)
{ {
return false; return false;
@@ -438,7 +441,7 @@ namespace Yi.Framework.Rbac.Application.Services
//发布更新头像任务事件 //发布更新头像任务事件
await this.LocalEventBus.PublishAsync( await this.LocalEventBus.PublishAsync(
new AssignmentEventArgs(AssignmentRequirementTypeEnum.UpdateIcon, _currentUser.GetId()), false); new AssignmentEventArgs(AssignmentRequirementTypeEnum.UpdateIcon, userId), false);
return true; return true;
} }
} }

View File

@@ -2,11 +2,15 @@
import type { ResultFile } from "@/api/result"; import type { ResultFile } from "@/api/result";
/** 上传文件*/ /** 上传文件*/
export const uploadFile = (data?: object) => { export const uploadFile = data => {
return http.request<ResultFile>("post", "/file", { return http.request<ResultFile>(
headers: { "post",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" "/file",
}, { data },
data {
}); headers: {
"Content-Type": "multipart/form-data"
}
}
);
}; };

View File

@@ -52,7 +52,7 @@ export const updateUserProfile = data => {
/** 只修改用户头像 */ /** 只修改用户头像 */
export const updateUserIcon = data => { export const updateUserIcon = data => {
return http.request<Result>("put", `/account/icon`, { data: { icon: data } }); return http.request<Result>("put", `/account/icon`, { data });
}; };
/** 用户密码重置 */ /** 用户密码重置 */

View File

@@ -11,6 +11,7 @@ import { addDialog } from "@/components/ReDialog";
import type { PaginationProps } from "@pureadmin/table"; import type { PaginationProps } from "@pureadmin/table";
import ReCropperPreview from "@/components/ReCropperPreview"; import ReCropperPreview from "@/components/ReCropperPreview";
import type { FormItemProps } from "../utils/types"; import type { FormItemProps } from "../utils/types";
import { createFormData } from "@pureadmin/utils";
import { import {
getKeyList, getKeyList,
isAllEmpty, isAllEmpty,
@@ -24,10 +25,12 @@ import {
resetUserPwd, resetUserPwd,
changeUserStatus, changeUserStatus,
updateUser, updateUser,
getUserList getUserList,
updateUserIcon
} from "@/api/system/user"; } from "@/api/system/user";
import { getRoleOption } from "@/api/system/role"; import { getRoleOption } from "@/api/system/role";
import { getDeptList } from "@/api/system/dept"; import { getDeptList } from "@/api/system/dept";
import { uploadFile } from "@/api/file";
import { import {
ElForm, ElForm,
ElInput, ElInput,
@@ -93,7 +96,7 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
<el-image <el-image
fit="cover" fit="cover"
preview-teleported={true} preview-teleported={true}
src={getFileUrl(row.avatar, userAvatar)} src={getFileUrl(row.icon, userAvatar)}
preview-src-list={Array.of(getFileUrl(row.avatar, userAvatar))} preview-src-list={Array.of(getFileUrl(row.avatar, userAvatar))}
class="w-[24px] h-[24px] rounded-full align-middle" class="w-[24px] h-[24px] rounded-full align-middle"
/> />
@@ -402,8 +405,24 @@ export function useUser(tableRef: Ref, treeRef: Ref) {
beforeSure: done => { beforeSure: done => {
console.log("裁剪后的图片信息:", avatarInfo.value); console.log("裁剪后的图片信息:", avatarInfo.value);
// 根据实际业务使用avatarInfo.value和row里的某些字段去调用上传头像接口即可 // 根据实际业务使用avatarInfo.value和row里的某些字段去调用上传头像接口即可
done(); // 关闭弹框 const formData = createFormData({
onSearch(); // 刷新表格数据 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() closeCallBack: () => cropRef.value.hidePopover()
}); });