Explorar el Código

fix 第三方登录

Michael Wang hace 5 años
padre
commit
bf02594f37
Se han modificado 4 ficheros con 39 adiciones y 58 borrados
  1. 18 26
      src/features/Login/Login.vue
  2. 9 26
      src/features/Login/StudentAccess.vue
  3. 2 1
      src/router.js
  4. 10 5
      src/utils/axios.js

+ 18 - 26
src/features/Login/Login.vue

@@ -192,6 +192,12 @@ export default {
       }
     }, 1000);
     if (this.isEPCC) {
+      const redirectUrl = new URLSearchParams(location.search).get(
+        "redirectUrl"
+      );
+      if (redirectUrl) {
+        sessionStorage.setItem("redirectUrl", redirectUrl);
+      }
       this.login();
     }
   },
@@ -203,9 +209,6 @@ export default {
         },
       });
     }
-    if (this.$route.query.redirectUrl) {
-      sessionStorage.setItem("redirectUrl", this.$route.query.redirectUrl);
-    }
 
     this.isElectron = typeof nodeRequire != "undefined";
 
@@ -304,6 +307,8 @@ export default {
         loginResponse = await this.epccLogin();
         if (!loginResponse) {
           return;
+        } else {
+          loginResponse.data = { content: loginResponse.data, code: "200" }; // 和老接口的always ok保持一致
         }
       }
       let data = loginResponse.data;
@@ -364,6 +369,7 @@ export default {
           }
           this.$router.push("/online-exam");
           window._hmt.push(["_trackEvent", "登录页面", "登录成功"]);
+          this.$Spin.hide();
         } catch (error) {
           window._hmt.push([
             "_trackEvent",
@@ -376,6 +382,10 @@ export default {
             duration: 15,
             closable: true,
           });
+          if (this.isEPCC) {
+            this.$Spin.hide();
+            this.logout();
+          }
         }
       } else {
         window._hmt.push(["_trackEvent", "登录页面", "登录失败", data.desc]);
@@ -635,35 +645,17 @@ export default {
       ) {
         try {
           const response = await this.$http.post(
-            "/api/ecs_core/auth/thirdPartyStudentAccess",
-            {
-              accountType,
-              accountValue,
-              rootOrgId,
-              appId,
-              timestamp,
-              token,
-            }
+            "/api/ecs_core/auth/thirdPartyStudentAccess" + location.search
           );
           return response;
         } catch (error) {
           window._hmt.push(["_trackEvent", "第三方登录页面", "接口出错", ""]);
-          this.$Modal.error({
-            title: "返回",
-            content: "第三方登录访问错误",
-            onOk: () => {
-              history.back();
-            },
-          });
+          this.$Spin.hide();
+          this.logout();
         }
       } else {
-        this.$Modal.error({
-          title: "返回",
-          content: "第三方登录参数错误",
-          onOk: () => {
-            history.back();
-          },
-        });
+        this.$Spin.hide();
+        this.logout();
       }
     },
   },

+ 9 - 26
src/features/Login/StudentAccess.vue

@@ -1,15 +1,17 @@
 <template>
   <div>
-    第三方登录
-    <br />
-    <Button @click="goBack"></Button>
+    第三方登录...
   </div>
 </template>
 
 <script>
 export default {
   name: "StudentAccess",
-  async created() {
+  async mounted() {
+    const search = location.search;
+    const obj = Object.fromEntries(
+      new URLSearchParams(location.search).entries()
+    );
     const {
       accountType,
       accountValue,
@@ -18,7 +20,7 @@ export default {
       timestamp,
       token,
       redirectUrl,
-    } = this.$route.query;
+    } = obj;
 
     if (
       accountType &&
@@ -31,29 +33,10 @@ export default {
     ) {
       try {
         const response = await this.$http.post(
-          "/api/ecs_core/auth/thirdPartyStudentAccess",
-          {
-            accountType,
-            accountValue,
-            rootOrgId,
-            appId,
-            timestamp,
-            token,
-          }
+          "/api/ecs_core/auth/thirdPartyStudentAccess" + search
         );
         const domain = response.data.rootOrgDomain;
-        const o = {
-          accountType,
-          accountValue,
-          rootOrgId,
-          appId,
-          timestamp,
-          token,
-        };
-        const query = Object.keys(o)
-          .map(key => key + "=" + o[key])
-          .join("&");
-        this.$router.push("/login/" + domain + "?" + query);
+        this.$router.push("/login/" + domain + search);
       } catch (error) {
         window._hmt.push(["_trackEvent", "第三方登录页面", "接口出错", ""]);
         this.$Modal.error({

+ 2 - 1
src/router.js

@@ -92,6 +92,7 @@ let router = new Router({
       name: "Password",
       component: Password,
     },
+
     {
       path: "*",
       component: NotFoundComponent,
@@ -106,7 +107,7 @@ router.beforeEach((to, from, next) => {
     window._hmt.push(["_trackPageview", "/oe" + to.fullPath]);
   }
 
-  if (to.path.match(/^\/login\/.+$/)) {
+  if (to.path.match(/^\/login\/.+$/) || to.path.match(/^\/StudentAccess$/)) {
     next();
   } else {
     if (!localStorage.getItem("domain")) {

+ 10 - 5
src/utils/axios.js

@@ -21,11 +21,16 @@ const qmInstance = axios.create({});
 let wk_token, wk_key;
 qmInstance.interceptors.request.use(
   config => {
-    if (config.url.includes("/login") === false) {
-      if (!wk_token) {
-        wk_token = window.sessionStorage.getItem("token");
-        wk_key = window.localStorage.getItem("key");
-      }
+    // debugger;
+    if (
+      config.url.includes("/login") === false ||
+      config.url.includes("/api/ecs_core/auth/thirdPartyStudentAccess") ===
+        false
+    ) {
+      // if (!wk_token) {
+      wk_token = window.sessionStorage.getItem("token");
+      wk_key = window.localStorage.getItem("key");
+      // }
       if (wk_token && config.headers.common["token"] == null) {
         config.headers.common["token"] = wk_token;
         // Axios.defaults.headers.common["key"] = window.localStorage.getItem("key");