edit: response.message
This commit is contained in:
parent
d7f824f353
commit
7de5457170
21 changed files with 227 additions and 127 deletions
|
|
@ -25,6 +25,12 @@ export interface UserProfileResponse {
|
|||
};
|
||||
}
|
||||
|
||||
export interface ApiResponse<T> {
|
||||
code: number;
|
||||
message: string;
|
||||
data: T;
|
||||
}
|
||||
|
||||
// Request body for PUT /api/user/me
|
||||
export interface UpdateProfileRequest {
|
||||
prefix?: {
|
||||
|
|
@ -132,7 +138,7 @@ export const userService = {
|
|||
return response;
|
||||
},
|
||||
|
||||
async updateProfile(data: UpdateProfileRequest): Promise<UserProfileResponse> {
|
||||
async updateProfile(data: UpdateProfileRequest): Promise<ApiResponse<UserProfileResponse>> {
|
||||
const config = useRuntimeConfig();
|
||||
const useMockData = config.public.useMockData as boolean;
|
||||
|
||||
|
|
@ -140,11 +146,15 @@ export const userService = {
|
|||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
// In mock mode, just return the current profile with updates
|
||||
const profile = await this.mockGetProfile();
|
||||
return { ...profile, profile: { ...profile.profile, ...data } };
|
||||
return {
|
||||
code: 200,
|
||||
message: 'Update profile successfully',
|
||||
data: { ...profile, profile: { ...profile.profile, ...data } }
|
||||
};
|
||||
}
|
||||
|
||||
const token = getAuthToken();
|
||||
const response = await $fetch<UserProfileResponse>('/api/user/me', {
|
||||
const response = await $fetch<ApiResponse<UserProfileResponse>>('/api/user/me', {
|
||||
method: 'PUT',
|
||||
baseURL: config.public.apiBaseUrl as string,
|
||||
headers: {
|
||||
|
|
@ -156,18 +166,22 @@ export const userService = {
|
|||
return response;
|
||||
},
|
||||
|
||||
async changePassword(oldPassword: string, newPassword: string): Promise<void> {
|
||||
async changePassword(oldPassword: string, newPassword: string): Promise<ApiResponse<null>> {
|
||||
const config = useRuntimeConfig();
|
||||
const useMockData = config.public.useMockData as boolean;
|
||||
|
||||
if (useMockData) {
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
// In mock mode, just simulate success
|
||||
return;
|
||||
return {
|
||||
code: 200,
|
||||
message: 'Change password successfully',
|
||||
data: null
|
||||
};
|
||||
}
|
||||
|
||||
const token = getAuthToken();
|
||||
await $fetch('/api/user/change-password', {
|
||||
const response = await $fetch<ApiResponse<null>>('/api/user/change-password', {
|
||||
method: 'POST',
|
||||
baseURL: config.public.apiBaseUrl as string,
|
||||
headers: {
|
||||
|
|
@ -178,23 +192,29 @@ export const userService = {
|
|||
newPassword
|
||||
}
|
||||
});
|
||||
|
||||
return response;
|
||||
},
|
||||
|
||||
async uploadAvatar(file: File): Promise<{ avatar_url: string; id: number }> {
|
||||
async uploadAvatar(file: File): Promise<ApiResponse<{ avatar_url: string; id: number }>> {
|
||||
const config = useRuntimeConfig();
|
||||
const useMockData = config.public.useMockData as boolean;
|
||||
|
||||
if (useMockData) {
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
// Return mock URL
|
||||
return { avatar_url: URL.createObjectURL(file), id: 1 };
|
||||
return {
|
||||
code: 200,
|
||||
message: 'Upload avatar successfully',
|
||||
data: { avatar_url: URL.createObjectURL(file), id: 1 }
|
||||
};
|
||||
}
|
||||
|
||||
const token = getAuthToken();
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
const response = await $fetch<{ code: number; message: string; data: { avatar_url: string; id: number } }>('/api/user/upload-avatar', {
|
||||
const response = await $fetch<ApiResponse<{ avatar_url: string; id: number }>>('/api/user/upload-avatar', {
|
||||
method: 'POST',
|
||||
baseURL: config.public.apiBaseUrl as string,
|
||||
headers: {
|
||||
|
|
@ -203,6 +223,6 @@ export const userService = {
|
|||
body: formData
|
||||
});
|
||||
|
||||
return response.data;
|
||||
return response;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue