浏览代码

腾讯验证码

wangxin 5 年之前
父节点
当前提交
b72845d650
共有 1 个文件被更改,包括 40 次插入7 次删除
  1. 40 7
      src/view/captcha/captcha.vue

+ 40 - 7
src/view/captcha/captcha.vue

@@ -53,8 +53,24 @@
             }
         },
         mounted() {
+            var container = document.querySelector("body")
+            container.addEventListener('DOMSubtreeModified', function () {
+                const element = document.querySelector('#tcaptcha_transform')
+                const t_verify = document.querySelector('#t_verify')
+                const mask = document.querySelector('.t-mask')
+                if (mask) {
+                    mask.style.display = 'none'
+                }
+                if (t_verify) {
+                    t_verify.style.border = 'none'
+                }
+                if (element) {
+                    element.style.border = 'none'
+                }
+
+            }, false);
             document.querySelector('iframe').onload = function () {
-                document.querySelector('.t-mask').style.display = 'none'
+
             }
 
             this.isAndroid = /(Android)/i.test(navigator.userAgent)
@@ -65,18 +81,35 @@
             this.TencentCaptcha = new window.TencentCaptcha(
                 getAppId(process.env.NODE_ENV),
                 function (res) {/* callback */
-                    if (that.isiOS) {
-                        window.webkit.messageHandlers.returnVerificationCode.postMessage(res.ret.toString());
-                    }
-                    if (that.isAndroid) {
-                        window.hap.verificationCode(res.ret.toString());
-                    }
                     if (res.ret === 0) {
                         postAction(getCaptchaCode, {
                             ticket: res.ticket,
                             randstr: res.randstr,
                             phone: that.phone
+                        }).then(() => {
+                            that.$toast.fail({message: '验证码获取成功'})
+                            if (that.isiOS) {
+                                window.webkit.messageHandlers.returnVerificationCode.postMessage(res.ret.toString());
+                            }
+                            if (that.isAndroid) {
+                                window.hap.verificationCode(res.ret.toString());
+                            }
+                        }).catch(data => {
+                            that.$toast.fail({icon: 'close', message: data.errmsg})
+                            if (that.isiOS) {
+                                window.webkit.messageHandlers.returnVerificationCode.postMessage(res.ret.toString());
+                            }
+                            if (that.isAndroid) {
+                                window.hap.verificationCode(res.ret.toString());
+                            }
                         })
+                    } else {
+                        if (that.isiOS) {
+                            window.webkit.messageHandlers.returnVerificationCode.postMessage(res.ret.toString());
+                        }
+                        if (that.isAndroid) {
+                            window.hap.verificationCode(res.ret.toString());
+                        }
                     }
                 },
                 {