Sfoglia il codice sorgente

1、企微登录校验问题

yys 1 settimana fa
parent
commit
f8a824a938
3 ha cambiato i file con 170 aggiunte e 87 eliminazioni
  1. 56 28
      src/views/qw/user/cuDeptIdIndex.vue
  2. 58 31
      src/views/qw/user/index.vue
  3. 56 28
      src/views/qw/user/myIndex.vue

+ 56 - 28
src/views/qw/user/cuDeptIdIndex.vue

@@ -558,6 +558,8 @@ export default {
         title:"",
         open:false,
         code:null,
+        submitted:false,
+        waitCount:0,
       },
       cloudAPOpen:{
         open:false,
@@ -702,6 +704,15 @@ export default {
       if (val.appKey==null || val.appKey===''){
         return this.$message.warning("没有授权码,无法登录企业微信,请授权");
       }
+      // 二次登录前清掉上次验证码弹窗与轮询,避免残留
+      if (this.loginQwInterval) {
+        clearInterval(this.loginQwInterval);
+        this.loginQwInterval = null;
+      }
+      this.qwCode.open = false;
+      this.qwCode.code = null;
+      this.qwCode.submitted = false;
+      this.qwCode.waitCount = 0;
       loginQwIpad({qwUserId:val.id}).then(res => {
 		this.qwUserId=val.id;
         this.qwLogin.code=null;
@@ -746,55 +757,72 @@ export default {
 	  }, 3000);
 	},
     loginQwPolling() {
+      if (this.loginQwInterval) {
+        clearInterval(this.loginQwInterval);
+        this.loginQwInterval = null;
+      }
       this.loginQwInterval = setInterval(() => {
         qrCodeStatus({ qwUserId: this.qwUserId }).then(res => {
 			console.log(res)
 			if (res.msg==22) {
-				this.$message.success('账号企业不一致请重新扫码登录');
+				this.$message.error('扫码企微与员工所属企业不一致,请重新点击登录,使用正确企微扫码');
 				this.clearDl();
-			}
-          if (res.msg==104001) {
+			} else if (res.msg==23) {
+				this.$message.error('扫码账号与员工不一致,请同步信息后重新点击登录扫码');
+				this.clearDl();
+			} else if (res.msg==104001) {
 			this.$message.success('登录成功');
 			this.clearDl()
-
           }else if(res.msg==100004){
-			  this.qwCode.open=true;
-			  clearInterval(this.loginQwInterval);
+			  if (!this.qwCode.open && !this.qwCode.submitted) {
+			    this.qwLogin.open = false;
+			    this.qwCode.code = null;
+			    this.qwCode.open = true;
+			  }
+		  } else if (this.qwCode.submitted) {
+			  this.qwCode.waitCount = (this.qwCode.waitCount || 0) + 1;
+			  if (this.qwCode.waitCount >= 20) {
+			    this.$message.warning('登录确认超时,请重新点击登录后再扫码');
+			    this.clearDl();
+			  }
 		  }
-        });
+        }).catch(() => {});
       }, 3000);
     },
 	submitCodeForm(){
-
+		if (!this.qwCode.code) {
+			return this.$message.warning('请输入验证码');
+		}
 		qrCodeVerify({ code: this.qwCode.code,qwUserId: this.qwUserId }).then(res => {
 			console.log(res)
-
-			this.$message.success('验证成功账号信息确认中。。。。');
 			this.qwCode.open=false;
-			 this.loginQwInterval = setTimeout(() => {
-			     qrCodeStatus({ qwUserId: this.qwUserId }).then(res => {
-			         console.log(res);
-			         if (res.msg == 23) {
-			             this.$message.error('账号不一致请重新扫码登录');
-			             this.clearDl();
-			         }
-					 if (res.msg == 22) {
-					     this.$message.error('账号企业不一致请重新扫码登录');
-					     this.clearDl();
-					 }
-			         if (res.msg == 104001) {
-			             this.$message.success('登录成功');
-			             this.clearDl();
-			         }
-			     });
-			 }, 4000);
+			this.qwCode.code=null;
+			this.qwCode.submitted = true;
+			this.qwCode.waitCount = 0;
+			if (res.msg === 'NOT_NEED_VERIFY') {
+				this.$message.info('当前无需验证码,正在确认登录状态...');
+			} else {
+				this.$message.success('验证成功,账号信息确认中...');
+			}
+			this.loginQwPolling();
+		}).catch(err => {
+			const msg = (err && err.message) ? err.message : '';
+			if (msg.indexOf('重新点击登录') !== -1 || msg.indexOf('已过期') !== -1 || msg.indexOf('企业不一致') !== -1) {
+				this.clearDl();
+			}
 		});
 	},
 
 	clearDl(){
 		this.qwCode.open=false;
+		this.qwCode.code=null;
+		this.qwCode.submitted = false;
+		this.qwCode.waitCount = 0;
 		this.qwLogin.open=false;
-		clearInterval(this.loginQwInterval);
+		if (this.loginQwInterval) {
+			clearInterval(this.loginQwInterval);
+			this.loginQwInterval = null;
+		}
 		this.getList()
 	},
 

