import { useState } from 'react' import { Link } from 'react-router-dom' import { Building2, Eye, EyeOff } from 'lucide-react' import { useForm } from 'react-hook-form' import { zodResolver } from '@hookform/resolvers/zod' import { z } from 'zod' import api from '../../lib/api' import { Input, Label } from '../../components/ui/Input' import Button from '../../components/ui/Button' const schema = z.object({ phone: z.string().regex(/^1[3-9]\d{9}$/, '手机号格式不正确'), newPassword: z.string().min(8, '密码至少8位').max(32, '密码最多32位'), }).refine((data) => data.newPassword.length >= 8, { message: '密码至少8位', path: ['newPassword'], }) type FormData = z.infer export default function ForgotPassword() { const [showPassword, setShowPassword] = useState(false) const [error, setError] = useState('') const [success, setSuccess] = useState(false) const [loading, setLoading] = useState(false) const { register, handleSubmit, formState: { errors } } = useForm({ resolver: zodResolver(schema), }) const onSubmit = async (data: FormData) => { setError('') setLoading(true) try { await api.post('/auth/reset-password', data) setSuccess(true) } catch (err: any) { setError(err.response?.data?.error?.message || '重置失败,请稍后重试') } finally { setLoading(false) } } return (
用工合规助手

重置密码

{success ? (
密码已重置成功
返回登录
) : ( <> {error && (
{error}
)}
{errors.phone &&

{errors.phone.message}

}
{errors.newPassword &&

{errors.newPassword.message}

}
返回登录
)}
) }