Browse Source

feat(registerBar.vue):注册时点击验证码也判断用户输入是否有效

liyangbin 2 years ago
parent
commit
f25fee14fa
1 changed files with 29 additions and 19 deletions
  1. 29 19
      components/RegisterBar.vue

+ 29 - 19
components/RegisterBar.vue

@@ -55,26 +55,36 @@ export default {
     //发送验证码
     handlePostCode() {
       if(this.sending) return
-      const params = {
-        action: '0', // 注册用户
-        receiver: this.form.username
-      }
-      if(this.regPhone.test(this.form.username)) params.type = '1'
-      if(this.regEmail.test(this.form.username)) params.type = '0'
-      this.$axios.get('auth/getVerifyCode', {params}).then((res)=> {
-        if(res.code === 200) {
-          this.sending = true
-          let interval = setInterval(() => {
-            this.clock--
-            if(this.clock === 0) {
-              clearInterval(interval)
-              interval = null
-              this.clock = 60
-              this.sending = false
-            }
-          }, 1000);
+      if(!this.regPhone.test(this.form.username) && !this.regEmail.test(this.form.username)) {
+        this.errMsg = '手机号/邮箱格式不对'
+      }else if(this.form.password !== this.form.passwordConfirm) {
+        this.errMsg = '两次输入的密码不一致'
+      }else if(this.form.password.length < 6) {
+        this.errMsg = '密码位数不能少于6位'
+      }else if(this.form.password.length> 16){
+        this.errMsg = '密码位数不能大于16位'
+      }else{
+        const params = {
+          action: '0', // 注册用户
+          receiver: this.form.username
         }
-      })
+        if(this.regPhone.test(this.form.username)) params.type = '1'
+        if(this.regEmail.test(this.form.username)) params.type = '0'
+        this.$axios.get('auth/getVerifyCode', {params}).then((res)=> {
+          if(res.code === 200) {
+            this.sending = true
+            let interval = setInterval(() => {
+              this.clock--
+              if(this.clock === 0) {
+                clearInterval(interval)
+                interval = null
+                this.clock = 60
+                this.sending = false
+              }
+            }, 1000);
+          }
+        })
+      }
     },
     //登录
     handlerLogin() {