+ 58 - 31
src/views/qw/user/index.vue

@@ -658,6 +658,8 @@ export default {
         title:"",
         open:false,
         code:null,
+        submitted:false,
+        waitCount:0,
       },
       cloudAPOpen:{
         open:false,
@@ -814,6 +816,15 @@ export default {
       if (val.appKey == null || val.appKey === '') {
         return this.$message.warning("没有授权码,无法登录企业微信,请授权");
       }
+      // 二次登录前清掉上次验证码弹窗与轮询,避免残留
+      if (this.loginQwInterval) {
+        clearInterval(this.loginQwInterval);
+        this.loginQwInterval = null;
+      }
+      this.qwCode.open = false;
+      this.qwCode.code = null;
+      this.qwCode.submitted = false;
+      this.qwCode.waitCount = 0;
       loginQwIpad({qwUserId: val.id}).then(res => {
         this.qwUserId = val.id;
         this.qwLogin.code = null;
@@ -858,59 +869,75 @@ export default {
       }, 3000);
     },
     loginQwPolling() {
+      if (this.loginQwInterval) {
+        clearInterval(this.loginQwInterval);
+        this.loginQwInterval = null;
+      }
       this.loginQwInterval = setInterval(() => {
         qrCodeStatus({qwUserId: this.qwUserId}).then(res => {
           console.log(res)
           if (res.msg == 22) {
-            this.$message.success('账号企业不一致请重新扫码登录');
+            this.$message.error('扫码企微与员工所属企业不一致,请重新点击登录,使用正确企微扫码');
             this.clearDl();
-          }
-          if (res.msg == 23) {
-            this.$message.success('账号不匹配,请同步信息后重新扫码登录');
+          } else if (res.msg == 23) {
+            this.$message.error('扫码账号与员工不一致,请同步信息后重新点击登录扫码');
             this.clearDl();
-          }
-          if (res.msg == 104001) {
+          } else if (res.msg == 104001) {
             this.$message.success('登录成功');
             this.clearDl()
-
           } else if (res.msg == 100004) {
-            this.qwCode.open = true;
-            clearInterval(this.loginQwInterval);
+            // 已提交过验证码则不再弹窗;进入验证码后关闭二维码,避免同一码换主体再扫
+            if (!this.qwCode.open && !this.qwCode.submitted) {
+              this.qwLogin.open = false;
+              this.qwCode.code = null;
+              this.qwCode.open = true;
+            }
+          } else if (this.qwCode.submitted) {
+            // 验码后等待终态,超时则提示重试,避免一直空转
+            this.qwCode.waitCount = (this.qwCode.waitCount || 0) + 1;
+            if (this.qwCode.waitCount >= 20) {
+              this.$message.warning('登录确认超时,请重新点击登录后再扫码');
+              this.clearDl();
+            }
           }
-        });
+        }).catch(() => {});
       }, 3000);
     },
     submitCodeForm() {
-
+      if (!this.qwCode.code) {
+        return this.$message.warning('请输入验证码');
+      }
       qrCodeVerify({code: this.qwCode.code, qwUserId: this.qwUserId}).then(res => {
         console.log(res)
-
-        this.$message.success('验证成功账号信息确认中。。。。');
         this.qwCode.open = false;
-        this.loginQwInterval = setTimeout(() => {
-          qrCodeStatus({qwUserId: this.qwUserId}).then(res => {
-            console.log(res);
-            if (res.msg == 23) {
-              this.$message.error('账号不一致请重新扫码登录');
-              this.clearDl();
-            }
-            if (res.msg == 22) {
-              this.$message.error('账号企业不一致请重新扫码登录');
-              this.clearDl();
-            }
-            if (res.msg == 104001) {
-              this.$message.success('登录成功');
-              this.clearDl();
-            }
-          });
-        }, 4000);
+        this.qwCode.code = null;
+        this.qwCode.submitted = true;
+        this.qwCode.waitCount = 0;
+        if (res.msg === 'NOT_NEED_VERIFY') {
+          this.$message.info('当前无需验证码,正在确认登录状态...');
+        } else {
+          this.$message.success('验证成功,账号信息确认中...');
+        }
+        this.loginQwPolling();
+      }).catch(err => {
+        const msg = (err && err.message) ? err.message : '';
+        // 需要重新发起登录的错误,直接收掉弹窗
+        if (msg.indexOf('重新点击登录') !== -1 || msg.indexOf('已过期') !== -1 || msg.indexOf('企业不一致') !== -1) {
+          this.clearDl();
+        }
       });
     },
 
     clearDl() {
       this.qwCode.open = false;
+      this.qwCode.code = null;
+      this.qwCode.submitted = false;
+      this.qwCode.waitCount = 0;
       this.qwLogin.open = false;
-      clearInterval(this.loginQwInterval);
+      if (this.loginQwInterval) {
+        clearInterval(this.loginQwInterval);
+        this.loginQwInterval = null;
+      }
       this.getList()
     },
 

