Explorar o código

新增登录双重校验

Tang %!s(int64=2) %!d(string=hai) anos
pai
achega
a1fa3f565a
Modificáronse 4 ficheiros con 100 adicións e 26 borrados
  1. 2 1
      config/dev.env.js
  2. 11 0
      src/apis/login.js
  3. 31 5
      src/pages/home/index.vue
  4. 56 20
      src/pages/login/index.vue

+ 2 - 1
config/dev.env.js

@@ -2,7 +2,8 @@
 module.exports = {
   NODE_ENV: '"development"',
   BASE_IMG_URL: '"https://file-dev.xyyxt.net/"', //图片上传api
-  BASE_URL: '"http://120.79.166.78:19012"',
+  BASE_URL: '"http://192.168.1.24:5055"',
+  // BASE_URL: '"http://120.79.166.78:19012"',
   TENANT_ID: '"867735392558919680"',
   WEAPP_LOGO: '"@/assets/xcxqrcode.jpg"', // 微信小程序扫码图片
   TENANT_NANE: '"祥粤云学堂"',

+ 11 - 0
src/apis/login.js

@@ -141,4 +141,15 @@ export default {
 			noToken: true
 		})
 	},
+  /**
+   * 
+   * @returns 获取用户登录是否需要验证码
+   */
+   dualAuth(data) {
+		return request({
+			url: '/app/common/dual_auth',
+			method: 'get',
+      params:data,
+		})
+	},
 }

+ 31 - 5
src/pages/home/index.vue

@@ -228,7 +228,7 @@
                         autocomplete="new-password"
                         v-model="loginForm.account"
                         @keyup.enter.native="login"
-                        placeholder="请输入手机号或身份证号"
+                        :placeholder="dualStatus ? '请输入手机号' : '请输入手机号或身份证号' "
                       ></el-input>
                     </el-form-item>
                   </div>
@@ -243,6 +243,21 @@
                       ></el-input>
                     </el-form-item>
                   </div>
+                  <div class="input" v-if="dualStatus">
+                    <el-form-item prop="code">
+                      <el-input
+                        autocomplete="new-password"
+                        v-model="loginForm.code"
+                        placeholder="请输入验证码"
+                      >
+                        <span slot="suffix" @click="getLoginSms(1)" class="btn">{{
+                          countDown == 0
+                            ? "获取验证码"
+                            : `${countDown}秒重新获取`
+                        }}</span>
+                      </el-input>
+                    </el-form-item>
+                  </div>
                   <el-button
                     type="primary"
                     class="submit"
@@ -284,7 +299,7 @@
                         v-model="loginSmsForm.code"
                         placeholder="请输入验证码"
                       >
