<ProFormCaptcha
label="验证码"
placeholder={intl.formatMessage({
id: 'pages.login.captcha.placeholder',
defaultMessage: '请输入验证码',
})}
captchaTextRender={(timing, count) => {
if (timing) {
return `${count} ${intl.formatMessage({
id: 'pages.getCaptchaSecondText',
defaultMessage: '获取验证码',
})}`;
}
return intl.formatMessage({
id: 'pages.login.phoneLogin.getVerificationCode',
defaultMessage: '获取验证码',
});
}}
phoneName="phone"
name="code"
rules={[
{
required: true,
message: (
<FormattedMessage
id="pages.login.captcha.required"
defaultMessage="请输入验证码"
/>
),
},
]}
onGetCaptcha={onGetCaptcha}
/>
- 下边是
onGetCaptcha
const onGetCaptcha = async (phone) => {
await waitTime();
}
const waitTime = () => {
return new Promise((resolve) => {
dispatch({
type: "openModal",
payload: {
modalVisible: true
}
})
window.resolve = resolve;
});
};
这里有个关键的地方,把promise的resolve挂载到window上 然后弹窗操作完 再调用 window.resolve
window.resolve && window.resolve();
window.resolve = null;