import Vue from 'vue'

import 'normalize.css/normalize.css'// A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import locale from 'element-ui/lib/locale/lang/zh-CN' // lang i18n
import VCharts from 'v-charts'

import '@/styles/index.scss' // global css

import App from './App'
import router from './router'
import store from './store'

import '@/icons' // icon
import '@/permission' // permission control

Vue.use(ElementUI, { locale })
Vue.use(VCharts)

Vue.config.productionTip = false


// 将selects全局混入当前vue实例中
Vue.mixin({
  methods: {
    isNumber(val, max) {
      // 只能输入正整数，且可以限制最大值，用法：@input="e => (form.cloud_room_up_limit = isNumber(e, 7))"
      val = val.replace(/\b(0+)+[^0-9]*/gi, "");
      if (val > max) {
        val = max;
      }
      return val;
    },
    keyupEvent(e) {
      // 正数，小数2位 @keyup.native='keyupEvent($event)'
      e.target.value = e.target.value.replace(/[^\d.]/g, "");
      e.target.value = e.target.value.replace(/\.{2,}/g, ".");
      e.target.value = e.target.value.replace(/^\./g, "0.");
      e.target.value = e.target.value.replace(
        /^\d*\.\d*\./g,
        e.target.value.substring(0, e.target.value.length - 1)
      );
      e.target.value = e.target.value.replace(/^0[^\.]+/g, "0");
      e.target.value = e.target.value.replace(/^(\d+)\.(\d\d).*$/, "$1.$2");
    },
    changeHash(value) {
      const origin = window.location.origin;
      history.replaceState(
        "",
        "",
        `${origin}/#${this.$route.path}?opt=${value}`
      );
    },
  }
});


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