ProFormCaptcha獲取驗證碼之前進行圖形驗證碼校驗


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM