halo-admin/src/permission.js

41 lines
1.0 KiB
JavaScript
Raw Normal View History

2019-03-20 12:22:52 +00:00
import Vue from 'vue'
import router from './router'
import store from './store'
2019-05-23 14:42:37 +00:00
import { setDocumentTitle, domTitle } from '@/utils/domUtil'
2019-03-20 12:22:52 +00:00
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
NProgress.configure({ showSpinner: false }) // NProgress Configuration
2019-04-30 03:18:03 +00:00
const whiteList = ['Login', 'Install', 'NotFound'] // no redirect whitelist
2019-03-20 12:22:52 +00:00
router.beforeEach((to, from, next) => {
2019-04-30 03:18:03 +00:00
NProgress.start()
2019-05-23 14:42:37 +00:00
to.meta && (typeof to.meta.title !== 'undefined' && setDocumentTitle(`${to.meta.title} - ${domTitle}`))
2019-04-30 03:18:03 +00:00
Vue.$log.debug('Token', store.getters.token)
if (store.getters.token) {
if (to.name === 'Login') {
next({ name: 'Dashboard' })
2019-03-20 12:22:52 +00:00
NProgress.done()
2019-04-30 03:18:03 +00:00
return
2019-03-20 12:22:52 +00:00
}
2019-04-30 03:18:03 +00:00
// TODO Get installation status
2019-03-20 12:22:52 +00:00
2019-04-30 03:18:03 +00:00
next()
2019-04-30 03:36:22 +00:00
NProgress.done()
2019-04-30 03:18:03 +00:00
return
}
2019-03-20 12:22:52 +00:00
2019-04-30 03:18:03 +00:00
// Not login
// Check whitelist
if (whiteList.includes(to.name)) {
next()
2019-04-30 03:36:22 +00:00
NProgress.done()
2019-04-30 03:18:03 +00:00
return
2019-03-20 12:22:52 +00:00
}
2019-04-30 03:18:03 +00:00
next({ name: 'Login', query: { redirect: to.fullPath } })
NProgress.done()
})