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