diff --git a/client/mobile/api.ts b/client/mobile/api.ts index b816a89..647cd66 100644 --- a/client/mobile/api.ts +++ b/client/mobile/api.ts @@ -222,6 +222,26 @@ export const UserAPI = { } catch (error) { throw error; } + }, + + // 获取当前用户信息 + getCurrentUser: async (): Promise => { + try { + const response = await axios.get(`${API_BASE_URL}/users/me`); + return response.data; + } catch (error) { + throw error; + } + }, + + // 更新当前用户信息 + updateCurrentUser: async (userData: Partial): Promise => { + try { + const response = await axios.put(`${API_BASE_URL}/users/me`, userData); + return response.data; + } catch (error) { + throw error; + } } }; diff --git a/client/mobile/pages_settings.tsx b/client/mobile/pages_settings.tsx index 5bffe2d..6fa6a5c 100644 --- a/client/mobile/pages_settings.tsx +++ b/client/mobile/pages_settings.tsx @@ -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,