import Vue from 'vue'
import App from './App.vue'
//引入 路由 vuex
import router from '@/router'
import store from '@/store'

import './element'
/* 语言转换 */
import VueI18n from 'vue-i18n'
Vue.use(VueI18n)

const i18n = new VueI18n({
  locale: 'en-US', // 语言标识
  //this.$i18n.locale // 通过切换locale的值来实现语言切换
  messages: {
    'zh-CN': require('./common/lang/zh'), // 中文语言包
    'en-US': require('./common/lang/en') // 英文语言包
  }
})

//引入element-ui 组件实现过度动画
import 'element-ui/lib/theme-chalk/base.css';
import CollapseTransition from 'element-ui/lib/transitions/collapse-transition';
Vue.component(CollapseTransition.name, CollapseTransition)

Vue.filter('returnFloat', function (value) {
  var value = Math.round(parseFloat(value) * 100) / 100;
  var xsd = value.toString().split(".");
  if (xsd.length == 1) {
    if (isNaN(value.toString()) || value.toString() == null) {
      return 0
    } else {
      value = value.toString() + ".0";
      return value;
    }
  }
  if (xsd.length > 1) {

    return value;
  }
})
/*  */
Vue.filter('baifengbi', function (value) {
  if (value == null) {
    return 0
  } else {
    return value.toFixed(2)
  }
})


//统一接口api文件夹里面的全部请求函数
import * as API from '@/api'
import '@/utils/flexble'

/* 防抖 */
/* Vue.prototype.$on = function (event, func) {
  let timer
  let newFunc = func
  if (event === 'click') {
    newFunc = function () {
      clearTimeout(timer)
      timer = setTimeout(function () {
        func.apply(this, arguments)
      }, 500)
    }
  }
  on.call(this, event, newFunc)
} */
// 节流
const on = Vue.prototype.$on
Vue.prototype.$on = function (event, func) {
  let previous = 0
  let newFunc = func
  if (event === 'click') {
    newFunc = function () {
      const now = new Date().getTime()
      if (previous + 1000 <= now) {
        func.apply(this, arguments)
        previous = now
      }
    }
  }
  on.call(this, event, newFunc)
}


import Moment from 'moment'
Vue.prototype.moment = Moment


Vue.config.productionTip = false
new Vue({
  render: h => h(App),
  router,
  i18n,
  store,
  beforeCreate() {
    Vue.prototype.$bus = this;
    Vue.prototype.$API = API;
  }
}).$mount('#app')