diff --git a/web/src/component/CountDownInput.js b/web/src/component/CountDownInput.js index ade81940..943e0cc8 100644 --- a/web/src/component/CountDownInput.js +++ b/web/src/component/CountDownInput.js @@ -30,14 +30,21 @@ export const CountDownInput = (props) => { const [captchaImg, setCaptchaImg] = React.useState(""); const [checkType, setCheckType] = React.useState(""); const [checkId, setCheckId] = React.useState(""); - const [buttonDisabled, setButtonDisabled] = React.useState(false); + const [buttonLeftTime, setButtonLeftTime] = React.useState(0); + const [buttonLoading, setButtonLoading] = React.useState(false); - const countDown = (leftTime) => { - if (leftTime === 0) { - setButtonDisabled(false); - return; + const handleCountDown = (leftTime = 60) => { + let leftTimeSecond = leftTime + setButtonLeftTime(leftTimeSecond) + const countDown = () => { + leftTimeSecond--; + setButtonLeftTime(leftTimeSecond) + if (leftTimeSecond === 0) { + return; + } + setTimeout(countDown, 1000); } - setTimeout(() => countDown(leftTime - 1), 1000); + setTimeout(countDown, 1000); } const handleOk = () => { @@ -50,11 +57,12 @@ export const CountDownInput = (props) => { Util.showMessage("error", i18next.t("login:Invalid Email or phone")) return; } + setButtonLoading(true) UserBackend.sendCode(checkType, checkId, key, ...onButtonClickArgs).then(res => { setKey(""); + setButtonLoading(false) if (res) { - setButtonDisabled(true) - countDown(60); + handleCountDown(60); } }) } @@ -81,22 +89,23 @@ export const CountDownInput = (props) => { const renderCaptcha = () => { return ( - - - - } placeholder={i18next.t("general:Captcha")} onPressEnter={handleOk} onChange={e => setKey(e.target.value)} /> - - + + + + } placeholder={i18next.t("general:Captcha")} + onPressEnter={handleOk} onChange={e => setKey(e.target.value)}/> + + ) } @@ -106,39 +115,38 @@ export const CountDownInput = (props) => { } return ( - - } - placeholder={i18next.t("code:Enter your code")} - onChange={e => onChange(e.target.value)} - enterButton={ - - } - onSearch={loadHumanCheck} - /> - - { - renderCheck() - } - - + + } + placeholder={i18next.t("code:Enter your code")} + onChange={e => onChange(e.target.value)} + enterButton={ + + } + onSearch={loadHumanCheck} + /> + + { + renderCheck() + } + + ); } diff --git a/web/src/locales/en/data.json b/web/src/locales/en/data.json index 142689d0..1cd4a19a 100644 --- a/web/src/locales/en/data.json +++ b/web/src/locales/en/data.json @@ -40,7 +40,8 @@ "Please input your phone verification code!": "Please input your phone verification code!", "Please input your verification code!": "Please input your verification code!", "Send Code": "Send Code", - "Submit and complete": "Submit and complete" + "Submit and complete": "Submit and complete", + "Sending Code": "Sending" }, "forget": { "Account": "Account", diff --git a/web/src/locales/zh/data.json b/web/src/locales/zh/data.json index c3407613..0560ce19 100644 --- a/web/src/locales/zh/data.json +++ b/web/src/locales/zh/data.json @@ -40,7 +40,8 @@ "Please input your phone verification code!": "请输入您的手机验证码!", "Please input your verification code!": "请输入您的验证码!", "Send Code": "发送验证码", - "Submit and complete": "完成提交" + "Submit and complete": "完成提交", + "Sending Code": "发送中" }, "forget": { "Account": "账号",