From 9ac8f399f8b6357c53b01d703cd6aa2c8c981afd Mon Sep 17 00:00:00 2001 From: dayezi <1372755472@qq.com> Date: Tue, 7 May 2024 04:45:07 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=88=20perf(userAvatar):=20=E9=99=90?= =?UTF-8?q?=E5=88=B6=E7=94=A8=E6=88=B7=E4=BF=AE=E6=94=B9=E5=A4=B4=E5=83=8F?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=A7=E5=B0=8F=E4=BB=A5=E5=8F=8A=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../superAdmin/UserManagement/utils/hook.tsx | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/frontend/src/views/superAdmin/UserManagement/utils/hook.tsx b/frontend/src/views/superAdmin/UserManagement/utils/hook.tsx index 30cc999..8ff683b 100644 --- a/frontend/src/views/superAdmin/UserManagement/utils/hook.tsx +++ b/frontend/src/views/superAdmin/UserManagement/utils/hook.tsx @@ -50,7 +50,7 @@ import { reactive, onMounted } from "vue"; -import { successNotification } from "@/utils/notification"; +import { successNotification, warningNotification } from "@/utils/notification"; import { generatePassword } from "../utils/util"; export function useUser(tableRef: Ref, treeRef: Ref) { @@ -401,17 +401,24 @@ export function useUser(tableRef: Ref, treeRef: Ref) { contentRenderer: () => h(ReCropperPreview, { ref: cropRef, - imgSrc: getUserAvatar(row.avatar) || userAvatar, + imgSrc: row.avatar ? getUserAvatar(row.avatar) : userAvatar, onCropper: info => (avatarInfo.value = info) }), beforeSure: done => { - console.log("裁剪后的图片信息:", avatarInfo.value, row); + console.log("avatarInfo", avatarInfo.value.blob); // 根据实际业务使用avatarInfo.value和row里的某些字段去调用上传头像接口即可 - updateUserAvatar(row.id, avatarInfo.value).then(() => { - successNotification(`头像修改成功`); - done(); // 关闭弹框 - onSearch(); // 刷新表格数据 - }); + if ( + avatarInfo.value.blob.size < 1024 * 1024 * 3 && + avatarInfo.value.blob.type.startsWith("image") + ) { + updateUserAvatar(row.id, avatarInfo.value).then(() => { + successNotification(`头像修改成功`); + done(); // 关闭弹框 + onSearch(); // 刷新表格数据 + }); + } else { + warningNotification("请选择正确的图片格式且图片小于3M!"); + } }, closeCallBack: () => cropRef.value.hidePopover() });