|
@ -1,32 +1,41 @@ |
|
|
import { Layout, Input, Button, Typography, Row, Col, Form } from "antd"; |
|
|
import { Layout, Input, Button, Typography, Row, Col, Form } from "antd"; |
|
|
import { LockOutlined, MailOutlined, SecurityScanOutlined } from "@ant-design/icons"; |
|
|
import { LockOutlined, MailOutlined, SecurityScanOutlined } from "@ant-design/icons"; |
|
|
import { createFileRoute, useNavigate } from "@tanstack/react-router"; |
|
|
import { createFileRoute, useNavigate } from "@tanstack/react-router"; |
|
|
import { useAtomValue } from "jotai"; |
|
|
|
|
|
|
|
|
import { useAtom, useAtomValue } from "jotai"; |
|
|
import React, { memo, useEffect, useState } from "react"; |
|
|
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 { Title, Text, Link } = Typography; |
|
|
|
|
|
|
|
|
const Register = memo(() => { |
|
|
const Register = memo(() => { |
|
|
const navigate = useNavigate(); |
|
|
const navigate = useNavigate(); |
|
|
const [registerForm] = Form.useForm(); |
|
|
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"); |
|
|
const email = registerForm.getFieldValue("email"); |
|
|
setCountdown(10); |
|
|
setCountdown(10); |
|
|
setIsButtonDisabled(true); |
|
|
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 [countdown, setCountdown] = useState<number>(0); |
|
|
const [isButtonDisabled, setIsButtonDisabled] = useState<boolean>(false); |
|
|
const [isButtonDisabled, setIsButtonDisabled] = useState<boolean>(false); |
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
useEffect(() => { |
|
|
|
|
|
if ((emailData as any)?.countdown === -1) { |
|
|
|
|
|
setCountdown(0); |
|
|
|
|
|
setIsButtonDisabled(false); |
|
|
|
|
|
} |
|
|
|
|
|
}, [emailData]); |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
let timer: number; |
|
|
let timer: number; |
|
|
if (countdown > 0) { |
|
|
if (countdown > 0) { |
|
|
timer = setTimeout(() => setCountdown(countdown - 1), 1000); |
|
|
timer = setTimeout(() => setCountdown(countdown - 1), 1000); |
|
@ -71,27 +80,41 @@ const Register = memo(() => { |
|
|
height: "500px", |
|
|
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: "请输入邮箱" }]}> |
|
|
<Form.Item name="email" rules={[{ required: true, message: "请输入邮箱" }]}> |
|
|
<Input |
|
|
<Input |
|
|
size="large" |
|
|
size="large" |
|
|
placeholder="请输入邮箱" |
|
|
placeholder="请输入邮箱" |
|
|
prefix={<MailOutlined />} |
|
|
prefix={<MailOutlined />} |
|
|
addonAfter={ |
|
|
addonAfter={ |
|
|
<Button onClick={handleGetCode} disabled={isButtonDisabled}> |
|
|
|
|
|
|
|
|
<Button onClick={getEmailCode} disabled={isButtonDisabled}> |
|
|
{isButtonDisabled ? `${countdown}秒后重试` : "获得验证码"} |
|
|
{isButtonDisabled ? `${countdown}秒后重试` : "获得验证码"} |
|
|
</Button> |
|
|
</Button> |
|
|
} |
|
|
} |
|
|
/> |
|
|
/> |
|
|
</Form.Item> |
|
|
</Form.Item> |
|
|
<Form.Item name="code" rules={[{ required: true, message: "请输入验证码" }]}> |
|
|
<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> |
|
|
<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> |
|
|
<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> |
|
|
</Form.Item> |
|
|
<Button type="primary" htmlType="submit" style={{ width: "100%" }}> |
|
|
<Button type="primary" htmlType="submit" style={{ width: "100%" }}> |
|
|
注册 |
|
|
注册 |
|
|