Pārlūkot izejas kodu

第三方登录

zhangjie 2 gadi atpakaļ
vecāks
revīzija
9a17af40f2

+ 1 - 0
lin.txt

@@ -0,0 +1 @@
+http://192.168.10.86:7111/api/open/authentication?account=admin2&returnUrl=http%3A%2F%2Fwww.baidu.com

+ 1 - 1
src/main.js

@@ -16,7 +16,7 @@ import "../card/assets/styles/module.scss";
 
 Vue.use(ElementUI, { size: "small" });
 
-Vue.use(VueLocalStorage, { storage: "session" });
+Vue.use(VueLocalStorage, { snamespace: "vs_", torage: "session" });
 Vue.use(globalVuePlugins);
 
 Vue.prototype.GLOBAL = GLOBAL;

+ 5 - 0
src/modules/login/api.js

@@ -39,3 +39,8 @@ export const getSysConfig = key => {
 export const getSysTime = () => {
   return $postParam("/api/admin/common/get_system_time", {});
 };
+
+// open-login
+export const openLogin = datas => {
+  return $postParam("/api/admin/print/open/account/login", datas);
+};

+ 23 - 0
src/modules/login/components/redirectLogin.vue

@@ -0,0 +1,23 @@
+<template>
+  <el-button type="primary">
+    redirect-login
+  </el-button>
+</template>
+
+<script>
+export default {
+  name: "redirect-login",
+  props: {
+    params: {
+      type: Object,
+      default() {
+        return {};
+      }
+    }
+  },
+  data() {
+    return {};
+  },
+  methods: {}
+};
+</script>

+ 10 - 0
src/modules/login/router.js

@@ -1,6 +1,7 @@
 import LoginHome from "./views/LoginHome";
 import Login from "./views/Login";
 import SelectSchool from "./views/SelectSchool";
+import LoginOpen from "./views/LoginOpen";
 
 export default {
   path: "/login-home",
@@ -15,6 +16,15 @@ export default {
         noRequire: true
       }
     },
+    {
+      path: "/login-open",
+      name: "LoginOpen",
+      component: LoginOpen,
+      meta: {
+        title: "第三方登录",
+        noRequire: true
+      }
+    },
     {
       path: "/select-school",
       name: "SelectSchool",

+ 61 - 0
src/modules/login/views/LoginOpen.vue

@@ -0,0 +1,61 @@
+<template>
+  <div class="login-open">
+    正在登录……
+  </div>
+</template>
+
+<script>
+/**
+ * returnUrl
+ * 所有需要重新登录的地方都要使用returnUrl。包括:
+ * axios
+ * router
+ * home:logout
+ */
+
+import { openLogin } from "../api";
+
+export default {
+  name: "login-open",
+  data() {
+    return {};
+  },
+  created() {
+    this.autoLogin();
+  },
+  methods: {
+    async autoLogin() {
+      this.$ls.clear();
+      const query = this.$route.query;
+      const data = await openLogin({
+        ...query,
+        path: "/#/login-open"
+      }).catch(() => {});
+
+      if (!data) {
+        window.history.go(-1);
+        return;
+      }
+      // 不同系统登录成功之后的处理逻辑可能会有差异
+      if (data.orgInfo)
+        this.$ls.set("orgId", data.orgInfo.id, this.GLOBAL.authTimeout);
+      if (data.schoolInfo)
+        this.$ls.set("schoolId", data.schoolInfo.id, this.GLOBAL.authTimeout);
+      this.$ls.set("user", data, this.GLOBAL.authTimeout);
+
+      this.$ls.set("token", data.accessToken, this.GLOBAL.authTimeout);
+      this.$ls.set("returnUrl", query["returnUrl"]);
+
+      if (data.roleList && data.roleList.includes("ADMIN")) {
+        this.$router.push({
+          name: "SelectSchool"
+        });
+      } else {
+        this.$router.push({
+          name: "Home"
+        });
+      }
+    }
+  }
+};
+</script>

+ 7 - 0
src/plugins/axios.js

@@ -169,6 +169,13 @@ const errorDataCallback = response => {
       callback: action => {
         unauthMsgBoxIsShow = false;
         if (action !== "confirm") return;
+
+        const returnUrl = Vue.ls.get("returnUrl");
+        if (returnUrl) {
+          window.location.href = returnUrl;
+          return;
+        }
+
         Vue.ls.clear();
         router.push({ name: "Login" });
       }

+ 6 - 0
src/router.js

@@ -88,6 +88,12 @@ router.beforeEach((to, from, next) => {
 
   if (!token) {
     // 登录失效的处理
+    const returnUrl = Vue.ls.get("returnUrl");
+    if (returnUrl) {
+      window.location.href = returnUrl;
+      return;
+    }
+
     Vue.ls.clear();
     next({ name: "Login" });
     return;

+ 7 - 0
src/views/Home.vue

@@ -388,6 +388,13 @@ export default {
     },
     async logoutAction() {
       await logout();
+
+      const returnUrl = this.$ls.get("returnUrl");
+      if (returnUrl) {
+        window.location.href = returnUrl;
+        return;
+      }
+
       this.$ls.clear();
       this.$router.push({ name: "Login" });
     },