/*
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2018-10-08 10:45:05
 * @LastEditors: 无尘
 * @LastEditTime: 2020-05-28 20:34:08
 */
import 'babel-polyfill';
import promise from 'es6-promise';
promise.polyfill();
import App from './App';
import router from './router';
import store from './store/store';
import directives from '@/components/utils/directives';
/* eslint-disable  */
import './assets/font/iconfont.css'
import './assets/gic后台font/iconfont.css'
import '../static/css/index.less';
import '../theme/index.css';

import '../static/css/dialog.css';
import filters from './filters/index.js';

import SvgIcon from "./components/common/svg-icon"
Vue.component("svg-icon", SvgIcon)

import vueOfficeHeader from '@gic-test/vue-office-header';
import vueOfficeAside from '@gic-test/vue-office-aside';
import vueOfficeArea from '@gic-test/vue-office-area';
import vueGicImgPreview from '@gic-test/vue-gic-img-preview';
import vueOfficeUploadImage from '@gic-test/vue-office-upload-image';
import htmlToPdf from '@/components/utils/htmlToPdf';
import VueAMap from 'vue-amap';
import Vue from 'vue';
import buttonCode from '../menu-data/button-code.json';
import HbFormBottom from '@/components/layout/hb-form-bottom.vue';

// Vue.use(contentmenu);
Object.keys(directives).map(item => Vue.directive(item, directives[item]));
Vue.use(VueAMap);
VueAMap.initAMapApiLoader({
  key: 'd53a58848be368a7398dc56d5670fe9c',
  plugin: ['Autocomplete', 'PlaceSearch', 'Scale', 'OverView', 'Geocoder', 'ToolBar', 'MapType', 'PolyEditor', 'AMap.CircleEditor'],
  v: '1.4.4'
});
window.ELEMENT.Dialog.props.closeOnClickModal.default = false; // 全局设置点击蒙层不关闭
Vue.use(htmlToPdf);
Vue.use(vueGicImgPreview);
Vue.use(vueOfficeUploadImage);
Vue.use(vueOfficeArea);
Vue.use(vueOfficeAside);
Vue.use(vueOfficeHeader);
Vue.component('hb-form-bottom', HbFormBottom);

Vue.config.productionTip = false;
// Vue.use(ElementUI, { size: 'large' });

// 全局注册过滤器
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key]);
});

/*
 * 路由守护
 */
router.beforeEach((to, from, next) => {
  if (window.axiosPromiseArr) {
    axiosPromiseArr.forEach((ele, index) => {
      ele.cancel();
      delete axiosPromiseArr[index];
    });
  }

  let baseUrl;
  let host = window.location.origin;
  if (host.indexOf('localhost') != -1) {
    baseUrl = 'http://www.gicdev.com';
  } else {
    baseUrl = host;
  }
  
  const { fromPath = [] } = from.meta || {};
  if (Array.isArray(fromPath)) {
    from.meta.keepAlive = fromPath.some(el => {
      let menuUrlReg = el;
      let pathConfigReg = /(:.*)(\/?)/;
      const pathRegStr = '([\\d\\w]+[\\-]*[\\d\\w]*)';
      while (pathConfigReg.test(menuUrlReg)) {
        menuUrlReg = menuUrlReg.replace(pathConfigReg, `${pathRegStr}$2`);
      }
      pathConfigReg = /(\/\*)(\/?)/;
      while (pathConfigReg.test(menuUrlReg)) {
        menuUrlReg = menuUrlReg.replace(pathConfigReg, `${pathRegStr}$2`);
      }
      const reg = new RegExp(menuUrlReg);
      return reg.test(to.path);
    });
  }
  next();
});
 
// 将按钮code挂到vue的原型上，供页面中埋点使用
Vue.prototype.$buttonCode = buttonCode;

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