-                        <span slot="suffix" @click="getLoginSms" class="btn">{{
+                        <span slot="suffix" @click="getLoginSms(2)" class="btn">{{
                           countDown == 0
                             ? "获取验证码"
                             : `${countDown}秒重新获取`
@@ -624,6 +639,7 @@ export default {
   },
   data() {
     return {
+      dualStatus:false,//是否双重校验
       msgShow: false,
       msgData: {},
       showBox: false,
@@ -724,6 +740,13 @@ export default {
     this.courseLists();
   },
   mounted() {
+    //双重校验
+    this.$request.dualAuth().then((res) => {
+      this.dualStatus = res.data === "1" ? true : false;
+      if(this.dualStatus){
+        this.loginRules["account"][0].message = "请输入手机号"
+      }
+    });
     if (this.userInfo) {
       this.getRecord();
       // this.getmsg();
@@ -1418,6 +1441,9 @@ export default {
           let loginForm = JSON.parse(JSON.stringify(this.loginForm));
           loginForm.pwd = this.$tools.encryptor(loginForm.pwd);
           console.log(this.loginForm);
+          if(this.dualStatus){
+            loginForm.tel = loginForm.account
+          }
           this.$request
             .login(loginForm)
             .then((res) => {
@@ -1449,8 +1475,8 @@ export default {
     /**
      * 获取登录短信
      */
-    getLoginSms() {
-      this.$refs.loginSmsForm.validateField("tel", (valid) => {
+    getLoginSms(int) {
+      this.$refs[int === 1 ? 'loginForm' :'loginSmsForm'].validateField(int === 1 ? "account" :"tel", (valid) => {
         if (!valid) {
           if (this.countDown == 0) {
             if (this.getLoginCodeLock) {
@@ -1458,7 +1484,7 @@ export default {
             }
             this.getLoginCodeLock = true;
             this.$request
-              .getLoginSms({ tel: this.loginSmsForm.tel })
+              .getLoginSms({ tel: int === 1 ? this.loginForm.account : this.loginSmsForm.tel })
               .then((res) => {
                 this.getLoginCodeLock = false;
                 this.$message({

+ 56 - 20
src/pages/login/index.vue

@@ -48,7 +48,7 @@
                       <el-form-item prop="account">
                         <el-input
                           autocomplete="new-password"
-                          placeholder="手机号/身份证号"
+                          :placeholder="dualStatus ? '手机号' :'手机号/身份证号'"
                           v-model="loginForm.account"
                           @keyup.enter.native="login"
                         ></el-input>
@@ -71,6 +71,26 @@
                           ></i> </el-input
                       ></el-form-item>
                     </div>
+                    <div class="input" v-if="dualStatus">
+                      <el-form-item prop="code"
+                        ><el-input
+                          autocomplete="new-password"
+                          placeholder="短信验证码"
+                          v-model="loginForm.code"
+                        >
+                          <span
+                            slot="suffix"
+                            @click="getLoginSms(1)"
+                            class="btn"
+                            >{{
+                              countDown == 0
+                                ? "获取验证码"
+                                : `${countDown}秒重新获取`
+                            }}</span
+                          >
+                        </el-input></el-form-item
+                      >
+                    </div>
                     <div class="text">
                       <a @click="state = 2">立即注册</a>
                       <a @click="state = 3">找回密码</a>
@@ -109,7 +129,7 @@
                         >
                           <span
                             slot="suffix"
-                            @click="getLoginSms"
+                            @click="getLoginSms(2)"
                             class="btn"
                             >{{
                               countDown == 0
@@ -202,7 +222,9 @@
                   <div class="checkbox">
                     <el-form-item prop="read">
                       <div>
-                        <el-checkbox v-model="registerForm.read">我已认真阅读并同意</el-checkbox>
+                        <el-checkbox v-model="registerForm.read"
+                          >我已认真阅读并同意</el-checkbox
+                        >
                         <!-- <input type="checkbox" v-model="registerForm.read" /> -->
                       </div>
 
@@ -869,20 +891,20 @@ export default {
     };
     var validateAccept = (rule, value, callback) => {
       if (!value) {
-        callback(new Error('请勾选服务协议'))
+        callback(new Error("请勾选服务协议"));
       } else {
         callback();
       }
-    }
+    };
     return {
       state: 1, //1登录 2注册  3找回密码 4绑定学员身份
       tabIndex: 1,
       loginForm: {},
       loginSmsForm: {},
       registerForm: {
-        tel: '',
-        code: '',
-        pwd: '',
+        tel: "",
+        code: "",
+        pwd: "",
         read: false,
       },
       forgetForm: {},
@@ -932,7 +954,13 @@ export default {
         ],
         code: [{ required: true, trigger: "blur", message: "请输入验证码" }],
         pwd: [{ required: true, trigger: "blur", message: "请输入密码" }],
-        read: [{ required: true, trigger: ["blur", 'change'], validator: validateAccept },],
+        read: [
+          {
+            required: true,
+            trigger: ["blur", "change"],
+            validator: validateAccept,
+          },
+        ],
       },
 
       bindRules: {
@@ -954,6 +982,7 @@ export default {
       registerPwdShow: false,
       forgetPwdShow: false,
       showAgreementModal: false,
+      dualStatus: false, //是否需要双重校验
     };
   },
   computed: {
@@ -961,6 +990,13 @@ export default {
   },
   mounted() {
     this.state = this.$route.query.state || 1;
+    //双重校验
+    this.$request.dualAuth().then((res) => {
+      this.dualStatus = res.data === "1" ? true : false;
+      if(this.dualStatus){
+        this.loginRules["account"][0].message = "请输入手机号"
+      }
+    });
   },
   methods: {
     ...mapMutations(["setUserInfo", "setCurrentRouter"]),
@@ -978,7 +1014,6 @@ export default {
       localStorage.setItem("token", res.data.token);
       this.$tools.setUuid(new Date().valueOf() + "");
       if (res.data.full_info) {
-        
         this.getInfo();
       } else {
         this.user_account = res.data.user_account;
@@ -999,6 +1034,9 @@ export default {
           this.islogin = true;
           let loginForm = JSON.parse(JSON.stringify(this.loginForm));
           loginForm.pwd = this.$tools.encryptor(loginForm.pwd);
+          if(this.dualStatus){
+            loginForm.tel = loginForm.account
+          }
           this.$request
             .login(loginForm)
             .then((res) => {
@@ -1006,7 +1044,6 @@ export default {
               localStorage.setItem("token", res.data.token);
               this.$tools.setUuid(new Date().valueOf() + "");
               if (res.data.full_info) {
-                
                 this.getInfo();
               } else {
                 this.user_account = res.data.user_account;
@@ -1030,8 +1067,8 @@ export default {
     /**
      * 获取登录短信
      */
-    getLoginSms() {
-      this.$refs.loginSmsForm.validateField("tel", (valid) => {
+    getLoginSms(int) {
+      this.$refs[int === 1 ? 'loginForm' :'loginSmsForm'].validateField(int === 1 ? "account" :"tel", (valid) => {
         if (!valid) {
           if (this.countDown == 0) {
             if (this.getLoginCodeLock) {
@@ -1039,7 +1076,7 @@ export default {
             }
             this.getLoginCodeLock = true;
             this.$request
-              .getLoginSms({ tel: this.loginSmsForm.tel })
+              .getLoginSms({ tel: int === 1 ? this.loginForm.account : this.loginSmsForm.tel })
               .then((res) => {
                 this.getLoginCodeLock = false;
                 this.$message({
@@ -1056,7 +1093,7 @@ export default {
                 }, 1000);
               })
               .catch((err) => {
-                this.$message.error(err.msg)
+                this.$message.error(err.msg);
                 this.getLoginCodeLock = false;
               });
           }
@@ -1116,7 +1153,6 @@ export default {
               localStorage.setItem("token", res.data.token);
               this.$tools.setUuid(new Date().valueOf() + "");
               if (res.data.full_info) {
-                
                 this.getInfo();
               } else {
                 this.user_account = res.data.user_account;
@@ -1140,15 +1176,15 @@ export default {
      */
     getInfo() {
       this.$request
-        .getInfo({fromPlat: 2})
+        .getInfo({ fromPlat: 2 })
         .then((res) => {
           this.isRegister = false;
           this.islogin = false;
           this.isloginSms = false;
           this.setUserInfo(res.data);
-          console.log('=========',this.currentRouter);
+          console.log("=========", this.currentRouter);
           if (JSON.stringify(this.currentRouter) != "{}") {
-            console.log('zhelisafhsdifgsdiufg')
+            console.log("zhelisafhsdifgsdiufg");
             this.$router.push(this.currentRouter);
             this.setCurrentRouter({});
           } else {
@@ -1241,7 +1277,7 @@ export default {
           this.$tools.setUuid(new Date().valueOf() + "");
           if (res.data.full_info) {
             //信息完善,获取用户信息
-            
+
             this.getInfo();
           } else {
             //不完善,跳转完善信息页面