|
|
@ -34,7 +34,7 @@ export default function LoginForm({ className }: { className?: string }) {
|
|
|
|
const [time, setTime] = useState<number>(0); // 倒计时
|
|
|
|
const [time, setTime] = useState<number>(0); // 倒计时
|
|
|
|
const [btnLoading, setBtnLoading] = useState<boolean>(false);
|
|
|
|
const [btnLoading, setBtnLoading] = useState<boolean>(false);
|
|
|
|
const activeSMS = useMemo(() => phone.length !== 11 || !!time, [phone, time]);
|
|
|
|
const activeSMS = useMemo(() => phone.length !== 11 || !!time, [phone, time]);
|
|
|
|
const activeLogin = useMemo(() => !(phone.length === 11 && authCode.length === 6), [phone, authCode]); // 是否激活发送短信按钮
|
|
|
|
const disLogin = useMemo(() => !(phone.length === 11 && authCode.length === 6), [phone, authCode]); // 是否激活发送短信按钮
|
|
|
|
|
|
|
|
|
|
|
|
const handleSendSMS = async () => {
|
|
|
|
const handleSendSMS = async () => {
|
|
|
|
setBtnLoading(true);
|
|
|
|
setBtnLoading(true);
|
|
|
@ -70,6 +70,7 @@ export default function LoginForm({ className }: { className?: string }) {
|
|
|
|
|
|
|
|
|
|
|
|
// 登录
|
|
|
|
// 登录
|
|
|
|
const handleLogin = async () => {
|
|
|
|
const handleLogin = async () => {
|
|
|
|
|
|
|
|
if (disLogin) return;
|
|
|
|
setBtnLoading(true);
|
|
|
|
setBtnLoading(true);
|
|
|
|
const uuid = localStorage.getItem('deviceId') || 'error';
|
|
|
|
const uuid = localStorage.getItem('deviceId') || 'error';
|
|
|
|
const result = await SmsLogin({ phone, authCode: authCode, deviceId: uuid });
|
|
|
|
const result = await SmsLogin({ phone, authCode: authCode, deviceId: uuid });
|
|
|
@ -106,11 +107,24 @@ export default function LoginForm({ className }: { className?: string }) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [time]);
|
|
|
|
}, [time]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
const handleListenKeyboard = (e: KeyboardEvent) => {
|
|
|
|
|
|
|
|
if (e.key === 'Enter' || e.keyCode === 13) {
|
|
|
|
|
|
|
|
handleLogin();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
document.addEventListener('keydown', handleListenKeyboard);
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
|
|
|
document.removeEventListener('keydown', handleListenKeyboard);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div className={className}>
|
|
|
|
<div className={className}>
|
|
|
|
<div className={`w-full flex flex-col`}>
|
|
|
|
<div className={`w-full flex flex-col`}>
|
|
|
|
<input
|
|
|
|
<input
|
|
|
|
className="w-full h-[56px] rounded-[100px] !placeholder-[rgba(0,0,0,0.4)] !placeholder-text-14px px-[24px] text-[rgba(0,0,0,0.95)] bg-#fff leading-[20px]"
|
|
|
|
className="w-full h-56px rounded-100px !placeholder-[rgba(0,0,0,0.4)] !placeholder-text-14px px-24px text-[rgba(0,0,0,0.95)] bg-#fff leading-20px border-1px border-#fff focus:border-#000/70 transition-all-100"
|
|
|
|
type="text"
|
|
|
|
type="text"
|
|
|
|
value={phone}
|
|
|
|
value={phone}
|
|
|
|
maxLength={11}
|
|
|
|
maxLength={11}
|
|
|
@ -120,7 +134,7 @@ export default function LoginForm({ className }: { className?: string }) {
|
|
|
|
|
|
|
|
|
|
|
|
<div className="relative w-full mt-[20px]">
|
|
|
|
<div className="relative w-full mt-[20px]">
|
|
|
|
<input
|
|
|
|
<input
|
|
|
|
className="w-full h-[56px] rounded-[100px] px-[24px] !placeholder-[rgba(0,0,0,0.4)] !placeholder-text-14px text-[rgba(0,0,0,0.95)] bg-#fff leading-[20px]"
|
|
|
|
className="w-full h-56px rounded-100px px-24px !placeholder-[rgba(0,0,0,0.4)] !placeholder-text-14px text-[rgba(0,0,0,0.95)] bg-#fff leading-20px border-1px border-1px border-#fff focus:border-#000/70 transition-all-100"
|
|
|
|
type="text"
|
|
|
|
type="text"
|
|
|
|
value={authCode}
|
|
|
|
value={authCode}
|
|
|
|
maxLength={6}
|
|
|
|
maxLength={6}
|
|
|
@ -130,7 +144,7 @@ export default function LoginForm({ className }: { className?: string }) {
|
|
|
|
|
|
|
|
|
|
|
|
<Button
|
|
|
|
<Button
|
|
|
|
type="white"
|
|
|
|
type="white"
|
|
|
|
className={`absolute top-[6px] right-[24px] w-fit h-[44px] rounded-[100px] font-size-[14px] text-right leading-[20px]`}
|
|
|
|
className={`absolute top-6px right-24px w-fit h-44px rounded-100px font-size-14px text-right leading-20px`}
|
|
|
|
disabled={btnLoading || activeSMS}
|
|
|
|
disabled={btnLoading || activeSMS}
|
|
|
|
onClick={debounce(handleSendSMS, 300)}
|
|
|
|
onClick={debounce(handleSendSMS, 300)}
|
|
|
|
>
|
|
|
|
>
|
|
|
@ -145,14 +159,14 @@ export default function LoginForm({ className }: { className?: string }) {
|
|
|
|
|
|
|
|
|
|
|
|
<Button
|
|
|
|
<Button
|
|
|
|
type="primary"
|
|
|
|
type="primary"
|
|
|
|
className="w-full h-[56px] mt-[30px] rounded-[100px] font-size-[14px] leading-[20px]"
|
|
|
|
className="w-full h-56px mt-30px rounded-100px font-size-14px leading-20px"
|
|
|
|
disabled={activeLogin}
|
|
|
|
disabled={disLogin}
|
|
|
|
onClick={debounce(handleLogin, 300)}
|
|
|
|
onClick={debounce(handleLogin, 300)}
|
|
|
|
>
|
|
|
|
>
|
|
|
|
确定登录
|
|
|
|
确定登录
|
|
|
|
</Button>
|
|
|
|
</Button>
|
|
|
|
|
|
|
|
|
|
|
|
<p className="mt-[16px] text-center text-brand text-[13px] leading-[18px]">{errorText}</p>
|
|
|
|
<p className="mt-16px text-center text-brand text-13px leading-18px">{errorText}</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|