import Vue from 'vue'
import App from './App'
import ElementUI from 'element-ui';
import router from './router'
import store from '@/store/store.js'
import less from 'less'
Vue.use(less)

import './assets/js/directives'; // 实现elementui对话框可拖拽功能
import drag from '@/assets/js/drag'; // 实现div弹框可拖拽功能

import Viewer from 'v-viewer'
import 'viewerjs/dist/viewer.css'
Vue.use(Viewer, {
  defaultOptions: {
    "zIndex": 9999,
  }
})
// import Viewer from 'v-viewer'
// import 'viewerjs/dist/viewer.css'
// Vue.use(Viewer)
// Viewer.setDefaults({
//   Options: {
//     inline: true,
//     button: false,
//     navbar: true,
//     title: true,
//     toolbar: true,
//     tooltip: true,
//     movable: true,
//     zoomable: true,
//     rotatable: true,
//     scalable: true,
//     transition: true,
//     fullscreen: true,
//     keyboard: true,
//     url: 'data-source'
//   }
// })

import echarts from 'echarts'
Vue.prototype.$echarts = echarts

// import $ from 'jquery'

Vue.prototype.$store = store

import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI);
Vue.config.productionTip = false

const axios = require('axios')
const Qs = require('qs')

Vue.prototype.$imghost = 'http://www.hnyfwlw.com:8006/projectimg' // 线上图片服务器路径常量
Vue.prototype.$insectHost = 'https://images.weserv.nl/?url=' // 线上图片服务器路径常量
Vue.prototype.$deriveData = Vue.prototype.DOMIN // 导出
// Vue.prototype.$deriveData = 'http://192.168.1.112:8002' // 导出
Vue.prototype.$faultvideo = 'http://192.168.1.3:8000' //售后视频地址前缀

import VueHighcharts from 'vue-highcharts';
Vue.use(VueHighcharts);

Vue.prototype.$axios = axios //全局注册，使用方法为:this.$axios
Vue.prototype.$EventBus = new Vue()
Vue.prototype.qs = Qs //全局注册，使用方法为:this.qs
import './util/http.js'

// import './assets/css/global.css'
import './assets/icon/iconfont.css'
//格式化时间戳
import './util/formatTime'

Vue.directive('btnRight', {
  inserted: function (el, binding, vnode) {
    const optName = binding.arg;
    const routeName = binding.value.slice(7); //路由地址
    const authName = `${routeName}_${optName}` //这里根据路由名和操作类型拼出按钮名 overview-edit
    const btnRightList = store.getters.btnRight;
    if (btnRightList[authName] == 0) {
      el.parentNode.removeChild(el)
    } else if (btnRightList[authName] == 1) { }
  }
})

import VueLazyLoad from 'vue-lazyload'
Vue.use(VueLazyLoad, {
  preLoad: 1,
  error: require('./assets/images/newImg/noimage.png'),
  loading: require('./assets/images/newImg/shot-1.gif'),
  attempt: 2,
})

router.beforeEach(async (to, from, next) => {
  console.log(to)
  if (to.path == '/Login'||to.path == '/') {
    next()
  }else{
    if(localStorage.getItem("session")){
      next()
    }else{
      next({
        path: '/Login'
      });
    }
  }
})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
