123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- 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/todo', '/user/register', '/user/register-result', '/user/alteration']
- router.beforeEach((to, from, next) => {
- NProgress.start()
- if (Vue.ls.get(ACCESS_TOKEN)) {
-
- if (to.path === '/user/login') {
-
- next({ path: '/user/todo' })
- NProgress.done()
- } else {
- if (store.getters.permissionList.length === 0) {
- store
- .dispatch('GetPermissionList')
- .then(res => {
- const menuData = res.result.menu
- console.log('res.maessage:', 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()
- })
|