<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;