// 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 ElementUI from 'element-ui'

import './assets/styles/reset.css'
import './assets/styles/common.css'
import 'animate.css'
// import 'element-ui/lib/theme-chalk/index.css'
import qs from 'qs'
import store from './store'
import Axios from 'axios'
import * as filters from './filters'
// 引入echarts
import echarts from 'echarts'
import VCharts from 'v-charts'

import plugins from './plugin'

Vue.use(VCharts)
Axios.defaults.withCredentials = true // 让ajax携带cookie

// const AUTH_TOKEN =
// 'normal-template-group-id=; cur_menu_index=2,0,0; JSESSIONID=B2F75494E6A8EE17E02290C6BB416CD5; UM_distinctid=166ccdf0e5f70d-05e2e61a01177d-b79193d-1fa400-166ccdf0e6036f; CNZZDATA1259419277=1964719690-1541039590-http%253A%252F%252Ftestcenter.bigaka.net%252F%7C1541039590; Hm_lvt_e2d87cf3717dbcd37c38af18128178c1=1541035458,1541125643,1541400895; CNZZDATA1263189240=393444180-1541032734-http%253A%252F%252Ftestcenter.bigaka.net%252F%7C1541399561; Hm_lpvt_e2d87cf3717dbcd37c38af18128178c1=1541404581; token=QuY4MdyNXUjnOSmTTn17apD9vxc'
// const AUTH_TOKEN = 'QuY4MdyNXUjnOSmTTn17apD9vxc'
// Axios.defaults.headers.common['Authorization'] = AUTH_TOKEN
// Axios.defaults.headers.common['Cookie'] = AUTH_TOKEN

Axios.interceptors.request.use(
  config => {
    if (config.method === 'post') {
      config.data = qs.stringify(config.data)
      config.headers['Content-Type'] = 'application/x-www-form-urlencoded'
    }
    return config
  },
  error => {
    return Promise.reject(error)
  }
)

Vue.use(ElementUI)

Object.keys(plugins).forEach(key => {
  const plugin = plugins[key]
  Vue.use(plugin)
})

Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.config.productionTip = false
Vue.prototype.axios = Axios
Vue.prototype.$echarts = echarts

Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
