Просмотр исходного кода

修改验证码和登录接口

lihongxiao 3 лет назад
Родитель
Сommit
60de07096b
2 измененных файлов с 23 добавлено и 5 удалено
  1. 10 0
      src/http/moudules/login.js
  2. 13 5
      src/views/Login.vue

+ 10 - 0
src/http/moudules/login.js

@@ -13,6 +13,16 @@ export const login = data => {
     })
 }
 
+// 登录2
+export const login2 = data => {
+    return axios({
+        url: '/login2',
+        method: 'post',
+        data
+    })
+}
+
+
 // 登出
 export const logout = () => {
     return axios({

+ 13 - 5
src/views/Login.vue

@@ -124,7 +124,8 @@ export default {
       let userInfo = {
         account: this.loginForm.account,
         password: this.loginForm.password,
-        captcha: this.loginForm.captcha.toLowerCase()
+        captcha: this.loginForm.captcha.toLowerCase(),
+        captchaId:this.loginForm.captchaId
       }
             
       // this.$store.dispatch('login', userInfo)
@@ -144,14 +145,19 @@ export default {
       //     this.loading = false
       //   })
     
-      this.$api.login.login(userInfo).then((res) => {
+      this.$api.login.login2(userInfo).then((res) => {
         if (res.code != 200) {
           this.$message({
             message: res.msg,
             type: 'error',
             duration: 2000
           })
-        } else {
+         if(res.code==500&&res.msg=='验证码不正确'){
+            this.refreshCaptcha()
+            }
+        }
+        else {
+         
           if (this.rememberPassword) { //是否保存密码
             Cookies.set('accountInfo', { 'account': this.loginForm.account, 'password': this.loginForm.password, })
           } else {
@@ -238,8 +244,10 @@ export default {
     })
     },
     refreshCaptcha() {
-      // this.loginForm.src = this.global.baseUrl + "/captcha.jpg?t=" + new Date().getTime();
-      this.loginForm.src = process.env.BASE_URL + "/captcha.jpg?t=" + new Date().getTime();
+      let randnum =Math.floor(Math.random() * (1000000 - 1 + 1) ) + 1
+      this.loginForm.src = process.env.BASE_URL + "/captchaById?t=" + new Date().getTime()+'&captchaId='+randnum;
+      this.loginForm.captchaId=randnum
+
     },
     reset() {
       this.$refs.loginForm.resetFields()