1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- /**
- * 全站权限配置
- *
- */
- import router from './router/router'
- import store from '@/store'
- import { validatenull } from '@/util/validate'
- import NProgress from 'nprogress' // progress bar
- import 'nprogress/nprogress.css' // progress bar style
- NProgress.configure({ showSpinner: false })
- router.beforeEach((to, from, next) => {
- NProgress.start()
- const meta = to.meta || {}
- if (store.getters.access_token) {
- if (store.getters.isLock && to.path !== '/lock') {
- next({ path: '/lock' })
- } else if (to.path === '/login') {
- next({ path: '/' })
- } else {
- const value = to.query.src || to.fullPath
- const label = to.query.name || to.name
- if (meta.isTab !== false && !validatenull(value) && !validatenull(label)) {
- store.commit('ADD_TAG', {
- label: label,
- value: value,
- params: to.params,
- query: to.query,
- group: router.$avueRouter.group || []
- })
- }
- next()
- }
- } else {
- const specialPath = store.getters.specialPath
- const pathQuery = { path: '/login' }
- if (specialPath !== 'default') pathQuery.query = { s: specialPath }
- if (meta.isAuth === false) {
- next()
- } else {
- next(pathQuery)
- }
- }
- })
- router.afterEach(() => {
- NProgress.done()
- const title = store.getters.tag.label
- router.$avueRouter.setTitle(title)
- })
|