Reduce CountDownInput args.

This commit is contained in:
Gucheng Wang
2021-11-28 20:57:14 +08:00
parent 36b7993994
commit d224e728a3
6 changed files with 20 additions and 53 deletions

View File

@ -22,35 +22,29 @@ import {SafetyOutlined} from "@ant-design/icons";
const { Search } = Input;
export const CountDownInput = (props) => {
const {defaultButtonText, disabled, textBefore, placeHolder, onChange, coolDownTime, onButtonClick, onButtonClickArgs} = props;
const [buttonText, setButtonText] = React.useState(defaultButtonText);
const {disabled, textBefore, onChange, onButtonClickArgs} = props;
const [visible, setVisible] = React.useState(false);
const [key, setKey] = React.useState("");
const [captchaImg, setCaptchaImg] = React.useState("");
const [checkType, setCheckType] = React.useState("");
// const [coolDown, setCoolDown] = React.useState(false);
const [checkId, setCheckId] = React.useState("");
const [buttonDisabled, setButtonDisabled] = React.useState(false);
const countDown = (leftTime) => {
if (leftTime === 0) {
setButtonDisabled(false);
// setCoolDown(false);
setButtonText(defaultButtonText);
return;
}
setButtonText(`${leftTime} s`);
setTimeout(() => countDown(leftTime - 1), 1000);
}
const handleOk = () => {
setVisible(false);
onButtonClick(checkType, checkId, key, ...onButtonClickArgs).then(res => {
UserBackend.sendCode(checkType, checkId, key, ...onButtonClickArgs).then(res => {
setKey("");
if (res) {
// setCoolDown(true);
setButtonDisabled(true)
countDown(coolDownTime);
countDown(60);
}
})
}
@ -63,7 +57,7 @@ export const CountDownInput = (props) => {
const loadHumanCheck = () => {
UserBackend.getHumanCheck().then(res => {
if (res.type === "none") {
onButtonClick("none", "", "", ...onButtonClickArgs);
UserBackend.sendCode("none", "", "", ...onButtonClickArgs);
} else if (res.type === "captcha") {
setCheckId(res.captchaId);
setCaptchaImg(res.captchaImage);
@ -107,12 +101,12 @@ export const CountDownInput = (props) => {
addonBefore={textBefore}
disabled={disabled}
prefix={<SafetyOutlined />}
placeholder={placeHolder}
placeholder={i18next.t("code:Enter your code")}
onChange={e => onChange(e.target.value)}
enterButton={
<Button type={"primary"} disabled={disabled || buttonDisabled}>
<div style={{fontSize: 14}}>
{buttonText}
{i18next.t("code:Send Code")}
</div>
</Button>
}