import { Button, Card, Form, Input, message, Tabs, Typography, Row, Col, Space, Avatar } from "antd"; import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { getCurrentUser, updateMyProfile, updateMyPassword } from "../api"; import { UserOutlined, LockOutlined, SaveOutlined, SolutionOutlined } from "@ant-design/icons"; import type { UserProfile } from "../types"; import PageHeader from "../components/shared/PageHeader"; const { Title, Text } = Typography; export default function Profile() { const { t } = useTranslation(); const [loading, setLoading] = useState(false); const [saving, setSaving] = useState(false); const [user, setUser] = useState(null); const [profileForm] = Form.useForm(); const [pwdForm] = Form.useForm(); const loadUser = async () => { setLoading(true); try { const data = await getCurrentUser(); setUser(data); profileForm.setFieldsValue(data); } catch (e) { // Interceptor handles error } finally { setLoading(false); } }; useEffect(() => { loadUser(); }, []); const handleUpdateProfile = async () => { try { const values = await profileForm.validateFields(); setSaving(true); await updateMyProfile(values); message.success(t('common.success')); loadUser(); } catch (e) { } finally { setSaving(false); } }; const handleUpdatePassword = async () => { try { const values = await pwdForm.validateFields(); setSaving(true); await updateMyPassword(values); message.success(t('common.success')); pwdForm.resetFields(); } catch (e) { } finally { setSaving(false); } }; return (
} style={{ backgroundColor: '#1677ff', marginBottom: 16 }} /> {user?.displayName} @{user?.username}
{user?.isPlatformAdmin ? 平台管理员 : 普通用户}
基本信息} key="basic" >
安全设置} key="password" >
({ validator(_, value) { if (!value || getFieldValue('newPassword') === value) { return Promise.resolve(); } return Promise.reject(new Error('两次输入的密码不一致')); }, }), ]} >
); } import { Tag } from "antd";