<template>
  <div id="app">
    <router-view></router-view>
  </div>
</template>

<script>
const debounce = (fn, delay) => {
  let timer = null;
  return function () {
    let context = this;
    let args = arguments;
    clearTimeout(timer);
    timer = setTimeout(function () {
      fn.apply(context, args);
    }, delay);
  };
};

const _ResizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends _ResizeObserver {
  constructor(callback) {
    callback = debounce(callback, 16);
    super(callback);
  }
};
import { getUserInfo } from "@/api/index";
export default {
  name: "App",
  components: {},
  data() {
    return {
      signIn: false,
    };
  },
  methods: {
    bodyScale() {
      // var deviceHeight = window.innerHeight;
      // var scale = deviceHeight / 1080;
      // document.body.style.zoom = scale;
      // document.body.style.height = (1 / scale) * 100 + "vh";

      // document.styleSheets[document.styleSheets.length - 1].insertRule(
      //   "canvas:not(.amap-layer):not(.amap-labels) {zoom: " +
      //     Number(1 / scale).toFixed(2) +
      //     "!important}"
      // );

      // document.styleSheets[document.styleSheets.length - 1].insertRule(
      //   "canvas:not(.amap-layer):not(.amap-labels) {transform: scale(" +
      //     scale +
      //     ")!important}"
      // );

      // document.styleSheets[document.styleSheets.length - 1].insertRule(
      //   "canvas:not(.amap-layer):not(.amap-labels) {transform-origin: 0 0}"
      // );
      var designW = 1920;
      var font_rate = 100;
      document.getElementsByTagName("html")[0].style.fontSize =
        (document.body.offsetWidth / designW) * font_rate + "px";
      document.getElementsByTagName("body")[0].style.fontSize =
        (document.body.offsetWidth / designW) * font_rate + "px";
      //监测窗口大小变化

      var that = this;
      window.addEventListener(
        "onorientationchange" in window ? "orientationchange" : "resize",
        function () {
          setTimeout(() => {
            document.getElementsByTagName("html")[0].style.fontSize =
              (document.body.offsetWidth / designW) * font_rate + "px";
            document.getElementsByTagName("body")[0].style.fontSize =
              (document.body.offsetWidth / designW) * font_rate + "px";
          }, 500);
        },
        false
      );
    },
    getUserInfo() {
      // var op_id = "B0877928-60DF-4CE8-A18C-41954D48B183 ";
      if (this.getcookie("op_id")) {
        getUserInfo(this.getcookie("op_id")).then((res) => {
          if (res.status == 200) {
            this.$store.commit("changeUserInfo", res.data[0]);
          }
        });
      }
      // getUserInfo(op_id).then((res) => {
      //   if (res.status == 200) {
      //     this.$store.commit("changeUserInfo", res.data[0]);
      //   }
      // });
    },

    getcookie(sname) {
      var acookie = document.cookie.split("; ");
      for (var i = 0; i < acookie.length; i++) {
        var arr = acookie[i].split("=");
        if (sname == arr[0]) {
          if (arr.length > 1) return unescape(arr[1]);
          else return "";
        }
      }
      return "";
    },
  },
  mounted() {
    var isChrome = window.navigator.userAgent.indexOf("Chrome") !== -1;
    if (isChrome) {
    }
    this.bodyScale();
    // this.getUserInfo();
  },
  watch: {
    $route(to, from) {
      window.location.reload();
    },
  },
};
</script>

<style>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body {
  margin: 0px;
}
#app {
  height: 100%;
}

/* 滚动条样式 */
*::-webkit-scrollbar {
  width: 8px; /*  设置纵轴（y轴）轴滚动条 */
  height: 8px; /*  设置横轴（x轴）轴滚动条 */
}
/* 滚动条滑块（里面小方块） */
*::-webkit-scrollbar-thumb {
  border-radius: 10px;
  box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  background: rgba(255, 255, 255, 0.3);
}
/* 滚动条轨道 */
*::-webkit-scrollbar-track {
  border-radius: 0;
  box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  background: rgba(0, 0, 0, 0.5);
}
</style>
