Elements-SY

modify

1 -import router from './router' 1 +import router from "./router";
2 -import store from './store' 2 +import store from "./store";
3 -import { Message } from 'element-ui' 3 +import { Message } from "element-ui";
4 -import { getToken, setToken, removeToken } from '@/utils/auth' 4 +import { getToken, removeToken } from "@/utils/auth";
5 -import settings from "@/settings"
6 -
7 -
8 -const whiteList = ['/login', '/auth-redirect', '/bind', '/register']
9 5
6 +const whiteList = ["/login", "/auth-redirect", "/bind", "/register"];
10 router.beforeEach((to, from, next) => { 7 router.beforeEach((to, from, next) => {
11 if (getToken()) { 8 if (getToken()) {
12 /* has token*/ 9 /* has token*/
13 - if (to.path === '/login') { 10 + if (to.path === "/login") {
14 - next({ path: '/' }) 11 + next({ path: "/" });
15 } else { 12 } else {
16 if (store.getters.roles.length === 0) { 13 if (store.getters.roles.length === 0) {
17 // 判断当前用户是否已拉取完user_info信息 14 // 判断当前用户是否已拉取完user_info信息
18 - store.dispatch('GetInfo').then(() => { 15 + store
19 - store.dispatch('GetTableHeaders').then(() => { 16 + .dispatch("GetInfo")
20 - store.dispatch('GenerateRoutes').then(accessRoutes => { 17 + .then(() => {
18 + //获取用户表头
19 + store.dispatch("GetTableHeaders").then(() => {
21 // 根据roles权限生成可访问的路由表 20 // 根据roles权限生成可访问的路由表
22 - router.addRoutes(accessRoutes) // 动态添加可访问路由表 21 + store.dispatch("GenerateRoutes").then((accessRoutes) => {
23 - next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 22 + router.addRoutes(accessRoutes); // 动态添加可访问路由表
24 - }) 23 + next({ ...to, replace: true }); // hack方法 确保addRoutes已完成
25 - }) 24 + });
26 - }).catch(err => { 25 + });
27 - Message.error(err)
28 - // store.dispatch('LogOut').then(() => {
29 - // // next({ path: '/' })
30 - // window.location.href = settings.loginURL;//wsso系统跳转
31 - // })
32 }) 26 })
27 + .catch((err) => {});
33 } else { 28 } else {
34 - next() 29 + next();
35 } 30 }
36 } 31 }
37 } else { 32 } else {
38 - removeToken() 33 + removeToken();
39 // 没有token 34 // 没有token
40 - //wsso登录时对后端重定向带来的token进行记录
41 - let token = location.search.split("token=")[1]
42 - if (token != undefined && token != '' && token != null) {
43 - setToken(token)
44 - next({ path: '/' })
45 - } else {
46 if (whiteList.indexOf(to.path) !== -1) { 35 if (whiteList.indexOf(to.path) !== -1) {
47 // 在免登录白名单,直接进入 36 // 在免登录白名单,直接进入
48 - next() 37 + next();
49 } else { 38 } else {
50 - window.location.href = settings.loginURL;//wsso系统跳转 39 + next(`/login?redirect=${to.fullPath}`); // 否则全部重定向到登录页
51 - }
52 } 40 }
53 } 41 }
54 -}) 42 +});
55 43
56 -router.afterEach(() => { 44 +router.afterEach(() => {});
57 -})
......