+ 56 - 28
src/views/qw/user/myIndex.vue

@@ -650,6 +650,8 @@ export default {
         title:"",
         open:false,
         code:null,
+        submitted:false,
+        waitCount:0,
       },
       cloudAPOpen:{
         open:false,
@@ -789,6 +791,15 @@ export default {
       if (val.appKey == null || val.appKey === '') {
         return this.$message.warning("没有授权码,无法登录企业微信,请授权");
       }
+      // 二次登录前清掉上次验证码弹窗与轮询,避免残留
+      if (this.loginQwInterval) {
+        clearInterval(this.loginQwInterval);
+        this.loginQwInterval = null;
+      }
+      this.qwCode.open = false;
+      this.qwCode.code = null;
+      this.qwCode.submitted = false;
+      this.qwCode.waitCount = 0;
       loginQwIpad({qwUserId: val.id}).then(res => {
         this.qwUserId = val.id;
         this.qwLogin.code = null;
@@ -833,55 +844,72 @@ export default {
       }, 3000);
     },
     loginQwPolling() {
+      if (this.loginQwInterval) {
+        clearInterval(this.loginQwInterval);
+        this.loginQwInterval = null;
+      }
       this.loginQwInterval = setInterval(() => {
         qrCodeStatus({qwUserId: this.qwUserId}).then(res => {
           console.log(res)
           if (res.msg == 22) {
-            this.$message.success('账号企业不一致请重新扫码登录');
+            this.$message.error('扫码企微与员工所属企业不一致,请重新点击登录,使用正确企微扫码');
             this.clearDl();
-          }
-          if (res.msg == 104001) {
+          } else if (res.msg == 23) {
+            this.$message.error('扫码账号与员工不一致,请同步信息后重新点击登录扫码');
+            this.clearDl();
+          } else if (res.msg == 104001) {
             this.$message.success('登录成功');
             this.clearDl()
-
           } else if (res.msg == 100004) {
-            this.qwCode.open = true;
-            clearInterval(this.loginQwInterval);
+            if (!this.qwCode.open && !this.qwCode.submitted) {
+              this.qwLogin.open = false;
+              this.qwCode.code = null;
+              this.qwCode.open = true;
+            }
+          } else if (this.qwCode.submitted) {
+            this.qwCode.waitCount = (this.qwCode.waitCount || 0) + 1;
+            if (this.qwCode.waitCount >= 20) {
+              this.$message.warning('登录确认超时,请重新点击登录后再扫码');
+              this.clearDl();
+            }
           }
-        });
+        }).catch(() => {});
       }, 3000);
     },
     submitCodeForm() {
-
+      if (!this.qwCode.code) {
+        return this.$message.warning('请输入验证码');
+      }
       qrCodeVerify({code: this.qwCode.code, qwUserId: this.qwUserId}).then(res => {
         console.log(res)
-
-        this.$message.success('验证成功账号信息确认中。。。。');
         this.qwCode.open = false;
-        this.loginQwInterval = setTimeout(() => {
-          qrCodeStatus({qwUserId: this.qwUserId}).then(res => {
-            console.log(res);
-            if (res.msg == 23) {
-              this.$message.error('账号不一致请重新扫码登录');
-              this.clearDl();
-            }
-            if (res.msg == 22) {
-              this.$message.error('账号企业不一致请重新扫码登录');
-              this.clearDl();
-            }
-            if (res.msg == 104001) {
-              this.$message.success('登录成功');
-              this.clearDl();
-            }
-          });
-        }, 4000);
+        this.qwCode.code = null;
+        this.qwCode.submitted = true;
+        this.qwCode.waitCount = 0;
+        if (res.msg === 'NOT_NEED_VERIFY') {
+          this.$message.info('当前无需验证码,正在确认登录状态...');
+        } else {
+          this.$message.success('验证成功,账号信息确认中...');
+        }
+        this.loginQwPolling();
+      }).catch(err => {
+        const msg = (err && err.message) ? err.message : '';
+        if (msg.indexOf('重新点击登录') !== -1 || msg.indexOf('已过期') !== -1 || msg.indexOf('企业不一致') !== -1) {
+          this.clearDl();
+        }
       });
     },
 
     clearDl() {
       this.qwCode.open = false;
+      this.qwCode.code = null;
+      this.qwCode.submitted = false;
+      this.qwCode.waitCount = 0;
       this.qwLogin.open = false;
-      clearInterval(this.loginQwInterval);
+      if (this.loginQwInterval) {
+        clearInterval(this.loginQwInterval);
+        this.loginQwInterval = null;
+      }
       this.getList()
     },