App.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <div id="app">
  3. <router-view></router-view>
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. name: "App",
  9. created() {
  10. this.getIp();
  11. },
  12. methods: {
  13. async getIp() {
  14. let res = await this.$axios({
  15. url: "http://ip-api.com/json",
  16. method: "get"
  17. });
  18. // console.log(res);
  19. if (res.status == 200) {
  20. let IP = res.data.query;
  21. // console.log(IP);
  22. let ipList = [
  23. "58.17.42.179",
  24. "10.201.5.31",
  25. "10.205.64.222",
  26. "171.34.215.31",
  27. "182.105.82.9",
  28. "220.175.60.46",
  29. "39.160.30.198"
  30. ];
  31. let isip = ipList.includes(IP);
  32. let isip2 = IP.indexOf("218.64.4") > -1;
  33. if (!isip && !isip2) {
  34. alert("没有访问权限");
  35. this.closeWin();
  36. }
  37. }
  38. },
  39. closeWin() {
  40. if (
  41. navigator.userAgent.indexOf("Firefox") != -1 ||
  42. navigator.userAgent.indexOf("Chrome") != -1
  43. ) {
  44. window.location.href =
  45. "https://www.baidu.com" + "?v=" + new Date().getTime();
  46. window.location.href = "about:blank";
  47. window.close();
  48. } else {
  49. let iphone = navigator.userAgent.toLowerCase().indexOf("iphone");
  50. let ipad = navigator.userAgent.toLowerCase().indexOf("ipad");
  51. if (iphone != -1 || ipad != -1) {
  52. window.location =
  53. "https://www.baidu.com" + "?v=" + new Date().getTime();
  54. }
  55. window.location.href =
  56. "https://www.baidu.com" + "?v=" + new Date().getTime();
  57. window.opener = null;
  58. window.open("", "_self");
  59. window.close();
  60. }
  61. }
  62. }
  63. };
  64. </script>
  65. <style>
  66. html,
  67. body,
  68. #app {
  69. padding: 0;
  70. margin: 0;
  71. height: calc(100vh);
  72. width: 100%;
  73. background-color: #eaeaea;
  74. }
  75. a {
  76. text-decoration: none;
  77. }
  78. </style>