|
|
@ -1,32 +1,41 @@ |
|
|
|
import { Layout, Input, Button, Typography, Row, Col, Form } from "antd"; |
|
|
|
import { LockOutlined, MailOutlined, SecurityScanOutlined } from "@ant-design/icons"; |
|
|
|
import { createFileRoute, useNavigate } from "@tanstack/react-router"; |
|
|
|
import { useAtomValue } from "jotai"; |
|
|
|
import { useAtom, useAtomValue } from "jotai"; |
|
|
|
import React, { memo, useEffect, useState } from "react"; |
|
|
|
import { emailCodeAtom } from "@/store/system/user.ts"; |
|
|
|
import { emailCodeAtom, emailRegisterAtom } from "@/store/system/user.ts"; |
|
|
|
import { passwordRules } from "@/pages/use/useTools"; |
|
|
|
const { Title, Text, Link } = Typography; |
|
|
|
|
|
|
|
const Register = memo(() => { |
|
|
|
const navigate = useNavigate(); |
|
|
|
const [registerForm] = Form.useForm(); |
|
|
|
const { mutate: emailCodeMutate } = useAtomValue(emailCodeAtom); |
|
|
|
|
|
|
|
const handleRegisterSubmit = (values: any) => { |
|
|
|
console.log(values); |
|
|
|
// 调用注册API
|
|
|
|
}; |
|
|
|
|
|
|
|
const handleGetCode = () => { |
|
|
|
const { mutate: emailRegisterMutate } = useAtomValue(emailRegisterAtom); |
|
|
|
const { mutateAsync: emailCodeMutate, data: emailData } = useAtomValue(emailCodeAtom); |
|
|
|
//const [{ mutate: emailCodeMutate, data: emailData }] = useAtom(emailCodeAtom);
|
|
|
|
//const [, mutate: emailCodeMutate] = useAtom(emailCodeAtom);
|
|
|
|
const getEmailCode = () => { |
|
|
|
const email = registerForm.getFieldValue("email"); |
|
|
|
setCountdown(10); |
|
|
|
setIsButtonDisabled(true); |
|
|
|
emailCodeMutate({ email }); |
|
|
|
const data = emailCodeMutate({ is_register: true, email }); |
|
|
|
console.log(data); |
|
|
|
}; |
|
|
|
const emailRegisterSubmit = (values: any) => { |
|
|
|
emailRegisterMutate({ email: values.email, password: values.password, code: values.code }); |
|
|
|
}; |
|
|
|
|
|
|
|
const [countdown, setCountdown] = useState<number>(0); |
|
|
|
const [isButtonDisabled, setIsButtonDisabled] = useState<boolean>(false); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
if ((emailData as any)?.countdown === -1) { |
|
|
|
setCountdown(0); |
|
|
|
setIsButtonDisabled(false); |
|
|
|
} |
|
|
|
}, [emailData]); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
let timer: number; |
|
|
|
if (countdown > 0) { |
|
|
|
timer = setTimeout(() => setCountdown(countdown - 1), 1000); |
|
|
@ -71,27 +80,41 @@ const Register = memo(() => { |
|
|
|
height: "500px", |
|
|
|
}} |
|
|
|
> |
|
|
|
<Form form={registerForm} onFinish={handleRegisterSubmit} style={{ marginTop: "50px" }}> |
|
|
|
<Form form={registerForm} onFinish={emailRegisterSubmit} style={{ marginTop: "50px" }}> |
|
|
|
<Form.Item name="email" rules={[{ required: true, message: "请输入邮箱" }]}> |
|
|
|
<Input |
|
|
|
size="large" |
|
|
|
placeholder="请输入邮箱" |
|
|
|
prefix={<MailOutlined />} |
|
|
|
addonAfter={ |
|
|
|
<Button onClick={handleGetCode} disabled={isButtonDisabled}> |
|
|
|
<Button onClick={getEmailCode} disabled={isButtonDisabled}> |
|
|
|
{isButtonDisabled ? `${countdown}秒后重试` : "获得验证码"} |
|
|
|
</Button> |
|
|
|
} |
|
|
|
/> |
|
|
|
</Form.Item> |
|
|
|
<Form.Item name="code" rules={[{ required: true, message: "请输入验证码" }]}> |
|
|
|
<Input size="large" placeholder="请输入验证码" prefix={<SecurityScanOutlined />} /> |
|
|
|
<Input size="large" placeholder="请输入验证码" prefix={<SecurityScanOutlined />} autoComplete="off" /> |
|
|
|
</Form.Item> |
|
|
|
<Form.Item name="password" rules={[{ required: true, message: "请输入密码" }]}> |
|
|
|
<Input.Password size="large" placeholder="请输入密码" prefix={<LockOutlined />} /> |
|
|
|
<Form.Item name="password" rules={passwordRules}> |
|
|
|
<Input.Password size="large" placeholder="请输入密码" prefix={<LockOutlined />} autoComplete="off" /> |
|
|
|
</Form.Item> |
|
|
|
<Form.Item name="confirmPassword" rules={[{ required: true, message: "请确认密码" }]}> |
|
|
|
<Input.Password size="large" placeholder="请确认密码" prefix={<LockOutlined />} /> |
|
|
|
<Form.Item |
|
|
|
name="confirmPassword" |
|
|
|
dependencies={["password"]} |
|
|
|
rules={[ |
|
|
|
{ required: true, message: "请确认密码" }, |
|
|
|
({ getFieldValue }) => ({ |
|
|
|
validator(_, value) { |
|
|
|
if (!value || getFieldValue("password") === value) { |
|
|
|
return Promise.resolve(); |
|
|
|
} |
|
|
|
return Promise.reject(new Error("两次输入的密码不一致")); |
|
|
|
}, |
|
|
|
}), |
|
|
|
]} |
|
|
|
> |
|
|
|
<Input.Password size="large" placeholder="请确认密码" prefix={<LockOutlined />} autoComplete="off" /> |
|
|
|
</Form.Item> |
|
|
|
<Button type="primary" htmlType="submit" style={{ width: "100%" }}> |
|
|
|
注册 |
|
|
|