12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- import Vue from 'vue'
- import router from './router'
- import store from './store'
- import NProgress from 'nprogress'
- import 'nprogress/nprogress.css'
- import notification from 'ant-design-vue/es/notification'
- import { ACCESS_TOKEN } from '@/store/mutation-types'
- import { generateIndexRouter } from "@/utils/util"
- NProgress.configure({ showSpinner: false })
- const whiteList = ['/user/login', '/user/register', '/user/register-result','/user/alteration','/activiti/commencementSchedule','/automaticLogin','/redirect/login','/redirect/login/try','/index']
- router.beforeEach((to, from, next) => {
- NProgress.start()
- if (Vue.ls.get(ACCESS_TOKEN)) {
-
- if (to.path === '/user/login') {
- next({ path: '/dashboard/workplace' })
- NProgress.done()
- } else {
- if (store.getters.permissionList.length === 0) {
- store.dispatch('GetPermissionList').then(res => {
- const menuData = res.result.menu;
- console.log(res.message)
- if (menuData === null || menuData === "" || menuData === undefined) {
- return;
- }
- let constRoutes = [];
- constRoutes = generateIndexRouter(menuData);
-
- store.dispatch('UpdateAppRouter', { constRoutes }).then(() => {
-
-
- router.addRoutes(store.getters.addRouters)
- const redirect = decodeURIComponent(from.query.redirect || to.path)
- if (to.path === redirect) {
-
- next({ ...to, replace: true })
- } else {
-
- next({ path: redirect })
- }
- })
- })
- .catch(() => {
-
- store.dispatch('Logout').then(() => {
- next({ path: '/user/login', query: { redirect: to.fullPath } })
- })
- })
- } else {
- next()
- }
- }
- } else {
- if (whiteList.indexOf(to.path) !== -1) {
-
- next()
- } else {
- next({ path: '/user/login', query: { redirect: to.fullPath } })
- NProgress.done()
- }
- }
- })
- router.afterEach(() => {
- NProgress.done()
- })
|