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

<script>
export default {
  name: "App",
  created() {
    this.getIp();
  },
  methods: {
    async getIp() {
      let res = await this.$axios({
        url: "http://ip-api.com/json",
        method: "get"
      });
      // console.log(res);
      if (res.status == 200) {
        let IP = res.data.query;
        // console.log(IP);
        let ipList = [
          "58.17.42.179",
          "10.201.5.31",
          "10.205.64.222",
          "171.34.215.31",
          "182.105.82.9",
          "220.175.60.46",
          "39.160.30.198"
        ];
        let isip = ipList.includes(IP);
        let isip2 = IP.indexOf("218.64.4") > -1;
        if (!isip && !isip2) {
          alert("没有访问权限");
          this.closeWin();
        }
      }
    },
    closeWin() {
      if (
        navigator.userAgent.indexOf("Firefox") != -1 ||
        navigator.userAgent.indexOf("Chrome") != -1
      ) {
        window.location.href =
          "https://www.baidu.com" + "?v=" + new Date().getTime();
        window.location.href = "about:blank";
        window.close();
      } else {
        let iphone = navigator.userAgent.toLowerCase().indexOf("iphone");
        let ipad = navigator.userAgent.toLowerCase().indexOf("ipad");
        if (iphone != -1 || ipad != -1) {
          window.location =
            "https://www.baidu.com" + "?v=" + new Date().getTime();
        }
        window.location.href =
          "https://www.baidu.com" + "?v=" + new Date().getTime();
        window.opener = null;
        window.open("", "_self");
        window.close();
      }
    }
  }
};
</script>

<style>
html,
body,
#app {
  padding: 0;
  margin: 0;
  height: calc(100vh);
  width: 100%;
  background-color: #eaeaea;
}

a {
  text-decoration: none;
}
</style>
