|
|
@ -7,7 +7,7 @@ import { IObservableValue, observable } from 'mobx';
|
|
|
|
import { PostJson, RequestStatus } from '../../../Common/Request';
|
|
|
|
import { PostJson, RequestStatus } from '../../../Common/Request';
|
|
|
|
import { SignUrl, ResourcesCDN_HOST } from '../../../Common/HostUrl';
|
|
|
|
import { SignUrl, ResourcesCDN_HOST } from '../../../Common/HostUrl';
|
|
|
|
import { AppToaster } from '../Toaster';
|
|
|
|
import { AppToaster } from '../Toaster';
|
|
|
|
import { addCookie, editCookie, getCookieValue } from '../../../Common/Utils';
|
|
|
|
import { safeEval } from '../../../Common/eval';
|
|
|
|
|
|
|
|
|
|
|
|
interface IRegistInput
|
|
|
|
interface IRegistInput
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -32,7 +32,8 @@ enum InputType
|
|
|
|
PHONE = 2,
|
|
|
|
PHONE = 2,
|
|
|
|
OK = 3,
|
|
|
|
OK = 3,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const prefix = "time_";
|
|
|
|
|
|
|
|
let SMSTimer: NodeJS.Timeout;
|
|
|
|
@inject("store")
|
|
|
|
@inject("store")
|
|
|
|
@observer
|
|
|
|
@observer
|
|
|
|
export default class Regist extends React.Component<{ store?: TopPanelStore }> {
|
|
|
|
export default class Regist extends React.Component<{ store?: TopPanelStore }> {
|
|
|
@ -64,15 +65,6 @@ export default class Regist extends React.Component<{ store?: TopPanelStore }> {
|
|
|
|
PHONE: Intent.NONE,
|
|
|
|
PHONE: Intent.NONE,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UNSAFE_componentWillMount()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
const countdown = getCookieValue('secondsremained') ? getCookieValue('secondsremained') : 0; // 获取cookie值
|
|
|
|
|
|
|
|
if (countdown !== undefined && countdown > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
this.SMSBtnText = `${countdown}s后重新获取`;
|
|
|
|
|
|
|
|
this.settime(); // 开始倒计时
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
handleRegist = async () =>
|
|
|
|
handleRegist = async () =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (this.inputIntent.PSW !== Intent.SUCCESS)
|
|
|
|
if (this.inputIntent.PSW !== Intent.SUCCESS)
|
|
|
@ -152,35 +144,65 @@ export default class Regist extends React.Component<{ store?: TopPanelStore }> {
|
|
|
|
message: "短信已发送,请注意查收",
|
|
|
|
message: "短信已发送,请注意查收",
|
|
|
|
timeout: 1000,
|
|
|
|
timeout: 1000,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
addCookie('secondsremained', 120, 120);
|
|
|
|
//存入LocalStorage
|
|
|
|
const countdown = getCookieValue('secondsremained') ? getCookieValue('secondsremained') : 0; // 获取cookie值
|
|
|
|
localStorage.setItem(prefix + this.registInput.user_phone, new Date().getTime().toString());
|
|
|
|
if (countdown !== undefined && countdown > 0)
|
|
|
|
//开始倒计时
|
|
|
|
{
|
|
|
|
this.SetTime();
|
|
|
|
this.settime(); // 开始倒计时
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
this.SMSBtnText = `获取短信验证码`;
|
|
|
|
this.SMSBtnText = `获取短信验证码`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private settime = () =>
|
|
|
|
private SetTime = (count: number = 120) =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let countdown = 120;
|
|
|
|
if (SMSTimer)
|
|
|
|
// @ts-ignore
|
|
|
|
clearInterval(SMSTimer);
|
|
|
|
countdown = getCookieValue('secondsremained');
|
|
|
|
SMSTimer = setInterval(() =>
|
|
|
|
const timer = setInterval(() =>
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (countdown <= 0)
|
|
|
|
if (count <= 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
clearInterval(timer);
|
|
|
|
clearInterval(SMSTimer);
|
|
|
|
this.SMSBtnText = '获取短信验证码';
|
|
|
|
this.SMSBtnText = '获取短信验证码';
|
|
|
|
} else
|
|
|
|
this.inputIntent.PHONE = Intent.SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.SMSBtnText = `${countdown}s后重新获取`;
|
|
|
|
this.SMSBtnText = `${count}s后重新获取`;
|
|
|
|
countdown--;
|
|
|
|
count--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
editCookie('secondsremained', countdown, countdown + 1);
|
|
|
|
|
|
|
|
}, 1000);
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 检查当前手机号在LocalStorage中是否已有记录. 如有记录,倒计时是否过期
|
|
|
|
|
|
|
|
CheckPhoneNumFromLocalStorage()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
let user_phone = this.registInput.user_phone;
|
|
|
|
|
|
|
|
let aa = localStorage.getItem(prefix + user_phone);
|
|
|
|
|
|
|
|
clearInterval(SMSTimer);
|
|
|
|
|
|
|
|
if (aa)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
let time = safeEval(aa);
|
|
|
|
|
|
|
|
let timeLine = Math.floor((new Date().getTime() - time) / 1000);
|
|
|
|
|
|
|
|
if (timeLine < 120)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//计时未过期的号码
|
|
|
|
|
|
|
|
this.errMsg = "与上次发送间隔不足两分钟";
|
|
|
|
|
|
|
|
this.flag = InputType.PHONE;
|
|
|
|
|
|
|
|
this.SetTime(120 - timeLine);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//计时已过期的号码
|
|
|
|
|
|
|
|
localStorage.removeItem(prefix + user_phone);
|
|
|
|
|
|
|
|
this.SMSBtnText = '获取短信验证码';
|
|
|
|
|
|
|
|
this.inputIntent.PHONE = Intent.SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//LocalStorage无记录的号码
|
|
|
|
|
|
|
|
this.SMSBtnText = '获取短信验证码';
|
|
|
|
|
|
|
|
this.inputIntent.PHONE = Intent.SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
valueTest = async (type: InputType) =>
|
|
|
|
valueTest = async (type: InputType) =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let text = "";
|
|
|
|
let text = "";
|
|
|
@ -238,7 +260,7 @@ export default class Regist extends React.Component<{ store?: TopPanelStore }> {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.flag = InputType.OK;
|
|
|
|
this.flag = InputType.OK;
|
|
|
|
this.errMsg = "";
|
|
|
|
this.errMsg = "";
|
|
|
|
this.inputIntent.PHONE = Intent.SUCCESS;
|
|
|
|
this.CheckPhoneNumFromLocalStorage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|