Authored by targaryen

geetest-downgrade

@@ -202,3 +202,17 @@ $('.tp-link a').on('touchstart', function() { @@ -202,3 +202,17 @@ $('.tp-link a').on('touchstart', function() {
202 }, true); 202 }, true);
203 } 203 }
204 }); 204 });
  205 +
  206 +/**
  207 + * 极验证不行,重新初始化为自有图片验证
  208 + */
  209 +$('#js-img-check').on('change', function() {
  210 + validate = new Validate($captcha, {
  211 + useREM: {
  212 + rootFontSize: 40,
  213 + picWidth: 150
  214 + }
  215 + }, 1);
  216 +
  217 + validate.init();
  218 +});
@@ -19,10 +19,14 @@ const validType = { @@ -19,10 +19,14 @@ const validType = {
19 })(); 19 })();
20 20
21 class Validate { 21 class Validate {
22 - constructor(container, options) { 22 + constructor(container, options, type) {
23 this.$container = container instanceof $ ? container : $(container); 23 this.$container = container instanceof $ ? container : $(container);
24 this.options = options; 24 this.options = options;
25 - this.type = this.$container.data('geetest') ? validType.GEETEST : validType.IMG_CHECK; 25 + if (type) {
  26 + this.type = type;
  27 + } else {
  28 + this.type = this.$container.data('geetest') ? validType.GEETEST : validType.IMG_CHECK;
  29 + }
26 this.$container.after('<input id="yohobuy" type="text" style="display:none;">'); 30 this.$container.after('<input id="yohobuy" type="text" style="display:none;">');
27 if (this.type === validType.IMG_CHECK) { 31 if (this.type === validType.IMG_CHECK) {
28 this.imgCheck = new ImgCheck(this.$container, this.options); 32 this.imgCheck = new ImgCheck(this.$container, this.options);
@@ -32,16 +36,20 @@ class Validate { @@ -32,16 +36,20 @@ class Validate {
32 type: 'get', 36 type: 'get',
33 dataType: 'json', 37 dataType: 'json',
34 success: data => { 38 success: data => {
35 - window.initGeetest && window.initGeetest({  
36 - gt: data.gt,  
37 - challenge: data.challenge,  
38 - offline: !data.success  
39 - }, (captchaObj) => {  
40 - this.captchaObj = captchaObj;  
41 - captchaObj.appendTo(this.$container);  
42 - this._atWorking = true;  
43 - this.$container.addClass('hide').addClass('popup');  
44 - }); 39 + if (data.success) {
  40 + window.initGeetest && window.initGeetest({
  41 + gt: data.gt,
  42 + challenge: data.challenge,
  43 + offline: !data.success
  44 + }, (captchaObj) => {
  45 + this.captchaObj = captchaObj;
  46 + captchaObj.appendTo(this.$container);
  47 + this._atWorking = true;
  48 + this.$container.addClass('hide').addClass('popup');
  49 + });
  50 + } else {
  51 + this.$container.trigger('change');
  52 + }
45 } 53 }
46 }); 54 });
47 $('.yoho-page').on('touchstart', '#js-img-check', (e) => { 55 $('.yoho-page').on('touchstart', '#js-img-check', (e) => {