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