Former-commit-id: cbc33a78c59c6468df3e905a1bc1f5c513abf804 [formerly cbc33a78c59c6468df3e905a1bc1f5c513abf804 [formerly cbc33a78c59c6468df3e905a1bc1f5c513abf804 [formerly cbc33a78c59c6468df3e905a1bc1f5c513abf804 [formerly 66e615a1681dbb8ff72633fc3d53cbf5411610f5 [formerly 449c1c2a13a19d6d52537b97c18548c012b360dd]]]]] Former-commit-id: 2a7a63bce617f5acaf5c1e4b13455f001f69118d Former-commit-id: 49a1453a0343e1e52cbb1b7faf1d18ffbb0ae519 Former-commit-id: d303a906c5a794ef68376044fb6d9c578e9e85c9 [formerly bc51b43eaa43b3d1744d7edc36d605a6d3d0cd2e] Former-commit-id: 8867f09a27c99223dfd2cb5e66b2b25ca75b49d9 Former-commit-id: 2f01e346f3474822a2ec1f50e02ffcce05dce8a8 Former-commit-id: 8f68a3470559ea51ee3ab7617347eb0236b607f1 Former-commit-id: dbcf55c5cfcb9f52dc8705397a2423f790d7ed82 Former-commit-id: 58abe040aadabc72c1db5acef2f45a7f30874614
66 lines
1.6 KiB
JavaScript
Executable File
66 lines
1.6 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, fullPath } = to
|
|
// 多页控制 打开新的页面
|
|
app.$store.dispatch('d2admin/page/open', { name, params, query, fullPath })
|
|
// 更改标题
|
|
util.title(to.meta.title)
|
|
})
|
|
|
|
export default router
|