统一登录入口

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: {
...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 => {

@ -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 => {})

@ -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 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,13 +282,17 @@ router.beforeEach(function(to, from, next) {
getPermission();
}
} else {
if (to.path !== "/login") {
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 }
});
}
}
}
// 根据路由元信息设置文档标题
// window.document.title = to.meta.title ? to.meta.title : "";
window.document.title = "教师管理端"

@ -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",

@ -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: {

Loading…
Cancel
Save