Kaynağa Gözat

enable 第三方登录

Michael Wang 6 yıl önce
ebeveyn
işleme
25809b9c5f

+ 6 - 0
src/modules/portal/routes/routes.js

@@ -1,4 +1,5 @@
 import Login from "../views/Login.vue";
+import Access from "../views/Access.vue";
 import Home from "../views/home/Home.vue";
 import HomeMain from "../views/home/HomeMain.vue";
 
@@ -14,6 +15,11 @@ export default [
     name: "Login",
     component: Login
   },
+  {
+    path: "/access",
+    name: "Access",
+    component: Access
+  },
   {
     path: "/home",
     component: Home,

+ 58 - 0
src/modules/portal/views/Access.vue

@@ -0,0 +1,58 @@
+<template>
+  <div></div>
+</template>
+
+<script>
+import { mapActions } from "vuex";
+import { USER_SIGNIN } from "../store/user";
+import { CORE_API } from "@/constants/constants";
+
+export default {
+  name: "Access",
+  data() {
+    return {
+      accessInfo: {
+        orgId: null,
+        loginName: null,
+        appId: null,
+        timestamp: null,
+        token: null
+      }
+    };
+  },
+  created() {
+    sessionStorage.clear();
+    var params = this.$route.query;
+
+    this.accessInfo.orgId = params.orgId;
+    this.accessInfo.loginName = params.loginName;
+    this.accessInfo.appId = params.appId;
+    this.accessInfo.timestamp = params.timestamp;
+    this.accessInfo.token = params.token;
+
+    const url = CORE_API + "/auth/thirdPartyAccess";
+    this.$httpWithMsg
+      .post(url, new URLSearchParams(this.accessInfo), {
+        headers: { "content-type": "application/x-www-form-urlencoded" }
+      })
+      .then(response => {
+        var user = response.data;
+        this.USER_SIGNIN(user);
+        this.$router.replace({ path: "/home/overview" });
+        this.$notify({
+          message: "接入成功",
+          type: "success"
+        });
+      })
+      .catch(() => {
+        this.$notify({
+          message: "接入失败",
+          type: "error"
+        });
+      });
+  },
+  methods: {
+    ...mapActions([USER_SIGNIN])
+  }
+};
+</script>

+ 4 - 0
src/modules/portal/views/Login.vue

@@ -124,6 +124,10 @@ export default {
     }
   },
   created() {
+    if (this.$route.hash && this.$route.hash.startsWith("#/access?")) {
+      this.$router.push(this.$route.hash.slice(1));
+      return;
+    }
     this.loginInfo.domain = window.location.host;
     sessionStorage.clear();
     var params = this.$route.query;

+ 9 - 1
src/plugins/axios.js

@@ -30,13 +30,21 @@ let wk_orgId;
 _axios.interceptors.request.use(
   function(config) {
     // Do something before request is sent
-    if (config.url.includes("/login") === false) {
+    if (
+      config.url.includes("/login") === false &&
+      config.url.includes("/auth/thirdPartyAccess") === false
+    ) {
       if (!wk_token) {
         const user = JSON.parse(window.sessionStorage.getItem("user"));
         if (!user) {
           Vue.prototype.$alert("登录失效,请重新登录!", "提示", {
             confirmButtonText: "确定",
             callback: () => {
+              // if (process.env.NODE_ENV !== "production") {
+              //   router.push("/login/" + "?orgId=" + wk_orgId);
+              // } else {
+              //   router.push("/login");
+              // }
               router.push("/login/" + "?orgId=" + wk_orgId);
             }
           });