Browse Source

手机验证码登录

suhanqian 1 year ago
parent
commit
69caad6a48
1 changed files with 76 additions and 24 deletions
  1. 76 24
      src/views/pages/login.vue

+ 76 - 24
src/views/pages/login.vue

@@ -17,8 +17,8 @@
                   </span>
                 </el-input>
               </el-form-item>
-              <el-form-item v-if="showOnPhone" prop="phoneNum">
-                <el-input  v-model="dataForm.phoneNum" placeholder="请输入手机号">
+              <el-form-item v-if="showOnPhone" prop="phoneNumber">
+                <el-input  v-model="dataForm.phoneNumber" placeholder="请输入手机号">
                 </el-input>
               </el-form-item>
               <el-form-item v-if="showUsername" prop="password">
@@ -42,8 +42,8 @@
                   </el-col>
                 </el-row>
               </el-form-item>
-              <el-form-item v-if="showOnPhone" prop="VerificationCode" >
-                <el-input v-model="dataForm.VerificationCode"  placeholder="请输入验证码">
+              <el-form-item v-if="showOnPhone" prop="validsmsCode" >
+                <el-input v-model="dataForm.validsmsCode"  placeholder="请输入验证码">
                   <template #append> <div class="verView" @click="verCodeClick()">{{codeTitle}}</div></template>        
                 </el-input>
               </el-form-item>
@@ -76,6 +76,7 @@ export default {
       i18nMessages: messages,
       showOnPhone: false,
       showUsername: true,
+      show:false,
       codeTitle:"获取验证码",
       time_count:60,
       timer:null,
@@ -85,8 +86,8 @@ export default {
         password: '',
         deviceId: '',
         validCode: '',
-        phoneNum:'',
-        VerificationCode:'',
+        phoneNumber:'',
+        validsmsCode:'',
       }
     }
   },
@@ -100,8 +101,14 @@ export default {
           { required: true, message: this.$t('validate.required'), trigger: 'blur' }
         ],
         validCode: [
-          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
-        ]
+          { required: true, message: '请输入验证码', trigger: 'blur' }
+        ],
+        validsmsCode: [
+          { required: true, message: '请输入验证码', trigger: 'blur' }
+        ],
+        phoneNumber: [
+          { required: true, message: '请输入手机号码', trigger: 'blur' }
+        ],
       }
     }
   },
@@ -116,21 +123,36 @@ export default {
     },
     // 获取手机验证码
     verCodeClick () {
-      if(!this.timer) {
-        this.timer = setInterval ( () => {
-          if(this.time_count>0) {
-          this.time_count--
-          this.codeTitle = this.time_count +'秒后重新获取'
-        }
-        else {
-          this.codeTitle = '获取验证码'
-          clearInterval(this.timer)
-          this.timer = null
-          this.time_count = 60
-        }
-        },1000)
-       
-      }
+      if(!this.show){
+      this.$http.post('/idaas/sso/smsvalidate',{
+        phoneNumber:this.dataForm.phoneNumber,
+        deviceId:this.dataForm.deviceId,
+        validCode:this.dataForm.validCode,
+      }).then(({ data: res }) => {
+          // this.show = true
+            if (res.code !== 0) {
+                return this.$message.error(res.msg)
+              }
+              if(res.code==0) {
+                if(!this.timer) {
+                  this.timer = setInterval ( () => {
+                    if(this.time_count>0) {
+                    this.time_count--
+                    this.codeTitle = this.time_count +'秒后重新获取'
+                  }
+                  else {
+                    this.codeTitle = '获取验证码'
+                    clearInterval(this.timer)
+                    this.timer = null
+                    this.time_count = 60
+                    this.show = false
+                  }
+                  },1000)
+                 
+                }
+              }
+        }).catch(() => {})
+    }
     },
     onUserName () {
       this.showUsername = true
@@ -164,7 +186,35 @@ export default {
         if (!valid) {
           return false
         }
-        this.$http.post('/idaas/sso/login', this.dataForm).then(({ data: res }) => {
+        if(this.showOnPhone) {
+          this.$http.post('idaas/sso/smslogin', {
+            deviceId:this.dataForm.deviceId,
+            phoneNumber:this.dataForm.phoneNumber,
+            validCode:this.dataForm.validCode,
+            validsmsCode:this.dataForm.validsmsCode,
+          })
+          .then(({ data: res }) => {
+          if (res.code !== 0) {
+            this.getCaptcha()
+            return this.$message.error(res.msg)
+          }
+          Cookies.set('token', res.sessionToken)
+          // 发送用户登录成功MQ消息
+           this.$http.get('/mq/user/login').then(({ data: res }) => {
+            if (res.code !== 0) {
+              return this.$message.error(res.msg)
+            }
+          }).catch(() => {})
+          if(localStorage.getItem('pathCopyshow') && localStorage.getItem('pathCopy')) {
+            this.$router.push(localStorage.getItem('pathCopy'))
+          }
+          else{
+            this.$router.replace({ name: 'home' })
+          }
+        }).catch(() => {})
+          
+        }else {
+          this.$http.post('/idaas/sso/login', this.dataForm).then(({ data: res }) => {
           if (res.code !== 0) {
             this.getCaptcha()
             return this.$message.error(res.msg)
@@ -184,6 +234,8 @@ export default {
             this.$router.replace({ name: 'home' })
           }
         }).catch(() => {})
+        }
+       
       })
     }, 1000, { 'leading': true, 'trailing': false })
   }