Former-commit-id: a28520c4330a394d35edc48f7ff5181513dadc42 [formerly 471e70972dbb5e8c59e64097ce2585da07cea784] [formerly a28520c4330a394d35edc48f7ff5181513dadc42 [formerly 471e70972dbb5e8c59e64097ce2585da07cea784] [formerly a28520c4330a394d35edc48f7ff5181513dadc42 [formerly 471e70972dbb5e8c59e64097ce2585da07cea784] [formerly 471e70972dbb5e8c59e64097ce2585da07cea784 [formerly 1ff3b72ad5d7094c846242261e0b12814e6de086 [formerly 13a4f2546e356a8ee719227e8ae99f18e8552d65]]]]] Former-commit-id: 7c0fbbdd9d75b284329842910a1454f5cef1e316 Former-commit-id: 4ba68630c0d80447702dcf7435fcee5057b7df36 Former-commit-id: 38abdedf2c95c886656e3cac073fe36e17d8efc9 [formerly aa5f1d60ef2c8990ba40166586d7c269fc5ba95f] Former-commit-id: dc4e0d5ae0425ddd85f4f23fc606e00189cd3e57 Former-commit-id: 9af3dc8b3b220ac21e2a0e33d8b1707c792509a7 Former-commit-id: 793274c7fdefe32a9a2892aaf5fc96c45d50b20a Former-commit-id: f33df504bc31baf86bffea2fd79a6a0648d9507d Former-commit-id: b063e631c4e892e5f48bb5d2357d44cfcb509cac
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.auth)) {
|
|
// 这里暂时将cookie里是否存有token作为验证是否登录的条件
|
|
// 请根据自身业务需要修改
|
|
const token = util.cookies.get('token')
|
|
if (token && token !== 'undefined') {
|
|
next()
|
|
} else {
|
|
// 没有登录的时候跳转到登录界面
|
|
// 携带上登陆成功之后需要跳转的页面完整路径
|
|
next({
|
|
name: 'login',
|
|
query: {
|
|
redirect: to.fullPath
|
|
}
|
|
})
|
|
// https://github.com/d2-projects/d2-admin/issues/138
|
|
NProgress.done()
|
|
}
|
|
} else {
|
|
// 不需要身份校验 直接通过
|
|
next()
|
|
}
|
|
})
|
|
|
|
router.afterEach(to => {
|
|
// 进度条
|
|
NProgress.done()
|
|
// 多页控制 打开新的页面
|
|
store.dispatch('d2admin/page/open', to)
|
|
// 更改标题
|
|
util.title(to.meta.title)
|
|
})
|
|
|
|
export default router
|