// 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 '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 * as plugins from './plugin'
// Axios.defaults.baseURL = 'http://testcenter.bigaka.net/crm'

const AUTH_TOKEN = 'X8IvNcvIe7xFvbNhk0I5HyVZY1E'
Axios.defaults.withCredentials = true // 让ajax携带cookie
Axios.defaults.headers.common['Authorization'] = 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)
Vue.use(plugins)

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/>'
})
