统一登录入口

dev_2022-05-11
yujialong 3 years ago
parent dd5c7b125b
commit 6a5f6b8531
  1. 11
      src/layouts/header/index.vue
  2. 3
      src/pages/account/login/index.vue
  3. 49
      src/pages/account/redirect/index.vue
  4. 8
      src/router/index.js
  5. 5
      src/router/routes.js
  6. 6
      src/store/modules/user.js

@ -54,7 +54,7 @@ export default {
}, },
computed: { computed: {
...mapState("user", [ ...mapState("user", [
"avatar", "userName", "title", "logoUrl", "customer", "customerName" "avatar", "userName", "title", "logoUrl", "customer", "customerName", 'fromClient'
]) ])
}, },
mounted() { mounted() {
@ -66,10 +66,15 @@ export default {
"setTitle", "setLogoUrl", "setAvatar", "setUserName" "setTitle", "setLogoUrl", "setAvatar", "setUserName"
]), ]),
loginout() { // 退 loginout() { // 退
this.$router.push("/login");
localStorage.clear(); localStorage.clear();
sessionStorage.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 getSystemDetail() { // logo
this.$get(this.api.logoDetail).then(res => { this.$get(this.api.logoDetail).then(res => {

@ -109,7 +109,7 @@ export default {
}, },
methods: { methods: {
...mapMutations("user", [ ...mapMutations("user", [
"SET_ROLENAME" "SET_ROLENAME", 'SET_FROM'
]), ]),
...mapActions("user", [ ...mapActions("user", [
"setCustomer", "setCustomerName" "setCustomer", "setCustomerName"
@ -134,6 +134,7 @@ export default {
this.getVerImg(); this.getVerImg();
this.loginForm.code = ""; this.loginForm.code = "";
util.local.set(Setting.tokenKey, res.data.token, Setting.tokenExpires); util.local.set(Setting.tokenKey, res.data.token, Setting.tokenExpires);
this.SET_FROM(false)
this.getRole() this.getRole()
this.queryCustomer() this.queryCustomer()
}).catch(res => {}) }).catch(res => {})

@ -0,0 +1,49 @@
<template></template>
<script>
import { mapActions, mapMutations } from "vuex";
import util from "@/libs/util";
import Setting from "@/setting";
export default {
data: function() {
return {
token: this.$route.query.auth
};
},
mounted() {
this.token ? this.setLogin() : this.$router.replace('/login')
},
methods: {
...mapMutations("user", [
"SET_ROLENAME", 'SET_FROM'
]),
...mapActions("user", [
"setCustomer", "setCustomerName"
]),
setLogin() {
this.SET_FROM(true)
util.local.set(Setting.tokenKey, window.atob(decodeURI(this.token)), Setting.tokenExpires);
this.getRole()
this.queryCustomer()
},
//
getRole() {
this.$post(`${this.api.getUserAllRoleByToken}?platformId=${Setting.platformId}`).then(res => {
this.SET_ROLENAME(res)
}).catch(err => {})
},
queryCustomer() { //
this.$get(this.api.isClient).then(res => {
util.successMsg('登录成功')
this.setCustomer(res.customer)
this.setCustomerName(res.customerName)
this.$router.replace('/index')
}).catch(res => {})
}
}
};
</script>
<style lang="scss" scoped>
</style>

@ -6,9 +6,9 @@ import { get } from "@/plugins/requests/index.js";
import api from "@/api"; import api from "@/api";
import util from "@/libs/util"; import util from "@/libs/util";
import BasicLayout from "@/layouts/home"; import BasicLayout from "@/layouts/home";
import store from '@/store'
Vue.use(Router); Vue.use(Router);
const createRouter = () => new Router({ const createRouter = () => new Router({
mode: Setting.routerMode, mode: Setting.routerMode,
base: process.env.BASE_URL, base: process.env.BASE_URL,
@ -282,13 +282,17 @@ router.beforeEach(function(to, from, next) {
getPermission(); getPermission();
} }
} else { } else {
if (to.path !== "/login") { if (to.path !== "/login" && to.path !== '/redirect') {
if (store.state.user.fromClient) {
location.href = `${location.origin}/student`
} else {
next({ next({
path: "/login", path: "/login",
query: { redirect: to.path } query: { redirect: to.path }
}); });
} }
} }
}
// 根据路由元信息设置文档标题 // 根据路由元信息设置文档标题
// window.document.title = to.meta.title ? to.meta.title : ""; // window.document.title = to.meta.title ? to.meta.title : "";
window.document.title = "教师管理端" window.document.title = "教师管理端"

@ -30,6 +30,11 @@ const frameOut = [
}, },
component: () => import("@/pages/account/login") component: () => import("@/pages/account/login")
}, },
{
path: "/redirect",
name: "redirect",
component: () => import("@/pages/account/redirect")
},
{ {
path: "/setting/person", path: "/setting/person",
name: "person", name: "person",

@ -19,7 +19,8 @@ export default {
userName: "", userName: "",
roleId: "", roleId: "",
dataTime: "", dataTime: "",
roleName: '' roleName: '',
fromClient: false // 是否从学生端登录
}, },
mutations: { mutations: {
SET_INFO: (state, info) => { SET_INFO: (state, info) => {
@ -49,6 +50,9 @@ export default {
}, },
SET_ROLENAME: (state, roleName) => { SET_ROLENAME: (state, roleName) => {
state.roleName = roleName state.roleName = roleName
},
SET_FROM: (state, fromClient) => {
state.fromClient = fromClient
} }
}, },
actions: { actions: {

Loading…
Cancel
Save