|
|
|
@ -5,7 +5,7 @@ import React, { useState, useMemo, useEffect } from 'react';
|
|
|
|
|
import { debounce } from 'lodash';
|
|
|
|
|
import { useShallow } from 'zustand/react/shallow';
|
|
|
|
|
|
|
|
|
|
import { Input, Button } from '@/components';
|
|
|
|
|
import { Button } from '@/components';
|
|
|
|
|
import { apiSendSMS } from '@/services';
|
|
|
|
|
import useUserStore from '@/store/user';
|
|
|
|
|
|
|
|
|
@ -19,6 +19,7 @@ export default function LoginForm() {
|
|
|
|
|
|
|
|
|
|
const [phone, setPhone] = useState<string>('17861518060'); // 手机号
|
|
|
|
|
const [authCode, seAuthCode] = useState<string>('111111'); // 验证码
|
|
|
|
|
const [errorText, setErrorText] = useState<string>(''); // 验证码
|
|
|
|
|
const [time, setTime] = useState<number>(0); // 倒计时
|
|
|
|
|
const [btnLoading, setBtnLoading] = useState<boolean>(false);
|
|
|
|
|
const deviceId = '1'; // 设备id 暂时写死
|
|
|
|
@ -29,23 +30,33 @@ export default function LoginForm() {
|
|
|
|
|
setBtnLoading(true);
|
|
|
|
|
const result = await apiSendSMS({ mobile: phone, deviceId });
|
|
|
|
|
|
|
|
|
|
if (result.code === 200) {
|
|
|
|
|
setTime(59);
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
setBtnLoading(false);
|
|
|
|
|
}, 60000);
|
|
|
|
|
if (result.code !== 200) {
|
|
|
|
|
setErrorText(result.message);
|
|
|
|
|
setBtnLoading(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
setBtnLoading(false);
|
|
|
|
|
setTime(59);
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
setBtnLoading(false);
|
|
|
|
|
}, 60000);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 登录
|
|
|
|
|
const handleLogin = async () => {
|
|
|
|
|
setBtnLoading(true);
|
|
|
|
|
const result = await userLogin({ mobile: phone, mobileCheckCode: authCode, deviceId: '1' });
|
|
|
|
|
if (result) setShowLogin(false);
|
|
|
|
|
if (result.code === 200) {
|
|
|
|
|
setShowLogin(false);
|
|
|
|
|
window.location.reload();
|
|
|
|
|
} else {
|
|
|
|
|
setErrorText(result.message);
|
|
|
|
|
setBtnLoading(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 输入框,只允许输入数字
|
|
|
|
|
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>, fn: (text: string) => void) => {
|
|
|
|
|
if (errorText) setErrorText('');
|
|
|
|
|
const inputValue = e.target.value;
|
|
|
|
|
const regex = /^[0-9]*$/;
|
|
|
|
|
if (regex.test(inputValue) || inputValue === '') fn(e.target.value);
|
|
|
|
@ -64,7 +75,8 @@ export default function LoginForm() {
|
|
|
|
|
return (
|
|
|
|
|
<form autoComplete="on">
|
|
|
|
|
<div className="w-full flex flex-col">
|
|
|
|
|
<Input
|
|
|
|
|
<input
|
|
|
|
|
className="w-full h-[56px] rounded-[100px] px-[14px] bg-[#fff] leading-[20px]"
|
|
|
|
|
type="text"
|
|
|
|
|
value={phone}
|
|
|
|
|
maxLength={11}
|
|
|
|
@ -73,8 +85,8 @@ export default function LoginForm() {
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<div className="relative w-full mt-[20px]">
|
|
|
|
|
<Input
|
|
|
|
|
className="w-full"
|
|
|
|
|
<input
|
|
|
|
|
className="w-full h-[56px] rounded-[100px] px-[14px] bg-[#fff] leading-[20px]"
|
|
|
|
|
type="text"
|
|
|
|
|
value={authCode}
|
|
|
|
|
maxLength={6}
|
|
|
|
@ -83,7 +95,7 @@ export default function LoginForm() {
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
type="black"
|
|
|
|
|
type="white"
|
|
|
|
|
className={`absolute top-[6px] right-[6px] w-[123px] h-[44px] rounded-[100px] font-size-[14px] leading-[20px] ${time ? 'text-[#000]' : ''}`}
|
|
|
|
|
disabled={btnLoading || activeSMS}
|
|
|
|
|
onClick={debounce(handleSendSMS, 300)}
|
|
|
|
@ -101,6 +113,8 @@ export default function LoginForm() {
|
|
|
|
|
>
|
|
|
|
|
确定登录
|
|
|
|
|
</Button>
|
|
|
|
|
|
|
|
|
|
<p className="mt-[16px] text-center text-brand text-[13px] leading-[18.2px]">{errorText}</p>
|
|
|
|
|
</form>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|