Explorar o código

处理验证码问题

wangcz %!s(int64=7) %!d(string=hai) anos
pai
achega
b743b9a2b4

+ 27 - 1
components/mobile/registerEnterprise/index.vue

@@ -13,6 +13,11 @@
                     type="tel"
           ></mt-field>
         </div>
+        <div class="page-part">
+          <mt-field placeholder="验证码" v-model="code">
+            <img :src="imgSrc" height="45px" width="100px" @click="getCode">
+          </mt-field>
+        </div>
         <div class="page-part">
           <mt-field auto-complete="off"
                     placeholder="短信验证码"
@@ -99,6 +104,8 @@
     name: 'registerEnterprise',
     data () {
       return {
+        code: '',
+        imgSrc: '',
         step: 1,
         state: {
           mobile: 'error',
@@ -131,6 +138,11 @@
         progress: '弱'
       }
     },
+    mounted () {
+      this.$nextTick(() => {
+        this.getCode()
+      })
+    },
     watch: {
       'step1.token': {
         handler (newVal) {
@@ -142,6 +154,9 @@
       }
     },
     methods: {
+      getCode () {
+        this.imgSrc = '/sso/resetPwd/checkCaptcha?timestamp=' + (new Date()).valueOf()
+      },
       // 注册
       goRegister () {
         window.location.href = `/register/personalRegistration${this.$store.state.option.fullPath}`
@@ -210,14 +225,25 @@
       getCheckCode () {
         if (this.tokenTime > 0 && this.tokenTime < 60) {
           this.downToast('请稍后再点击,我在倒计时')
+        } else if (this.code === '') {
+          this.downToast('请输入验证码后获取!')
         } else {
           this.validateMobile()
           if (this.state.mobile === 'success') {
             this.$indicator.open('获取中...')
             let _this = this
-            this.$http.get('/sso/personal/register/checkCode', {params: {mobile: this.step1.mobile, timestamp: new Date().getTime() + ''}})
+            this.$http.get('/sso/personal/register/checkCode', {params: {mobile: this.step1.mobile, timestamp: new Date().getTime() + '', code: this.code}})
               .then(response => {
                 this.$indicator.close()
+                if (response.data.errMsg) {
+                  this.$toast({
+                    message: response.data.errMsg,
+                    iconClass: 'el-icon-error'
+                  })
+                  this.code = ''
+                  this.getCode()
+                  return
+                }
                 if (response.data) {
                   this.tokenCode = response.data.token
                   this.$toast({

+ 32 - 4
components/mobile/registerPersonal/index.vue

@@ -35,6 +35,11 @@
                   v-model="mobile"
                   type="tel"></mt-field>
       </div>
+      <div class="page-part">
+        <mt-field placeholder="验证码" v-model="code">
+          <img :src="imgSrc" height="45px" width="100px" @click="getCode">
+        </mt-field>
+      </div>
       <div class="page-part">
         <mt-field :state="state.token"
                   placeholder="短信验证码"
@@ -58,13 +63,16 @@
     name: 'registerPerson',
     data () {
       return {
+        imgSrc: '',
+        code: '',
         step: 1,
         state: {
           vipName: 'error',
           password: 'error',
           confirm: 'error',
           mobile: 'error',
-          token: 'error'
+          token: 'error',
+          code: 'error'
         },
         vipName: '',
         password: '',
@@ -77,6 +85,11 @@
         checked: true
       }
     },
+    mounted () {
+      this.$nextTick(() => {
+        this.getCode()
+      })
+    },
     watch: {
       'token': {
         handler (newVal) {
@@ -88,6 +101,9 @@
       }
     },
     methods: {
+      getCode () {
+        this.imgSrc = '/sso/resetPwd/checkCaptcha?timestamp=' + (new Date()).valueOf()
+      },
       // 注册
       goRegister () {
         window.location.href = `/register/enterpriseRegistration${this.$store.state.option.fullPath}`
@@ -215,13 +231,25 @@
       },
       // 获取验证码
       loadCheckCode () {
-        this.codeMobile()
-        if (this.state.mobile === 'success') {
+        if (this.state.mobile !== 'success') {
+          this.codeMobile()
+        } else if (this.code === '') {
+          this.downToast('请输入验证码后获取!')
+        } else {
           this.$indicator.open('获取中...')
           let _this = this
-          this.$http.get('/sso/personal/register/checkCode', {params: {mobile: this.mobile, timestamp: new Date().getTime() + ''}})
+          this.$http.get('/sso/personal/register/checkCode', {params: {code: this.code, mobile: this.mobile, timestamp: new Date().getTime() + ''}})
             .then(response => {
               this.$indicator.close()
+              if (response.data.errMsg) {
+                this.$toast({
+                  message: response.data.errMsg,
+                  iconClass: 'el-icon-error'
+                })
+                this.code = ''
+                this.getCode()
+                return
+              }
               if (response.data) {
                 this.tokenCode = response.data.token
                 this.$toast({