From 21ee4866765e4f9c17c630ce1215d28864bc13d5 Mon Sep 17 00:00:00 2001 From: zyh Date: Thu, 10 Apr 2025 13:58:21 +0000 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=8E=B7=E5=8F=96=E5=92=8C?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=BD=93=E5=89=8D=E7=94=A8=E6=88=B7=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E7=9A=84API=E6=8E=A5=E5=8F=A3=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E5=9C=A8=E8=AE=BE=E7=BD=AE=E9=A1=B5=E9=9D=A2=E4=B8=AD=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF=E7=9A=84=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E9=80=BB=E8=BE=91=EF=BC=8C=E6=8F=90=E5=8D=87=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BD=93=E9=AA=8C=E5=92=8C=E4=BB=A3=E7=A0=81=E5=8F=AF?= =?UTF-8?q?=E7=BB=B4=E6=8A=A4=E6=80=A7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/mobile/api.ts | 20 ++++++++++++++++++++ client/mobile/pages_settings.tsx | 4 +--- 2 files changed, 21 insertions(+), 3 deletions(-) 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,