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

//引入element-ui
import "../src/assets/css/theme/index.css";
import ElementUI from "element-ui";
// import "element-ui/lib/theme-chalk/index.css";

import { message } from "./components/message.js";

Vue.prototype.$message = message;
Vue.use(ElementUI, {
  size: "small",
});
//  引入Echarts
import * as echarts from "echarts";
Vue.prototype.$echarts = echarts;

// // 引入 vue-awesome-swiper
// import VueAwesomeSwiper from "vue-awesome-swiper";
// //引入 vue-awesome-swiper 样式
// import "swiper/dist/css/swiper.css";
// Vue.use(VueAwesomeSwiper /* { 全局组件的默认选项 } */);

import "./assets/css/reset.css"; //默认样式
import "./assets/css/theme.less"; //修改主题颜色
import "./assets/css/global.less"; //全局定义颜色
import "./assets/css/element.less"; //全局定义颜色
import "./assets/fonts/iconfont.css"; //按钮

//引入md5加密
import md5 from "js-md5";
Vue.prototype.$md5 = md5;

import moment from "moment"; // 导入文件
// 注册全局 moment
Vue.prototype.$moment = moment;
Vue.config.productionTip = false;
//图片预览
import "viewerjs/dist/viewer.css";
import Viewer from "v-viewer";
Vue.use(Viewer);
// 这里是插件的默认设置
Viewer.setDefaults({
  zIndexInline: 9999,
});

//使用钩子函数对路由进行权限跳转
router.beforeEach((to, from, next) => {
  document.title = `${to.meta.title} | 视频监控可视化平台`;
  const role = localStorage.getItem("role");
  const token = localStorage.getItem("token");
  console.log(role, token);
  if (!token && to.path !== "/login") {
    //next("/login");
    next({
      path: "/login",
    });
  } else {
    next();
  }
});

new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");

Vue.directive("debounce", {
  inserted(el, binding, vnode) {
    let timer = {};
    el.addEventListener("click", () => {
      if (timer) {
        clearTimeout(timer);
      }
      timer = setTimeout(() => {
        binding.value();
      }, 500);
    });
  },
});
