2017-06-26 13:38:24 +08:00
|
|
|
// 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'
|
2017-06-26 18:03:05 +08:00
|
|
|
import ElementUI from 'element-ui'
|
2017-06-26 13:38:24 +08:00
|
|
|
import 'element-ui/lib/theme-default/index.css'
|
|
|
|
import NProgress from 'nprogress'
|
2017-06-26 18:03:05 +08:00
|
|
|
import 'normalize.css/normalize.css'
|
|
|
|
import '@/assets/iconfont/iconfont'
|
|
|
|
import IconSvg from '@/components/Icon-svg/index.vue'
|
2017-06-26 13:38:24 +08:00
|
|
|
|
|
|
|
Vue.config.productionTip = false
|
|
|
|
|
|
|
|
Vue.use(ElementUI);
|
2017-06-26 18:03:05 +08:00
|
|
|
Vue.component('icon-svg', IconSvg)
|
2017-06-26 13:38:24 +08:00
|
|
|
|
2017-06-26 18:03:05 +08:00
|
|
|
const whiteList = ['/login'];
|
2017-06-26 15:43:11 +08:00
|
|
|
router.beforeEach((to, from, next) => {
|
2017-06-26 18:03:05 +08:00
|
|
|
NProgress.start();
|
|
|
|
if (store.getters.token) {
|
2017-06-26 15:43:11 +08:00
|
|
|
if (to.path === '/login') {
|
|
|
|
next({ path: '/' });
|
|
|
|
} else {
|
2017-06-26 18:03:05 +08:00
|
|
|
if (store.getters.roles.length === 0) {
|
|
|
|
store.dispatch('GetInfo').then(res => {
|
2017-06-26 15:43:11 +08:00
|
|
|
const roles = res.data.role;
|
2017-06-26 18:03:05 +08:00
|
|
|
store.dispatch('GenerateRoutes', { roles }).then(() => {
|
|
|
|
router.addRoutes(store.getters.addRouters)
|
|
|
|
next(to.path);
|
2017-06-26 15:43:11 +08:00
|
|
|
})
|
|
|
|
}).catch(err => {
|
|
|
|
console.log(err);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2017-06-26 18:03:05 +08:00
|
|
|
if (whiteList.indexOf(to.path) !== -1) {
|
2017-06-26 15:43:11 +08:00
|
|
|
next()
|
|
|
|
} else {
|
2017-06-26 18:03:05 +08:00
|
|
|
next('/login');
|
2017-06-26 15:43:11 +08:00
|
|
|
NProgress.done();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2017-06-26 13:38:24 +08:00
|
|
|
|
2017-06-26 15:43:11 +08:00
|
|
|
router.afterEach(() => {
|
|
|
|
NProgress.done();
|
|
|
|
});
|
2017-06-26 13:38:24 +08:00
|
|
|
|
|
|
|
new Vue({
|
|
|
|
el: '#app',
|
|
|
|
router,
|
|
|
|
store,
|
|
|
|
template: '<App/>',
|
|
|
|
components: { App }
|
|
|
|
})
|