/* * Author: 黎永顺 * name: 验证码弹框 * Description: * Date: 2023/6/16 */ import React, { Component } from "react"; import { WeaDialog, WeaError, WeaFormItem, WeaInput, WeaLocaleProvider, WeaSearchGroup } from "ecCom"; import { sendMobileCode } from "../../apis/payroll"; import { Button } from "antd"; import "./index.less"; const { getLabel } = WeaLocaleProvider; class Index extends Component { constructor(props) { super(props); this.state = { captcha: "", time: 60 }; this.timeRef = null; } componentWillUnmount() { clearInterval(this.timeRef); } componentWillReceiveProps(nextProps, nextContext) { if (nextProps.visible !== this.props.visible && !nextProps.visible) { this.setState({ captcha: "" }); } else { clearInterval(this.timeRef); this.setState({ time: 60 }); } } handleSendCaptcha = () => { sendMobileCode({ id: this.props.id }).then(({}) => { this.timeRef = setInterval(() => { const { time } = this.state; this.setState({ time: time - 1 }, () => { if (this.state.time === -1) { clearInterval(this.timeRef); this.setState({ time: 60 }); } }); }, 1000); }); }; render() { const { captcha, time } = this.state; return ( {getLabel(826, "确定")} ]} >
this.setState({ captcha })}/>
); } } export default Index;