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-07-14 14:02:16 +08:00
|
|
|
import 'nprogress/nprogress.css'
|
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-07-20 14:27:47 +08:00
|
|
|
import { getToken } from '@/utils/auth'
|
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();
|
2017-07-20 14:27:47 +08:00
|
|
|
if (getToken()) {
|
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(() => {
|
2017-07-04 16:13:02 +08:00
|
|
|
router.addRoutes(store.getters.addRouters);
|
|
|
|
next({ ...to });
|
2017-06-26 15:43:11 +08:00
|
|
|
})
|
2017-07-03 14:40:33 +08:00
|
|
|
})
|
2017-06-26 15:43:11 +08:00
|
|
|
} 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 }
|
|
|
|
})
|