Browse Source

登录 修改 注册 接口完成

main
lk 2 months ago
parent
commit
402a6b4bd2
  1. 27
      src/pages/use/login/index.tsx
  2. 13
      src/pages/use/register/index.tsx

27
src/pages/use/login/index.tsx

@ -24,7 +24,6 @@ const Login = memo(() => {
const { mutate: upLoginFun } = useAtomValue(upLoginAtom); const { mutate: upLoginFun } = useAtomValue(upLoginAtom);
const [emailCodeData, setEmailCodeData] = useState({}); const [emailCodeData, setEmailCodeData] = useState({});
const { mutate: emailLoginMutate } = useAtomValue(emailLoginAtom); const { mutate: emailLoginMutate } = useAtomValue(emailLoginAtom);
const { mutate: telegramCodeMutate } = useAtomValue(telegramCodeAtom);
const { mutate: telegramLoginMutate } = useAtomValue(telegramLoginAtom); const { mutate: telegramLoginMutate } = useAtomValue(telegramLoginAtom);
const uphandleSubmit = (values: any) => { const uphandleSubmit = (values: any) => {
@ -32,21 +31,19 @@ const Login = memo(() => {
upLoginFun(values); upLoginFun(values);
}; };
const getEmailCode = () => {
const getEmailCode = async () => {
const email = emailform.getFieldValue("email"); const email = emailform.getFieldValue("email");
setCountdown(10);
setIsButtonDisabled(true);
setEmailCodeData(systemServ.emailCode({ is_register: false, email }));
const result = await systemServ.emailCode({ is_register: false, email });
setEmailCodeData(result);
}; };
const emailhandleSubmit = (values: any) => { const emailhandleSubmit = (values: any) => {
emailLoginMutate(values); emailLoginMutate(values);
}; };
const getTelegramCode = () => {
const getTelegramCode = async () => {
const telegram = telegramform.getFieldValue("telegram"); const telegram = telegramform.getFieldValue("telegram");
setCountdown(10);
setIsButtonDisabled(true);
telegramCodeMutate({ telegram });
const result = await systemServ.telegramCode({ telegram });
setEmailCodeData(result);
}; };
const telegramhandleSubmit = (values: any) => { const telegramhandleSubmit = (values: any) => {
telegramLoginMutate(values); telegramLoginMutate(values);
@ -63,20 +60,24 @@ const Login = memo(() => {
}); });
useEffect(() => { useEffect(() => {
localStorage.setItem("countdown", String(countdown));
}, [countdown]);
useEffect(() => {
localStorage.setItem("isButtonDisabled", JSON.stringify(isButtonDisabled)); localStorage.setItem("isButtonDisabled", JSON.stringify(isButtonDisabled));
}, [isButtonDisabled]); }, [isButtonDisabled]);
useEffect(() => { useEffect(() => {
if ((emailCodeData as any)?.code === 0) {
setCountdown(10);
setIsButtonDisabled(true);
}
}, [emailCodeData]);
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);
} else { } else {
setIsButtonDisabled(false); setIsButtonDisabled(false);
} }
localStorage.setItem("countdown", String(countdown));
return () => clearTimeout(timer); return () => clearTimeout(timer);
}, [countdown]); }, [countdown]);

13
src/pages/use/register/index.tsx

@ -16,11 +16,10 @@ const Register = memo(() => {
const [emailCodeData, setEmailCodeData] = useState({}); const [emailCodeData, setEmailCodeData] = useState({});
const [isButtonDisabled, setIsButtonDisabled] = useState<boolean>(false); const [isButtonDisabled, setIsButtonDisabled] = useState<boolean>(false);
const getEmailCode = () => {
const getEmailCode = async () => {
const email = registerForm.getFieldValue("email"); const email = registerForm.getFieldValue("email");
setCountdown(10);
setIsButtonDisabled(true);
setEmailCodeData(systemServ.emailCode({ is_register: true, email }));
const result = await systemServ.emailCode({ is_register: true, email });
setEmailCodeData(result);
}; };
const emailRegisterSubmit = (values: any) => { const emailRegisterSubmit = (values: any) => {
@ -28,9 +27,9 @@ const Register = memo(() => {
}; };
useEffect(() => { useEffect(() => {
if ((emailCodeData as any)?.countdown === -1) {
setCountdown(0);
setIsButtonDisabled(false);
if ((emailCodeData as any)?.code === 0) {
setCountdown(10);
setIsButtonDisabled(true);
} }
}, [emailCodeData]); }, [emailCodeData]);

Loading…
Cancel
Save