import Vue from "vue";
import App from "./App.vue";
import router from "./router";


// 引入 vue-awesome-swiper 插件
import VueAwesomeSwiper from "vue-awesome-swiper";
import "swiper/css/swiper.css";
Vue.use(VueAwesomeSwiper);

// 引入 vue-video-player 插件
import VueVideoPlayer from "vue-video-player";
import "video.js/dist/video-js.css";
import "vue-video-player/src/custom-theme.css";
Vue.use(VueVideoPlayer);

// 引入H5图片裁剪插件
import H5Cropper from 'vue-cropper-h5'
Vue.use(H5Cropper)

// 引入全局iconfontz
import "./static/iconfont/iconfont.css";

// 引入H5手写签名插件
import vueEsign from 'vue-esign'
Vue.use(vueEsign)

// 引入 vant 组件
import Vant from "vant";
import {
  Lazyload
} from "vant";
import "vant/lib/index.css";
Vue.use(Vant);
Vue.use(Lazyload, {
  lazyComponent: true,
  loading: require("@/assets/images/not-opened.png"), //加载的图片
  error: "https://image.360lj.com/nopic.gif" //	错误时的图片	string
});

// 日期选择 demo => https://lx544690189.github.io/vue-mobile-calendar/
// api =>https://www.npmjs.com/package/vue-mobile-calendar
import Calendar from "vue-mobile-calendar";

Vue.use(Calendar);

// import FastClick from "fastclick";
// FastClick.attach(document.body);

import Vconsole from "vconsole";

if (process.env.VUE_APP_Name == "测试环境" || process.env.VUE_APP_Name == "开发环境") {
  let vc = new Vconsole();
}

import "animate.css";

// 图片裁剪插件 文档demo=>  http://github.xyxiao.cn/vue-cropper/example/
import VueCropper from "vue-cropper";

Vue.use(VueCropper);

import "./assets/css/reset.css";

// 接口js
import $http from "./api/api";
Vue.prototype.$http = $http;

// 获取当前定位js
import map from "./assets/js/getLocation.js";
Vue.prototype.map = map;

// 视频上传
// import uploader from 'vue-simple-uploader'
// Vue.use(uploader)

// 全局过滤器
import filters from "./assets/js/filters.js";
Object.keys(filters.filters).forEach(key => {
  Vue.filter(key, filters.filters[key]);
});
// 引入echarts
import echarts from "echarts";
Vue.prototype.$echarts = echarts;
Vue.mixin({
  data() {
    return {
      DisNumber: 30 // 混入虚假报名人数
    };
  },
  methods: {
    // 获取cookie
    getCookie(cname) {
      let name = cname + "="
      let ca = document.cookie.split(";")
      for (let i = 0; i < ca.length; i++) {
        let c = ca[i].trim()
        if (c.indexOf(name) == 0) {
          return c.substring(name.length, c.length)
        }
      }
      return ""
    },
    // 滚动到顶部
    scrollTop() {
      let sTop = document.documentElement.scrollTop || document.body.scrollTop;
      // let sTop = document.scrollingElement.scrollTop ;
      if (sTop > 0) {
        window.requestAnimationFrame(this.scrollTop);
        window.scrollTo(0, sTop - sTop / 8);
      }
    },
    // 默认加载中  loading动画
    LJ_LOADING(message = "加载中...") {
      this.$toast.loading({
        duration: 0, //持续展示
        forbidClick: true, //禁用背景点击
        message: message,
        mask: true //背景遮罩
      });
    },
    // 发送请求时的loadding效果
    isRequest() {
      this.$toast.loading({
        message: "加载中...",
        forbidClick: true,
        loadingType: "spinner",
        duration: 0
      })
    },
    // 获取URL中的参数值
    getUrlParams(paramsName) {
      //JavaScript获取url，并把url中的参数变成数组的方法，arr数组的值就是各参数值
      var url = window.document.location.href.toString();
      var u = url.split("?");
      var arr = [];
      if (typeof (u[1]) == "string") {
        u = u[1].split("&");
        for (var i in u) {
          var a = (u[i].split("="));
          arr[a[0]] = a[1];
        }
      }
      return arr[paramsName]
    }
    
  }
});

router.afterEach((to, from, next) => {
  setTimeout(() => {
    var _htm = _htm || [];
    (function () {
      // 每次执行前,先移除上次插入的代码
      document.getElementById('baidu_tj') && document.getElementById('baidu_tj').remove();
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?e40842ed9220cad62f187a647c3247e2";
      hm.id = "baidu_tj"
      var script = document.getElementsByTagName("script")[0];
      script.parentNode.insertBefore(hm, script);
    })();
  }, 0);
})

Vue.config.productionTip = false;
// 解决H5跳转小程序组件报错问题
Vue.config.ignoredElements = ['wx-open-launch-weapp']
new Vue({
  router,
  render: h => h(App)
}).$mount("#app");