浏览代码

修改登陆逻辑

wyling007 3 年之前
父节点
当前提交
5ad6f4a793
共有 1 个文件被更改,包括 24 次插入1 次删除
  1. 24 1
      src/route/guard.ts

+ 24 - 1
src/route/guard.ts

@@ -17,6 +17,30 @@ const guard = (router: Router) => {
 			console.log(location);
 		}
 
+		//监听到登陆事件
+		if (to.query.state === "LOGIN") {
+			const toast = Toast.loading({
+				duration: 0, // 持续展示 toast
+				forbidClick: true,
+				message: "登陆中",
+			});
+			try {
+				await useLogin(to.query);
+				toast.message = `登陆成功`;
+				setTimeout(() => {
+					Toast.clear();
+				}, 500);
+			} catch (error) {
+				toast.message = `登陆失败`;
+				setTimeout(() => {
+					Toast.clear();
+					location.replace(`https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx67ca1b8c9816ef28&redirect_uri=https://jpcj-h5.zzxcx.net/home/test&response_type=code&scope=snsapi_userinfo&state=LOGIN#wechat_redirect`);
+				}, 1000);
+			}
+		} else {
+			location.replace(`https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx67ca1b8c9816ef28&redirect_uri=${location.href}&response_type=code&scope=snsapi_userinfo&state=LOGIN#wechat_redirect`);
+		}
+
 		//检测token状态,token失效直接跳转至登陆链接
 		try {
 			const authTest = await userInfo();
@@ -26,7 +50,6 @@ const guard = (router: Router) => {
 		} catch (error) {
 			//监听到登陆事件
 			if (to.query.state === "LOGIN") {
-				next();
 				const toast = Toast.loading({
 					duration: 0, // 持续展示 toast
 					forbidClick: true,