| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 | import router from './router'import store from './store'import { Message } from 'element-ui'import NProgress from 'nprogress' // progress barimport 'nprogress/nprogress.css' // progress bar styleimport { getToken } from '@/utils/auth' // get token from cookieimport getPageTitle from '@/utils/get-page-title'import Cookies from 'js-cookie';NProgress.configure({ showSpinner: false }) // NProgress Configurationconst whiteList = ['/login'] // no redirect whitelistrouter.beforeEach(async(to, from, next) => {    // start progress bar    NProgress.start()        // set page title    document.title = getPageTitle(to.meta.title)        //next();    NProgress.done()    const hasToken = getToken();    const jId = Cookies.get('JSESSSIONID');    if (hasToken) {        if (!jId) {            store.dispatch('user/setJsessionId').then(res => {                if (to.path === '/login') {                    // if is logged in, redirect to the home page                    next({ path: '/' })                    NProgress.done()                } else {                    try {                        next()                    } catch (error) {                        Message.error(error || 'Has Error')                        next(`/login?redirect=${to.path}`)                        NProgress.done()                    }                }            })        } else {            if (to.path === '/login') {                // if is logged in, redirect to the home page                next({ path: '/' })                NProgress.done()            } else {                try {                    next()                } catch (error) {                    Message.error(error || 'Has Error')                    next(`/login?redirect=${to.path}`)                    NProgress.done()                }            }        }    } else {        /* has no token*/        if (whiteList.indexOf(to.path) !== -1) {            // in the free login whitelist, go directly            next()        } else {            // other pages that do not have permission to access are redirected to the login page.            next(`/login?redirect=${to.path}`)            NProgress.done()        }    }})router.afterEach(() => {    // finish progress bar    NProgress.done()})
 |