mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 01:59:20 +08:00
fix(profile): 修复头像预览 - 改用 @change 替代 before-upload
before-upload 的 async 返回值处理在某些场景下不生效,改为 @change 事件直接处理
This commit is contained in:
@@ -61,22 +61,22 @@ async function fetchUserInfo() {
|
||||
}
|
||||
}
|
||||
|
||||
async function handleAvatarChange(info: any) {
|
||||
const file = info.file.originFileObj || info.file;
|
||||
if (!file) return false;
|
||||
function handleAvatarChange({ file }: { file: any }) {
|
||||
// 获取实际文件对象
|
||||
const actualFile = file.originFileObj || file;
|
||||
if (!actualFile) return;
|
||||
|
||||
if (!file.type.startsWith('image/')) {
|
||||
if (!actualFile.type.startsWith('image/')) {
|
||||
message.error('只能上传图片文件');
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
if (file.size > 2 * 1024 * 1024) {
|
||||
if (actualFile.size > 2 * 1024 * 1024) {
|
||||
message.error('图片大小不能超过 2MB');
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
// 缓存头像文件,预览由 computed avatarSrc 自动处理
|
||||
pendingAvatarFile.value = file;
|
||||
return false; // 阻止默认上传
|
||||
pendingAvatarFile.value = actualFile;
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
@@ -153,7 +153,7 @@ fetchUserInfo();
|
||||
<div class="flex items-center">
|
||||
<div class="mr-6">
|
||||
<Upload
|
||||
:before-upload="handleAvatarChange"
|
||||
@change="handleAvatarChange"
|
||||
:show-upload-list="false"
|
||||
accept="image/*"
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user