补充pure用户头像上传功能
This commit is contained in:
@@ -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; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -379,7 +379,19 @@ 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;
|
||||||
|
|
||||||
|
if (input.UserId == null)
|
||||||
|
{
|
||||||
|
userId = _currentUser.GetId();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
userId = input.UserId.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
var entity = await _userRepository.GetByIdAsync(userId);
|
||||||
|
|
||||||
if (entity.Icon == input.Icon)
|
if (entity.Icon == input.Icon)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@@ -390,7 +402,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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 });
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 用户密码重置 */
|
/** 用户密码重置 */
|
||||||
|
|||||||
@@ -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()
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user