<template>
  <div id="app">
    <router-view v-if="signIn"></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 { checkLogin } from "@/api/index";
export default {
  name: "App",
  components: {},
  data() {
    return {
      signIn: true,
    };
  },
  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";
      // //监测窗口大小变化
      window.addEventListener(
        "onorientationchange" in window ? "orientationchange" : "resize",
        function () {
          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";
        },
        false
      );
    },

    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 "";
    },
    checkLogin() {
      checkLogin().then((res) => {
        if (res.status == 200) {
          this.signIn = true;
        } else {
          window.location.href = window.location.origin + "/wisdom";
        }
      });
    },
  },
  mounted() {
    // var isChrome = window.navigator.userAgent.indexOf("Chrome") !== -1;
    // if (isChrome) {
    //   this.bodyScale();
    // }
    this.bodyScale();
    // this.checkLogin();
  },
};
</script>

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

/* 滚动条样式 */
*::-webkit-scrollbar {
  width: 8px; /*  设置纵轴（y轴）轴滚动条 */
  height: 4px; /*  设置横轴（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>
