From 71da2d507e2cf74fb4592af74d7be87a980cd7b4 Mon Sep 17 00:00:00 2001 From: caozehui <2427765068@qq.com> Date: Tue, 19 May 2026 10:59:07 +0800 Subject: [PATCH] =?UTF-8?q?fix(personal-center):=20=E4=B8=AA=E4=BA=BA?= =?UTF-8?q?=E5=A4=B4=E5=83=8F=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/service/api/auth.ts | 27 +++++++++++- .../personal-center/my-profile/index.vue | 41 ++++++------------- 2 files changed, 38 insertions(+), 30 deletions(-) diff --git a/src/service/api/auth.ts b/src/service/api/auth.ts index 21a47a2..0abeb83 100644 --- a/src/service/api/auth.ts +++ b/src/service/api/auth.ts @@ -1,7 +1,7 @@ import { SYSTEM_SERVICE_PREFIX } from '@/constants/service'; import { request } from '../request'; import { clearUserRouteCache } from './route'; -import type { ServiceRequestResult } from './shared'; +import { type ServiceRequestResult, mapServiceResult, normalizeStringId } from './shared'; /** 后端登录返回 */ interface BackendLoginToken { @@ -38,6 +38,14 @@ interface BackendMyProfileDetailDTO { position?: Api.SystemManage.PostSimple | null; } +interface BackendFileDTO { + id: string | number; + configId: string | number; + name?: string | null; + path: string; + url: string; +} + let userInfoPromise: Promise> | null = null; /** 将后端 token 结构转换成前端现有结构 */ @@ -187,6 +195,23 @@ export function fetchUpdateMyProfile(data: Api.Auth.UpdateMyProfileParams) { } /** 修改当前登录人密码 */ +export async function fetchUpdateMyAvatar(file: File) { + const formData = new FormData(); + formData.append('file', file); + + const result = await request({ + url: `${SYSTEM_SERVICE_PREFIX}/user/profile/update-avatar`, + method: 'put', + data: formData + }); + + return mapServiceResult(result as ServiceRequestResult, data => ({ + ...data, + id: normalizeStringId(data.id), + configId: normalizeStringId(data.configId) + })); +} + export function fetchUpdateMyPassword(data: Api.Auth.UpdateMyPasswordParams) { return request({ url: `${SYSTEM_SERVICE_PREFIX}/user/profile/update-password`, diff --git a/src/views/personal-center/my-profile/index.vue b/src/views/personal-center/my-profile/index.vue index a3aeb8e..c017a7d 100644 --- a/src/views/personal-center/my-profile/index.vue +++ b/src/views/personal-center/my-profile/index.vue @@ -1,14 +1,13 @@