From d7b7a8df18305e8660eeaebec90817417502f80d Mon Sep 17 00:00:00 2001 From: zyh Date: Thu, 10 Apr 2025 13:49:14 +0000 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=AE=BE=E7=BD=AE=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=EF=BC=8C=E6=9B=B4=E6=96=B0=E4=B8=AA=E4=BA=BA=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E9=A1=B5=E9=9D=A2=E4=BB=A5=E5=8C=85=E5=90=AB=E5=AF=BC?= =?UTF-8?q?=E8=88=AA=E6=8C=89=E9=92=AE=EF=BC=8C=E4=BC=98=E5=8C=96=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BD=93=E9=AA=8C=E5=92=8C=E4=BB=A3=E7=A0=81=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/mobile/mobile_app.tsx | 7 +- client/mobile/pages_profile.tsx | 81 ++--------------------- client/mobile/pages_settings.tsx | 110 +++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+), 75 deletions(-) create mode 100644 client/mobile/pages_settings.tsx diff --git a/client/mobile/mobile_app.tsx b/client/mobile/mobile_app.tsx index 8f3b4ce..a9fb809 100644 --- a/client/mobile/mobile_app.tsx +++ b/client/mobile/mobile_app.tsx @@ -192,6 +192,7 @@ const ErrorPage = () => { }; import ProfilePage from './pages_profile.tsx' +import SettingsPage from './pages_settings.tsx' // 移动端布局组件 - 包含底部导航 const MobileLayout = () => { @@ -224,7 +225,7 @@ const MobileLayout = () => { 通知 - { { path: 'notifications', element: + }, + { + path: 'settings', + element: } ] }, diff --git a/client/mobile/pages_profile.tsx b/client/mobile/pages_profile.tsx index 0ed74c4..681fb13 100644 --- a/client/mobile/pages_profile.tsx +++ b/client/mobile/pages_profile.tsx @@ -104,80 +104,13 @@ export default function ProfilePage() {

个人信息

- - -
-

编辑信息

-
-
- - -
- -
- - - {errors.nickname &&

{errors.nickname.message}

} -
- -
- - - {errors.email &&

{errors.email.message}

} -
- -
- - -
- -
- - -
- -
- - -
-
+ +
diff --git a/client/mobile/pages_settings.tsx b/client/mobile/pages_settings.tsx new file mode 100644 index 0000000..5bffe2d --- /dev/null +++ b/client/mobile/pages_settings.tsx @@ -0,0 +1,110 @@ +import React from 'react' +import { useForm } from 'react-hook-form' +import { useMutation } from '@tanstack/react-query' +import { UserAPI } from './api.ts' +import { useAuth } from './hooks.tsx' + +export default function SettingsPage() { + const { register, handleSubmit, formState: { errors } } = useForm<{ + nickname: string + email: string + phone?: string + password?: string + }>() + + const { mutate: updateUser, isPending } = useMutation({ + mutationFn: async (data: { + nickname: string + email: string + 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, { + nickname: data.nickname, + email: data.email, + phone: data.phone, + ...(data.password ? { password: data.password } : {}) + }) + }, + onSuccess: () => alert('更新成功'), + onError: (error) => { + console.error('更新失败:', error) + alert('更新失败') + } + }) + + const onSubmit = (data: { + nickname: string + email: string + phone?: string + password?: string + }) => { + updateUser(data) + } + + return ( +
+

设置

+ +
+

编辑个人信息

+
+
+ + + {errors.nickname &&

{errors.nickname.message}

} +
+ +
+ + + {errors.email &&

{errors.email.message}

} +
+ +
+ + +
+ +
+ + +
+ +
+ +
+
+
+
+ ) +} \ No newline at end of file