var SMSRequest = { getCaptcha: function(phone, mold, callback) { $.ajax({ type: 'POST', url: '/publicapply/captcha/get', data: { phone: phone, mold: mold }, success: function (res) { if (res.error_code === 0 && res.data) { callback && callback(res.data) } else { if (res.error_msg) { showToast(res.error_msg) } } } }) }, verifyCaptcha: function(data, callback) { $.ajax({ type: 'POST', url: '/publicapply/captcha/check', data: data, success: function (res) { callback && callback(res) } }) } } var slideVerify = { el: null, $dialog: null, capt: null, phone: '', captKey: '', init: function() { if (!this.capt) { this.$dialog = $('#pc-slide-verify-dialog') this.initSlideVerify() } this.modalShow(true) }, initModalZIndex: function() { // 修复首页多层弹窗层级问题 if (!this.$dialog) return var modalInstance = this.$dialog.data('bs.modal') modalInstance.$backdrop.addClass('top-of-login') }, initSlideVerify: function() { var el = document.getElementById('slide-wrap'); var capt = new GoCaptcha.Slide({ width: 300, height: 220, }) capt.mount(el) this.el = el this.capt = capt this.bindCaptEvents() }, modalShow: function(f) { if (!this.$dialog) return if (f) { this.$dialog.modal('show') this.initModalZIndex() } else { this.$dialog.modal('hide') } }, bindCaptEvents: function() { if (!this.capt) return var _this = this this.capt.setEvents({ close: function() { _this.modalShow(false) }, confirm: function(point, reset) { const payload = { phone: _this.phone, key: _this.captKey, point: [point.x, point.y].join(',') } SMSRequest.verifyCaptcha(payload, function(res) { if (res.error_code === 0 && res.data) { const pass = res.data && res.data.code === 0 if (pass) { try { startSendSMSCodeTimer(_this.mold) } catch (error) { console.log(error) } _this.modalShow(false) reset() } else { reset() _this.capt.refresh() } } else { reset() _this.capt.refresh() } }) }, refresh: function() { SMSRequest.getCaptcha(_this.phone, _this.mold, function(data) { if (data && data.code === 1) { _this.refreshCaptData(data) } }) }, }) }, cachePhone: function(phone) { this.phone = phone }, cacheMold: function(mold) { this.mold = mold }, cacheCaptKey: function(k) { this.captKey = k }, refreshCaptData: function(x) { if (!this.capt) return const captKey = x.captcha_key || '' this.cacheCaptKey(captKey) this.capt.setData({ image: x.image_base64 || '', thumb: x.tile_base64 || '', captKey: captKey, thumbX: x.tile_x || 0, thumbY: x.tile_y || 0, thumbWidth: x.tile_width || 0, thumbHeight: x.tile_height || 0 }) } } function initGoCaptchaVerify(phone, mold) { SMSRequest.getCaptcha(phone, mold, function(data) { if (data && data.code === 1) { slideVerify.init() slideVerify.cachePhone(phone) slideVerify.cacheMold(mold) slideVerify.refreshCaptData(data) } }) } function getCaptchaInfo() { return { phone: slideVerify.phone, captKey: slideVerify.captKey } }