ソースを参照

微信登录流程优化

wangtao 7 ヶ月 前
コミット
c65c3e2249
1 ファイル変更28 行追加25 行削除
  1. 28 25
      src/store/modules/user.js

+ 28 - 25
src/store/modules/user.js

@@ -309,38 +309,41 @@ const useStores = defineStore("useStores", {
     GetWxOpenId(type, options) {
       let url = "https://manager.usky.cn/mobile/#/"
       if (type == 1 && common.isWechatMp()) {
-        if (localStorage.getItem("wxOpenId") && localStorage.getItem("App-Token")) {
-          getPageAuthorization({ openId: localStorage.getItem("wxOpenId") }).then((res) => {
-            if (res.data?.openid && res.data?.accessToken) {
-              window.location.href = `${url}pages/index`;
-            } else {
-              this.LogOut().then(() => {
-                localStorage.removeItem("wxOpenId")
-                localStorage.removeItem("App-Token")
-                window.location.href = config.baseUrl + "/service-iot/weChat/getFirst1";
-              })
-            }
-          })
-        } else {
+        if(localStorage.getItem("wxOpenId")){
+          if(localStorage.getItem("App-Token")){
+            window.location.href = `${url}pages/index`;
+          }else{
+            getPageAuthorization({ openId: localStorage.getItem("wxOpenId") }).then((res) => {
+              if (res?.data?.openid && res?.data?.accessToken) {
+                window.location.href = `${url}pages/index`;
+              } else {
+                this.LogOut().then()
+              }
+            })
+          }
+        }else{
           if (window.location.href.indexOf("openId=") == -1) {
             window.location.href = config.baseUrl + "/service-iot/weChat/getFirst1";
           } else {
             localStorage.setItem("wxOpenId", common.getUrlList().openId)
+            GetWxOpenId(1)
           }
         }
       } else if (type == 2 && common.isWechatMp()) {
-        if (localStorage.getItem("wxOpenId") && localStorage.getItem("App-Token")) {
-          getPageAuthorization({ openId: localStorage.getItem("wxOpenId") }).then((res) => {
-            if (!res.data?.openid || !res.data?.accessToken) {
-              this.LogOut().then(() => {
-                localStorage.removeItem("wxOpenId")
-                localStorage.removeItem("App-Token")
-                window.location.href = config.baseUrl + "/service-iot/weChat/getFirst1";
-              })
-            }
-          })
-        } else {
-          window.location.href = config.baseUrl + "/service-iot/weChat/getFirst1";
+        if(localStorage.getItem("wxOpenId")){
+          if(!localStorage.getItem("App-Token")){
+            getPageAuthorization({ openId: localStorage.getItem("wxOpenId") }).then((res) => {
+              if (res?.data?.openid && res?.data?.accessToken) {
+                window.location.href = `${url}pages/index`;
+              } else {
+                this.LogOut().then(() => {
+                  window.location.href = `${url}pages/login`;
+                })
+              }
+            })
+          }
+        }else{
+            window.location.href = config.baseUrl + "/service-iot/weChat/getFirst1";
         }
       }
     },