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 @@