import { Button, Card, Form, Input, Layout, Typography, message } from "antd"; import { LockOutlined, LogoutOutlined } from "@ant-design/icons"; import { useState } from "react"; import { useNavigate } from "react-router-dom"; import { updateMyPassword } from "@/api"; const { Title, Text } = Typography; type ResetPasswordFormValues = { oldPassword: string; newPassword: string; confirmPassword: string; }; export default function ResetPassword() { const [loading, setLoading] = useState(false); const navigate = useNavigate(); const [form] = Form.useForm(); const goToLogin = () => { localStorage.clear(); sessionStorage.clear(); navigate("/login"); }; const onFinish = async (values: ResetPasswordFormValues) => { setLoading(true); try { await updateMyPassword({ oldPassword: values.oldPassword, newPassword: values.newPassword }); message.success("密码已更新,请重新登录"); goToLogin(); } finally { setLoading(false); } }; return (
首次登录请修改密码 当前账号被要求更新初始密码,提交成功后会跳转到登录页。
} /> } /> ({ validator(_, value) { if (!value || getFieldValue("newPassword") === value) { return Promise.resolve(); } return Promise.reject(new Error("两次输入的新密码不一致")); } }) ]} > } />
); }