2023-06-16 11:12:20 +08:00
|
|
|
/*
|
|
|
|
|
* Author: 黎永顺
|
|
|
|
|
* name: 验证码弹框
|
|
|
|
|
* Description:
|
|
|
|
|
* Date: 2023/6/16
|
|
|
|
|
*/
|
|
|
|
|
import React, { Component } from "react";
|
|
|
|
|
import { WeaDialog, WeaError, WeaFormItem, WeaInput, WeaLocaleProvider, WeaSearchGroup } from "ecCom";
|
2025-04-25 13:38:43 +08:00
|
|
|
import { WeaForm, WeaSwitch } from "comsMobx";
|
|
|
|
|
import { checkMobileCode, sendMobileCode } from "../../apis/payroll";
|
|
|
|
|
import { getQueryString } from "../../util/url";
|
|
|
|
|
import FormInfo from "../FormInfo";
|
|
|
|
|
import { captchaCondition } from "../../pages/mobilePayroll/pwdCondtion";
|
|
|
|
|
import MobileModal from "../../pages/mobilePayroll/mobileModal";
|
|
|
|
|
import { Button, message } from "antd";
|
2023-06-16 11:12:20 +08:00
|
|
|
import "./index.less";
|
|
|
|
|
|
2025-04-25 13:38:43 +08:00
|
|
|
const form = new WeaForm();
|
2023-06-16 11:12:20 +08:00
|
|
|
const { getLabel } = WeaLocaleProvider;
|
|
|
|
|
|
|
|
|
|
class Index extends Component {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
2025-12-18 14:15:03 +08:00
|
|
|
this.state = { captcha: "", time: 60, loading: false };
|
2023-06-16 11:12:20 +08:00
|
|
|
this.timeRef = null;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-25 13:38:43 +08:00
|
|
|
componentDidMount() {
|
|
|
|
|
form.initFormFields(captchaCondition);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-16 11:12:20 +08:00
|
|
|
componentWillUnmount() {
|
|
|
|
|
clearInterval(this.timeRef);
|
2025-12-18 14:15:03 +08:00
|
|
|
this.setState({ captcha: "", time: 60, loading: false });
|
2023-06-16 11:12:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleSendCaptcha = () => {
|
2025-12-18 14:15:03 +08:00
|
|
|
this.setState({ loading: true });
|
2023-06-16 16:34:03 +08:00
|
|
|
sendMobileCode({ id: this.props.id }).then(({ status, data }) => {
|
|
|
|
|
if (status) {
|
|
|
|
|
this.timeRef = setInterval(() => {
|
|
|
|
|
const { time } = this.state;
|
|
|
|
|
this.setState({ time: time - 1 }, () => {
|
|
|
|
|
if (this.state.time === -1) {
|
|
|
|
|
clearInterval(this.timeRef);
|
2025-12-18 14:15:03 +08:00
|
|
|
this.setState({ time: 60, loading: false });
|
2023-06-16 16:34:03 +08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}, 1000);
|
2025-12-18 14:15:03 +08:00
|
|
|
} else {
|
|
|
|
|
this.setState({ loading: false });
|
2023-06-16 16:34:03 +08:00
|
|
|
}
|
2025-12-18 14:15:03 +08:00
|
|
|
}).catch(() => this.setState({ loading: false }));
|
2023-06-16 11:12:20 +08:00
|
|
|
};
|
2025-04-25 13:38:43 +08:00
|
|
|
handleConfirm = async () => {
|
|
|
|
|
const type = getQueryString("type"), f = await form.validateForm();
|
|
|
|
|
if (!this.state.captcha && type !== "phone") {
|
2023-06-16 16:34:03 +08:00
|
|
|
this.refs.weaError.showError();
|
2025-04-25 13:38:43 +08:00
|
|
|
return;
|
|
|
|
|
} else if (!f.isValid && type === "phone") {
|
|
|
|
|
f.showErrors();
|
|
|
|
|
return;
|
2023-06-16 16:34:03 +08:00
|
|
|
}
|
2025-04-25 13:38:43 +08:00
|
|
|
checkMobileCode({ id: this.props.id, mobileCode: this.state.captcha }).then(({ status, errormsg }) => {
|
|
|
|
|
if (status) {
|
|
|
|
|
this.props.onCancel();
|
|
|
|
|
this.props.onConfirm();
|
|
|
|
|
} else {
|
|
|
|
|
message.error(errormsg);
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-06-16 16:34:03 +08:00
|
|
|
};
|
2023-06-16 11:12:20 +08:00
|
|
|
|
|
|
|
|
render() {
|
2025-12-18 14:15:03 +08:00
|
|
|
const { captcha, time, loading } = this.state, type = getQueryString("type");
|
2025-04-25 13:38:43 +08:00
|
|
|
const itemRender = {
|
|
|
|
|
mobileCode: (field, textAreaProps, form, formParams) => {
|
|
|
|
|
return (<div className="captchaInputBox">
|
|
|
|
|
<WeaSwitch fieldConfig={{ ...field, ...textAreaProps }} form={form} formParams={formParams}
|
|
|
|
|
onChange={() => this.setState({ captcha: form.getFormParams().mobileCode })}/>
|
2025-12-18 14:15:03 +08:00
|
|
|
<Button type="primary" onClick={this.handleSendCaptcha} disabled={loading}>
|
2025-04-25 13:38:43 +08:00
|
|
|
{
|
|
|
|
|
time === 60 ? getLabel(111, "发送验证码") : `${time}S`
|
|
|
|
|
}
|
|
|
|
|
</Button>
|
|
|
|
|
</div>);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
return (<React.Fragment>
|
|
|
|
|
{
|
|
|
|
|
type === "phone" ? <MobileModal title={getLabel(111, "验证码验证")} onConfirm={this.handleConfirm}>
|
|
|
|
|
<FormInfo center={false} itemRender={itemRender} form={form} formFields={captchaCondition}/>
|
|
|
|
|
</MobileModal> :
|
|
|
|
|
<WeaDialog
|
|
|
|
|
initLoadCss {...this.props} style={{ width: 550 }}
|
|
|
|
|
className="captchaWrapper" title={getLabel(111, "验证码验证")}
|
|
|
|
|
buttons={[
|
|
|
|
|
<Button type="primary" onClick={this.handleConfirm}>{getLabel(826, "确定")}</Button>
|
|
|
|
|
]}
|
|
|
|
|
>
|
|
|
|
|
<WeaSearchGroup needTigger={false} title="" showGroup>
|
|
|
|
|
<WeaFormItem
|
|
|
|
|
label={getLabel(111, "验证码")}
|
|
|
|
|
labelCol={{ span: 8 }}
|
|
|
|
|
wrapperCol={{ span: 16 }}
|
|
|
|
|
>
|
|
|
|
|
<WeaError tipPosition="bottom" ref="weaError" error={getLabel(111, "验证码未填写")}>
|
|
|
|
|
<div className="captchaInputBox">
|
|
|
|
|
<WeaInput value={captcha} onChange={captcha => this.setState({ captcha })}/>
|
2025-12-18 14:15:03 +08:00
|
|
|
<Button type="primary" onClick={this.handleSendCaptcha} disabled={loading}>
|
2025-04-25 13:38:43 +08:00
|
|
|
{
|
|
|
|
|
time === 60 ? getLabel(111, "发送验证码") : `${time}S`
|
|
|
|
|
}
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</WeaError>
|
|
|
|
|
</WeaFormItem>
|
|
|
|
|
</WeaSearchGroup>
|
|
|
|
|
</WeaDialog>
|
|
|
|
|
}
|
|
|
|
|
</React.Fragment>
|
2023-06-16 11:12:20 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-18 14:15:03 +08:00
|
|
|
export default Index;
|