123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- 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
- }
- }
|