新增获取和更新当前用户信息的API接口,并在设置页面中更新用户信息的调用逻辑,提升用户体验和代码可维护性。
This commit is contained in:
@@ -222,6 +222,26 @@ export const UserAPI = {
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
// 获取当前用户信息
|
||||
getCurrentUser: async (): Promise<UserResponse> => {
|
||||
try {
|
||||
const response = await axios.get(`${API_BASE_URL}/users/me`);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
// 更新当前用户信息
|
||||
updateCurrentUser: async (userData: Partial<User>): Promise<UserUpdateResponse> => {
|
||||
try {
|
||||
const response = await axios.put(`${API_BASE_URL}/users/me`, userData);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -19,9 +19,7 @@ export default function SettingsPage() {
|
||||
phone?: string
|
||||
password?: string
|
||||
}) => {
|
||||
const res = await UserAPI.getUsers({ limit: 1 })
|
||||
if (!res.data?.[0]?.id) throw new Error('用户ID不存在')
|
||||
return UserAPI.updateUser(res.data[0].id, {
|
||||
return UserAPI.updateCurrentUser({
|
||||
nickname: data.nickname,
|
||||
email: data.email,
|
||||
phone: data.phone,
|
||||
|
||||
Reference in New Issue
Block a user