12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- 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,INDEX_MAIN_PAGE_PATH, OAUTH2_LOGIN_PAGE_PATH } from '@/store/mutation-types'
- import { generateIndexRouter, isOAuth2AppEnv } from '@/utils/util'
- NProgress.configure({ showSpinner: false })
- const whiteList = ['/user/login', '/user/register', '/user/register-result','/user/alteration']
- whiteList.push(OAUTH2_LOGIN_PAGE_PATH)
- router.beforeEach((to, from, next) => {
- NProgress.start()
- if (Vue.ls.get(ACCESS_TOKEN)) {
-
- if (to.path === '/user/login' || to.path === OAUTH2_LOGIN_PAGE_PATH) {
- next({ path: INDEX_MAIN_PAGE_PATH })
- NProgress.done()
- } else {
- if (store.getters.permissionList.length === 0) {
- store.dispatch('GetPermissionList').then(res => {
- const menuData = res.result.menu;
-
- 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) {
-
- if (to.path === '/user/login' && isOAuth2AppEnv()) {
- next({path: OAUTH2_LOGIN_PAGE_PATH})
- } else {
-
- next()
- }
- NProgress.done()
- } else {
-
- let path = isOAuth2AppEnv() ? OAUTH2_LOGIN_PAGE_PATH : '/user/login'
- next({ path: path, query: { redirect: to.fullPath } })
- NProgress.done()
- }
- }
- })
- router.afterEach(() => {
- NProgress.done()
- })
|