Former-commit-id: a98f0dc7f8c8202102557ec44a29081de09ef657 [formerly a98f0dc7f8c8202102557ec44a29081de09ef657 [formerly a98f0dc7f8c8202102557ec44a29081de09ef657 [formerly a98f0dc7f8c8202102557ec44a29081de09ef657 [formerly f244e1fdd164c1b79a79bb5a6b747ee86b9d8589 [formerly 9a88fe535b9d40bff1dcca1e9c312ab81c0961b5]]]]] Former-commit-id: 80f45f42407a12231dcb32861eae95da8b8f27d5 Former-commit-id: 294d0beb7890b73dd462900f6634b9ed43dda50b Former-commit-id: f639bbc1de8e27b18262e84545ff22b8556c402a [formerly 0f01b98c3d1b41eaa511bb56813d860105da930f] Former-commit-id: 9a33c6b83d309a76711c4fad397c149dac55a8b5 Former-commit-id: f556363312d2e505acc24ec531e787fc3863f9fc Former-commit-id: 4433f382bc7c25d437eabfab96e4a7b0dbca28b5 Former-commit-id: eb558eb22372f558e8d93ae8dac07c40016e2644 Former-commit-id: 963b8effbe52965ae14a77172a37c50dcfd6cf56
66 lines
1.5 KiB
JavaScript
Executable File
66 lines
1.5 KiB
JavaScript
Executable File
import Vue from 'vue'
|
|
import VueRouter from 'vue-router'
|
|
|
|
// 进度条
|
|
import NProgress from 'nprogress'
|
|
import 'nprogress/nprogress.css'
|
|
|
|
import store from '@/store/index'
|
|
|
|
import util from '@/libs/util.js'
|
|
|
|
// 路由数据
|
|
import routes from './routes'
|
|
|
|
Vue.use(VueRouter)
|
|
|
|
// 导出路由 在 main.js 里使用
|
|
const router = new VueRouter({
|
|
routes
|
|
})
|
|
|
|
/**
|
|
* 路由拦截
|
|
* 权限验证
|
|
*/
|
|
router.beforeEach((to, from, next) => {
|
|
// 进度条
|
|
NProgress.start()
|
|
// 关闭搜索面板
|
|
store.commit('d2admin/search/set', false)
|
|
// 验证当前路由所有的匹配中是否需要有登录验证的
|
|
if (to.matched.some(r => r.meta.requiresAuth)) {
|
|
// 这里暂时将cookie里是否存有token作为验证是否登录的条件
|
|
// 请根据自身业务需要修改
|
|
const token = util.cookies.get('token')
|
|
if (token && token !== 'undefined') {
|
|
next()
|
|
} else {
|
|
// 将当前预计打开的页面完整地址临时存储 登录后继续跳转
|
|
// 这个 cookie(redirect) 会在登录后自动删除
|
|
util.cookies.set('redirect', to.fullPath)
|
|
// 没有登录的时候跳转到登录界面
|
|
next({
|
|
name: 'login'
|
|
})
|
|
}
|
|
} else {
|
|
// 不需要身份校验 直接通过
|
|
next()
|
|
}
|
|
})
|
|
|
|
router.afterEach(to => {
|
|
// 进度条
|
|
NProgress.done()
|
|
// 需要的信息
|
|
const app = router.app
|
|
const { name, params, query } = to
|
|
// 多页控制 打开新的页面
|
|
app.$store.dispatch('d2admin/page/open', { name, params, query })
|
|
// 更改标题
|
|
util.title(to.meta.title)
|
|
})
|
|
|
|
export default router
|