import babelpolyfill from 'babel-polyfill'           //可以将es6代码转为es5代码,从而可以在现有环境执行
import Vue from 'vue'
import App from './App'
import ElementUI from 'element-ui'                   //element-ui插件  

//import 'element-ui/lib/theme-default/index.css'    //另外的一个主题
import './assets/theme/theme-green/index.css'        //更改主题

import VueRouter from 'vue-router'                   //路由文件
import store from './vuex/store'                     //状态态管理
import Vuex from 'vuex'
//import NProgress from 'nprogress'
//import 'nprogress/nprogress.css'
import routes from './routes'                        //路由文件
import Mock from './mock'
Mock.bootstrap();

import 'font-awesome/css/font-awesome.min.css'       //引入字体文件


import Api from './api/index.js';                    //封装的请求文件
Vue.prototype.$api = Api;                            

Vue.use(ElementUI)
Vue.use(VueRouter)
Vue.use(Vuex)




//NProgress.configure({ showSpinner: false });

const router = new VueRouter({
      routes
})





//路由之间跳转的判断
router.beforeEach((to, from, next) => {
  //NProgress.start();
  if (to.path == '/login') {
     sessionStorage.removeItem('user');    //移除user
     sessionStorage.removeItem('authKey');    //移除user
  }

  let user = JSON.parse(sessionStorage.getItem('user'));   //解析出来user
  let authKey = JSON.parse(sessionStorage.getItem('authKey'));
  // 如果用户不存在并且所去的地方不是登录界面，那么就到登录界面  
  if (!authKey &&!user && to.path != '/login') {

     next({ path: '/login' });

  } else {

     next();

  }

})

//router.afterEach(transition => {
//NProgress.done();
//});


new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')

