import Vue from 'vue'
import App from './App.vue'
import Storage from 'vue-ls'
import router from './router'
import store from './store/'

import {
  VueAxios
} from "@/utils/request"

import Antd from 'ant-design-vue'
import Viser from 'viser-vue'
import 'ant-design-vue/dist/antd.less'; // or 'ant-design-vue/dist/antd.less'

import '@/permission' // permission control
import '@/utils/filter' // base filter
import {
  getAction,
  postFormAction,
  postAction
} from "@/api/manage"
// import Print from 'vue-print-nb-jeecg'
/*import '@babel/polyfill'*/
import VueApexCharts from 'vue-apexcharts'
import preview from 'vue-photo-preview'
import 'vue-photo-preview/dist/skin.css'

import VuePreview from 'vue-preview';
import promiseFinally from 'promise.prototype.finally';
promiseFinally.shim();
import directive from './directive'
import filters from './filters'
Vue.use(directive)
Vue.use(filters)
import md5 from 'blueimp-md5';

import Print from 'vue-print-nb';
// Vue.use(print)

// // import KFormDesign from 'k-form-design'
// import KFormDesign from 'k-form-design/lib/k-form-design-mini.umd.min'
// import 'k-form-design/styles/k-form-design.less'
// // import 'k-form-design/lib/k-form-design.css'
// Vue.use(KFormDesign)
import 'ant-design-vue/dist/antd.less';
import '@/styles/index.less'
import VueLazyload from 'vue-lazyload'
Vue.use(VueLazyload, {
  preLoad: 1,
  loading: require('@assets/img/default.png')
})
Vue.prototype.$md5 = md5;
import {
  ACCESS_TOKEN,
  DEFAULT_COLOR,
  DEFAULT_THEME,
  DEFAULT_LAYOUT_MODE,
  DEFAULT_COLOR_WEAK,
  SIDEBAR_TYPE,
  DEFAULT_FIXED_HEADER,
  DEFAULT_FIXED_HEADER_HIDDEN,
  DEFAULT_FIXED_SIDEMENU,
  DEFAULT_CONTENT_WIDTH_TYPE,
  DEFAULT_MULTI_PAGE
} from "@/store/mutation-types"
import config from '@/defaultSettings'

import JDictSelectTag from './components/dict/index.js'
import hasPermission from '@/utils/hasPermission'
import vueBus from '@/utils/vueBus';


import '@/components/vend-ztree.all.js'
import JeecgComponents from '@/components/jeecg/index'
// import iView from 'iview'
import '!style-loader!css-loader!less-loader!./theme/index.less'

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);
import {
  getDay,
  allWeeks
} from '@/utils/getDay.js'

import * as WPS from './assets/jwps.es6'
Vue.prototype.wps = WPS;

import Icon from '@base/mm-icon/mm-icon'
import mmToast from '@base/mm-toast'
Vue.component(Icon.name, Icon)
Vue.use(mmToast)

Vue.prototype.$getDay = getDay
Vue.prototype.allWeeks = allWeeks

Vue.config.productionTip = false
// Vue.use(iView)
Vue.use(Storage, config.storageOptions)
Vue.use(Antd)
Vue.use(VueAxios, router)
Vue.use(Viser)
Vue.use(hasPermission)
Vue.use(JDictSelectTag)
Vue.use(Print)
Vue.use(VueApexCharts)
Vue.component('apexchart', VueApexCharts)
Vue.use(preview)
Vue.use(vueBus);
Vue.use(JeecgComponents);
Vue.use(VuePreview);
Vue.prototype.doMian = "http://139.186.31.213:8804/jeecg-boot";
Vue.prototype.postFormAction = postFormAction;
Vue.prototype.postDataAction = postAction;
Vue.prototype.getAction = getAction;

Vue.prototype.cancel = function () {
  let cancelArr = window.axiosCancel
  cancelArr = cancelArr || [] //判断空值
  cancelArr.forEach((ele, index) => {
    ele.cancel('取消了请求') // 在失败函数中返回这里自定义的错误信息
    delete window.axiosCancel[index]
  })
}

Vue.prototype.allMoney = function (num, n) {
  n = n || 2;
  let symbol = ",";
  if (num === null) return num;
  if (typeof num !== "number")
    throw new TypeError("num参数应该是一个number类型");
  if (n < 0) throw new Error("参数n不应该小于0");
  let hasDot = parseInt(num) != num; //这里检测num是否为小数，true表示小数
  let m = n != undefined && n != null ? n : 1;
  num =
    m == 0
      ? num.toFixed(m) + "."
      : hasDot
        ? n
          ? num.toFixed(n)
          : num
        : num.toFixed(m);
  symbol = symbol || ",";
  num = num
    .toString()
    .replace(/(\d)(?=(\d{3})+\.)/g, function (match, p1, p2) {
      return p1 + symbol;
    });
  if (n == 0 || (!hasDot && !n)) {
    //如果n为0或者传入的num是整数并且没有指定整数的保留位数，则去掉前面操作中的小数位
    num = num.substring(0, num.indexOf("."));
  }
  return num;
}
new Vue({
  router,
  store,
  mounted() {
    store.commit('SET_SIDEBAR_TYPE', Vue.ls.get(SIDEBAR_TYPE, true))
    store.commit('TOGGLE_THEME', Vue.ls.get(DEFAULT_THEME, config.navTheme))
    store.commit('TOGGLE_LAYOUT_MODE', Vue.ls.get(DEFAULT_LAYOUT_MODE, config.layout))
    store.commit('TOGGLE_FIXED_HEADER', Vue.ls.get(DEFAULT_FIXED_HEADER, config.fixedHeader))
    store.commit('TOGGLE_FIXED_SIDERBAR', Vue.ls.get(DEFAULT_FIXED_SIDEMENU, config.fixSiderbar))
    store.commit('TOGGLE_CONTENT_WIDTH', Vue.ls.get(DEFAULT_CONTENT_WIDTH_TYPE, config.contentWidth))
    store.commit('TOGGLE_FIXED_HEADER_HIDDEN', Vue.ls.get(DEFAULT_FIXED_HEADER_HIDDEN, config.autoHideHeader))
    store.commit('TOGGLE_WEAK', Vue.ls.get(DEFAULT_COLOR_WEAK, config.colorWeak))
    store.commit('TOGGLE_COLOR', Vue.ls.get(DEFAULT_COLOR, config.primaryColor))
    store.commit('SET_TOKEN', Vue.ls.get(ACCESS_TOKEN))
    store.commit('SET_MULTI_PAGE', Vue.ls.get(DEFAULT_MULTI_PAGE, true))
  },
  render: h => h(App)
}).$mount('#app')