From 6a5f6b8531265c0f693e07a5bcf3c519feea1c6a Mon Sep 17 00:00:00 2001 From: yujialong <479214531@qq.com> Date: Mon, 21 Feb 2022 14:28:39 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E7=99=BB=E5=BD=95=E5=85=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layouts/header/index.vue | 11 +++++-- src/pages/account/login/index.vue | 3 +- src/pages/account/redirect/index.vue | 49 ++++++++++++++++++++++++++++ src/router/index.js | 16 +++++---- src/router/routes.js | 5 +++ src/store/modules/user.js | 6 +++- 6 files changed, 79 insertions(+), 11 deletions(-) create mode 100644 src/pages/account/redirect/index.vue diff --git a/src/layouts/header/index.vue b/src/layouts/header/index.vue index 930f241..0031c5e 100644 --- a/src/layouts/header/index.vue +++ b/src/layouts/header/index.vue @@ -54,7 +54,7 @@ export default { }, computed: { ...mapState("user", [ - "avatar", "userName", "title", "logoUrl", "customer", "customerName" + "avatar", "userName", "title", "logoUrl", "customer", "customerName", 'fromClient' ]) }, mounted() { @@ -66,10 +66,15 @@ export default { "setTitle", "setLogoUrl", "setAvatar", "setUserName" ]), loginout() { // 退出登录 - this.$router.push("/login"); localStorage.clear(); sessionStorage.clear(); - location.reload(); + // 从学生端登录的就返回学生端,否则,直接刷新回到登录页面 + if (this.fromClient) { + location.href = `${location.origin}/student` + // location.href = `http://192.168.31.125:8082/#/index/list` + } else { + location.reload() + } }, getSystemDetail() { // 获取系统logo this.$get(this.api.logoDetail).then(res => { diff --git a/src/pages/account/login/index.vue b/src/pages/account/login/index.vue index 5447b2a..9dd3b5d 100644 --- a/src/pages/account/login/index.vue +++ b/src/pages/account/login/index.vue @@ -109,7 +109,7 @@ export default { }, methods: { ...mapMutations("user", [ - "SET_ROLENAME" + "SET_ROLENAME", 'SET_FROM' ]), ...mapActions("user", [ "setCustomer", "setCustomerName" @@ -134,6 +134,7 @@ export default { this.getVerImg(); this.loginForm.code = ""; util.local.set(Setting.tokenKey, res.data.token, Setting.tokenExpires); + this.SET_FROM(false) this.getRole() this.queryCustomer() }).catch(res => {}) diff --git a/src/pages/account/redirect/index.vue b/src/pages/account/redirect/index.vue new file mode 100644 index 0000000..0ef488e --- /dev/null +++ b/src/pages/account/redirect/index.vue @@ -0,0 +1,49 @@ + + + + + \ No newline at end of file diff --git a/src/router/index.js b/src/router/index.js index 1a95288..bcbb53f 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -6,9 +6,9 @@ import { get } from "@/plugins/requests/index.js"; import api from "@/api"; import util from "@/libs/util"; import BasicLayout from "@/layouts/home"; +import store from '@/store' Vue.use(Router); - const createRouter = () => new Router({ mode: Setting.routerMode, base: process.env.BASE_URL, @@ -282,11 +282,15 @@ router.beforeEach(function(to, from, next) { getPermission(); } } else { - if (to.path !== "/login") { - next({ - path: "/login", - query: { redirect: to.path } - }); + if (to.path !== "/login" && to.path !== '/redirect') { + if (store.state.user.fromClient) { + location.href = `${location.origin}/student` + } else { + next({ + path: "/login", + query: { redirect: to.path } + }); + } } } // 根据路由元信息设置文档标题 diff --git a/src/router/routes.js b/src/router/routes.js index 790529a..acd1ade 100644 --- a/src/router/routes.js +++ b/src/router/routes.js @@ -30,6 +30,11 @@ const frameOut = [ }, component: () => import("@/pages/account/login") }, + { + path: "/redirect", + name: "redirect", + component: () => import("@/pages/account/redirect") + }, { path: "/setting/person", name: "person", diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 78709e0..ca8c32a 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -19,7 +19,8 @@ export default { userName: "", roleId: "", dataTime: "", - roleName: '' + roleName: '', + fromClient: false // 是否从学生端登录 }, mutations: { SET_INFO: (state, info) => { @@ -49,6 +50,9 @@ export default { }, SET_ROLENAME: (state, roleName) => { state.roleName = roleName + }, + SET_FROM: (state, fromClient) => { + state.fromClient = fromClient } }, actions: {