import Vue from 'vue'
import axios from 'axios'
import i18n from '@/locale';
import router from './router/index'
import store from './store'
import { sync } from 'vuex-router-sync'
import App from './components/app-root'
import { FontAwesomeIcon } from './icons'
//import iView from 'iview';
//import 'iview/dist/styles/iview.css';
import ViewUI from 'view-design';
import 'view-design/dist/styles/iview.css';
import commons from "@/utils/public.js";
import apiTools from '@/api';
import mockTools from '@/mock';
import { fetch, post } from '@/filters/http';
import VideoPlayer from 'vue-video-player';
import jwtDecode from 'jwt-decode';
import Loading from '@/common/Loading';
import BaseChangeLine from '@/components/student-analysis/total/BaseChangeLine.vue'

require('video.js/dist/video-js.css');
require('vue-video-player/src/custom-theme.css');
Vue.use(VideoPlayer);
Vue.use(Loading);

Vue.component('BaseChangeLine', BaseChangeLine);

//新添加的
import vuescroll from 'vue-scroll'
import echarts from 'echarts'

//全局API请求
Vue.prototype.$api = apiTools;
Vue.prototype.$post = post;
Vue.prototype.$get = fetch;

//mock数据工具
Vue.prototype.$Mock = mockTools;

Vue.prototype.$jwtDecode = jwtDecode;

Vue.use(vuescroll)
Vue.prototype.$echarts = echarts

//ZXJ
Vue.prototype.common = commons;

// Registration of global components
Vue.component('icon', FontAwesomeIcon); 

const _import = require('./router/_import_file.js')//获取组件的方法
var getRouter //用来获取后台拿到的路由

// 動態加路由
//if(!getRouter){
//  if (!getObjArr('router')) {
//    axios.get('/api/testAPI/GetTestAuth').then(res =>{  
//      getRouter = res.data.data;
//      saveObjArr('router', getRouter) //存储路由到localStorage
//      getRouter = filterAsyncRouter(getRouter) //过滤路由
//      // 存入vuex
//      store.state.authorization.antRouter = getRouter;
//      router.addRoutes(getRouter) //动态添加路由
//    });    
//  } else {
//    getRouter = getObjArr('router')//拿到路由
//    getRouter = filterAsyncRouter(getRouter) //过滤路由
//    // 存入vuex
//    store.state.authorization.antRouter = getRouter;
//    router.addRoutes(getRouter) //动态添加路由
//  }
//}

router.beforeEach((to, from, next) => {  
  document.body.scrollTop = 0;
  next();
});

function saveObjArr(name, data) { // 存储数组对象的方法
  sessionStorage.setItem(name, JSON.stringify(data))
}

function getObjArr(name) { // 获取数组对象的方法
  return JSON.parse(window.sessionStorage.getItem(name));
}

//function filterAsyncRouter(routers){
//  let newRouter = [];
//  routers.forEach(function(item){
//    let page = {//}
//      name: '',
//      path: '',
//      component: '',
//      meta:{
//        access:[]
//      }
//    };
//    page.name = item.component;
//    page.path = item.path;
//    page.meta.access = item.access;
//    page.component = _import(item.component);
//    newRouter.push(page)
//  }); 
//  return newRouter;


router.afterEach((to, from, next) => {
  document.body.scrollTop = 0;
});




Vue.use(ViewUI, {
  i18n: (key, value) => i18n.t(key, value)
})

sync(store, router)

const app = new Vue({
  store,
  router,
  i18n,
  ...App
})

export {
  app
}
