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

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

@ -16,11 +16,10 @@ const Register = memo(() => {
const [emailCodeData, setEmailCodeData] = useState({});
const [isButtonDisabled, setIsButtonDisabled] = useState<boolean>(false);
const getEmailCode = () => {
const getEmailCode = async () => {
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) => {
@ -28,9 +27,9 @@ const Register = memo(() => {
};
useEffect(() => {
if ((emailCodeData as any)?.countdown === -1) {
setCountdown(0);
setIsButtonDisabled(false);
if ((emailCodeData as any)?.code === 0) {
setCountdown(10);
setIsButtonDisabled(true);
}
}, [emailCodeData]);

Loading…
Cancel
Save