You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.4 KiB
JavaScript

8 years ago
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
8 years ago
import ElementUI from 'element-ui'
8 years ago
import 'element-ui/lib/theme-default/index.css'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
8 years ago
import 'normalize.css/normalize.css'
import '@/assets/iconfont/iconfont'
import IconSvg from '@/components/Icon-svg/index.vue'
import { getToken } from '@/utils/auth'
8 years ago
Vue.config.productionTip = false
Vue.use(ElementUI);
8 years ago
Vue.component('icon-svg', IconSvg)
8 years ago
8 years ago
const whiteList = ['/login'];
8 years ago
router.beforeEach((to, from, next) => {
8 years ago
NProgress.start();
if (getToken()) {
8 years ago
if (to.path === '/login') {
next({ path: '/' });
} else {
8 years ago
if (store.getters.roles.length === 0) {
store.dispatch('GetInfo').then(res => {
8 years ago
const roles = res.data.role;
8 years ago
store.dispatch('GenerateRoutes', { roles }).then(() => {
8 years ago
router.addRoutes(store.getters.addRouters);
next({ ...to });
8 years ago
})
8 years ago
})
8 years ago
} else {
next();
}
}
} else {
8 years ago
if (whiteList.indexOf(to.path) !== -1) {
8 years ago
next()
} else {
8 years ago
next('/login');
8 years ago
NProgress.done();
}
}
});
8 years ago
8 years ago
router.afterEach(() => {
NProgress.done();
});
8 years ago
new Vue({
el: '#app',
router,
store,
template: '<App/>',
components: { App }
})