robot-check.page.js 1.05 KB
var $ = require('yoho-jquery'),
    Captcha = require('../plugins/captcha'),
    qs = require('yoho-qs');

var options = {
        checkURI: '/3party/check',
        initURI: '/3party/captcha.png',
        page: 'robot'
    },
    baseInfo = {},
    captcha;

// 接口风控图形验证码链接
if (window._captchaApiRisk) {
    options.refreshURI = '/passport/images-risk.png';
    baseInfo.apiRiskValidate = true;
}

captcha = new Captcha('.captcha-wrap', options).init();

// _captchaApiRisk
require('../common');
require('../common/promise');

// 定时监测cookie中refresh_page刷新页面也换验证方式
setInterval(function() {
    if (window.cookie('refresh_page') > 0) {
        window.setCookie('refresh_page', 0, {
            path: '/'
        });
        window.location.reload();
    }
}, 1000);

$('.confirm').on('click', function() {
    captcha.check(baseInfo).then(function() {
        window.jumpUrl(qs.refer ? decodeURIComponent(qs.refer) : '//www.yohobuy.com');
    });
});

captcha.onSuccess(function() {
    $('.confirm').trigger('click');
});