import { useEffect, useState } from 'react'; import { Button, Form, Input, Message } from '@arco-design/web-react'; import { useNavigate } from 'react-router-dom'; import { authApi } from '../api'; import { Panel } from '../components/Panel'; import { ProfileInfoList } from './components/ProfileInfoList'; import { ProfileSummary } from './components/ProfileSummary'; import type { AdminProfile, ChangePasswordFormValues, ProfileFormValues } from './interface'; function ProfilePage() { const navigate = useNavigate(); const [form] = Form.useForm(); const [passwordForm] = Form.useForm(); const [loading, setLoading] = useState(false); const [saving, setSaving] = useState(false); const [changingPassword, setChangingPassword] = useState(false); const [profile, setProfile] = useState(null); const loadProfile = async () => { setLoading(true); try { const data = await authApi.getProfile(); setProfile(data); form.setFieldsValue({ nickname: data.nickname, email: data.email, }); } finally { setLoading(false); } }; useEffect(() => { void loadProfile(); }, []); const updateProfile = async (values: ProfileFormValues) => { setSaving(true); try { const data = await authApi.updateProfile(values); setProfile(data); Message.success('个人信息已更新'); } finally { setSaving(false); } }; const changePassword = async (values: ChangePasswordFormValues) => { if (values.newPassword !== values.confirmPassword) { Message.error('两次输入的新密码不一致'); return; } setChangingPassword(true); try { await authApi.changePassword({ oldPassword: values.oldPassword, newPassword: values.newPassword, }); Message.success('密码修改成功,请重新登录'); passwordForm.resetFields(); authApi.clearAuthToken(); navigate('/login', { replace: true }); } finally { setChangingPassword(false); } }; return (
{loading ? (
加载中...
) : ( <> )}
); } export default ProfilePage;