/**
 * @file 项目入口文件
 */
import Vue from 'vue'
import VueRouter from 'vue-router'
import Vuex from 'vuex'
import routes from './routes'
import store from './store'
import App from 'modules/app/index.vue'
import './landscape.js'
import './ipadLandscape.js'
import './common'
import './filters'
import 'styles/common.css'
import 'styles/commonStyle.css'

Vue.use(VueRouter)
Vue.use(Vuex)
import 'vant/es/toast/style';
import { Toast, Popup } from "vant";
Vue.use(Toast);
Vue.use(Popup);

// 配置发送请求拦截器,实现路由切换后取消之前的请求
let axiosPromiseArr = [];
import axios from 'axios'
axios.interceptors.request.use(config => {
  config.cancelToken = new axios.CancelToken(cancel => {
    axiosPromiseArr.push({ cancel });
  })
  return config;
}, err => {
  var error = { message: '网络异常,请刷新重试', err: err, type: 'requestError' };
  console.log(error);
  return Promise.reject(error);
})

var Router = new VueRouter({ routes });

Router.beforeEach((to, from, next) => {
  axiosPromiseArr.forEach((ele, index) => {
    ele.cancel();
    delete axiosPromiseArr[index];
  })
  next()
})

new Vue({
  el: '#app',
  render: h => h(App),
  router: Router,
  store: new Vuex.Store(store),
})