/** init domain config */
import './config'

import Vue from 'vue'
import App from './App.vue'
import Storage from 'vue-ls'
import router from './router'
import store from './store/'
import EventBus from "@/EventBus";
import { VueAxios } from "@/utils/request"

//本地化部署，避免使用ArcGIS在线引用，因为ArcGIS服务器不稳定，经常访问不到
import esriConfig from "@arcgis/core/config";
esriConfig.assetsPath = "./assets";
import '@arcgis/core/assets/esri/themes/light/main.css';
// esriConfig.request.corsEnabledServers.push("localhost:8080");//设置地图服务器已允许跨域
require('@jeecg/antd-online-mini')
require('@jeecg/antd-online-mini/dist/OnlineForm.css')
esriConfig.fontsUrl='./assets'
import Antd, { version } from 'ant-design-vue'
console.log('ant-design-vue version:', version)
esriConfig.request.corsEnabledServers.push("localhost:8080");//设置地图服务器已允许跨域
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 Print from 'vue-print-nb-jeecg'
import ImageViewer from 'vue2-viewer';
/*import '@babel/polyfill'*/
import preview from 'vue-photo-preview'
import 'vue-photo-preview/dist/skin.css'
import SSO from '@/cas/sso.js'
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 JeecgComponents from '@/components/jeecg/index'
import '@/assets/less/JAreaLinkage.less'
import VueAreaLinkage from 'vue-area-linkage'
import '@/components/jeecg/JVxeTable/install'
import '@/components/JVxeCells/install'
//表单验证
import { rules } from '@/utils/rules'


Vue.prototype.rules = rules
Vue.config.productionTip = false
Vue.prototype.$EventBus= new Vue()

// esriConfig.defaults.io.proxyUrl = "http://localhost/Java/proxy.jsp";


Vue.use(ImageViewer,{});
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(preview)
Vue.use(vueBus);
Vue.use(JeecgComponents);
Vue.use(VueAreaLinkage);
//拖拽事件
Vue.directive('drag', {
  inserted: function(el, binding, vnode) {
    //获取拖拽主体
    var pannel = document.querySelector(`${binding.value}`);
    //整体拖拽物
    var all = el;
    //当鼠标点击时触发
    pannel.onmousedown = fndrag;
    function fndrag(event) {
      //获取鼠标距离窗口的位置
      var disX = event.clientX - all.offsetLeft;
      var disY = event.clientY - all.offsetTop;
      //鼠标移动
      document.onmousemove = function(event) {
        all.style.zIndex=1000;
        var e = event || window.event;
        fnmove(e, disX, disY);
      }
      //放开鼠标
      document.onmouseup = function() {
        document.onmouseup = null;
        document.onmousemove = null;
        all.style.zIndex=100;
      }
    }

    function fnmove(e, disX, disY) {
      //获取窗口的位置（左上角）
      var l = e.clientX - disX;
      var t = e.clientY - disY;
      //获取可视窗口的长宽，兼容浏览器
      var winWid = document.documentElement.clientWidth || document.body.clientWidth;
      var winHei = document.documentElement.clientHeight || document.body.clientHeight;
      //获取窗口的最大宽度和长度（左上角）
      var maxWid = winWid - all.offsetWidth;
      var maxHei = winHei - all.offsetHeight;
      //超出左边间距
      // console.log(t)
      if (l < 228) {
        l = 228;
      }
      //超出右边间距
      else if (l > maxWid) {
        l = maxWid;
      }
      //超出上面距离
      if (t < 115) {
        t = 115;
      } else if (t > maxHei) {
        t = maxHei;
      }

      // all.style.left = l + "px";
      all.style.right =winWid - all.offsetWidth - l + "px";
      all.style.top = t + "px";
    }
  }
});

SSO.init(() => {
  main()
})
function main() {
  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,config.multipage))
    },
    render: h => h(App)
  }).$mount('#app')
}