From 9c8abbc3419fa954a364c52ba5c78e4b128bd6c7 Mon Sep 17 00:00:00 2001 From: sunjianfeng Date: Fri, 12 Sep 2025 01:05:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=89=8D=E7=AB=AF=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E5=A4=B4=E5=83=8F=E5=90=8D=E7=A7=B0=E5=8F=96=E5=80=BC=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E4=BB=A5=E5=8F=8A=E7=94=A8=E6=88=B7=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E4=BF=A1=E6=81=AF=E6=97=B6=E8=BF=98=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E7=9A=84=E6=98=AF=E6=97=A7=E7=9A=84=E5=A4=B4=E5=83=8F?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/UploadFile/src/useUpload.ts | 10 +++++----- src/views/Profile/components/BasicInfo.vue | 15 +++++++++++++++ src/views/Profile/components/ProfileUser.vue | 13 +++++++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/components/UploadFile/src/useUpload.ts b/src/components/UploadFile/src/useUpload.ts index 951b23978..9fc27a0b4 100644 --- a/src/components/UploadFile/src/useUpload.ts +++ b/src/components/UploadFile/src/useUpload.ts @@ -20,7 +20,7 @@ export const useUpload = (directory?: string) => { // 模式一:前端上传 if (isClientUpload) { // 1.1 生成文件名称 - const fileName = await generateFileName(options.file) + const fileName = options.filename // 1.2 获取文件预签名地址 const presignedInfo = await FileApi.getFilePresignedUrl(fileName, directory) // 1.3 上传文件(不能使用 ElUpload 的 ajaxUpload 方法的原因:其使用的是 FormData 上传,Minio 不支持) @@ -32,7 +32,7 @@ export const useUpload = (directory?: string) => { }) .then(() => { // 1.4. 记录文件信息到后端(异步) - createFile(presignedInfo, options.file) + createFile(presignedInfo, options.file,fileName) // 通知成功,数据格式保持与后端上传的返回结果一致 return { data: presignedInfo.url } }) @@ -64,15 +64,15 @@ export const useUpload = (directory?: string) => { /** * 创建文件信息 * @param vo 文件预签名信息 - * @param name 文件名称 * @param file 文件 + * @param fileName */ -function createFile(vo: FileApi.FilePresignedUrlRespVO, file: UploadRawFile) { +function createFile(vo: FileApi.FilePresignedUrlRespVO, file: UploadRawFile, fileName: string) { const fileVo = { configId: vo.configId, url: vo.url, path: vo.path, - name: file.name, + name: fileName, type: file.type, size: file.size } diff --git a/src/views/Profile/components/BasicInfo.vue b/src/views/Profile/components/BasicInfo.vue index f785affb9..82181d1f1 100644 --- a/src/views/Profile/components/BasicInfo.vue +++ b/src/views/Profile/components/BasicInfo.vue @@ -78,6 +78,21 @@ const schema = reactive([ } ]) const formRef = ref() // 表单 Ref + +// 监听 userStore 中头像的变化,同步更新表单数据 +watch( + () => userStore.getUser.avatar, + (newAvatar) => { + if (newAvatar && formRef.value) { + // 直接更新表单模型中的头像字段 + const formModel = formRef.value.formModel + if (formModel) { + formModel.avatar = newAvatar + } + } + } +) + const submit = () => { const elForm = unref(formRef)?.getElFormRef() if (!elForm) return diff --git a/src/views/Profile/components/ProfileUser.vue b/src/views/Profile/components/ProfileUser.vue index 6282c3e0d..e226af09f 100644 --- a/src/views/Profile/components/ProfileUser.vue +++ b/src/views/Profile/components/ProfileUser.vue @@ -49,18 +49,31 @@