App.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <div id="app">
  3. <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  4. <router-view />
  5. <div
  6. v-if="userAgentTipShow"
  7. class="userAgentTips"
  8. :class="[isPhone ? 'userAgentTips-phone' : '']"
  9. >
  10. <img src="./assets/userAgentWarning.png" width="32px" />
  11. <span
  12. >当前浏览器可能与网站不兼容!建议使用 chrome 浏览器获得最佳使用体验。
  13. </span>
  14. <img
  15. src="./assets/userAgentClose.png"
  16. width="16px"
  17. @click="handleClickUserAgent"
  18. />
  19. </div>
  20. </div>
  21. </template>
  22. <script>
  23. import { removeSession } from "@/utils/role";
  24. import { removeToken } from "@/utils/auth";
  25. import Cookies from "js-cookie";
  26. import { getConfig } from "@/utils/auth";
  27. export default {
  28. name: "App",
  29. data() {
  30. return {
  31. userAgentTipShow: false,
  32. timeOut: null,
  33. isPhone: false,
  34. };
  35. },
  36. created() {
  37. const regExp = /Android|webOS|iPhone|BlackBerry|IEMobile|Opera Mini/i;
  38. this.isPhone = regExp.test(navigator.userAgent) && window.innerWidth < 860;
  39. this.handleUserAgentRoot();
  40. window.addEventListener("click", () => {
  41. sessionStorage.setItem("lastClickTime", new Date().getTime());
  42. });
  43. window.addEventListener("mousewheel", () => {
  44. sessionStorage.setItem("lastClickTime", new Date().getTime());
  45. });
  46. window.addEventListener("mousemove", () => {
  47. sessionStorage.setItem("lastClickTime", new Date().getTime());
  48. });
  49. },
  50. mounted() {
  51. sessionStorage.setItem("lastClickTime", new Date().getTime());
  52. console.log("2024-01-12");
  53. document.addEventListener("contextmenu", (event) => event.preventDefault());
  54. // this.isTimeOut();
  55. },
  56. methods: {
  57. // 判断是否为chrome浏览器
  58. handleUserAgentRoot() {
  59. if (
  60. (navigator.userAgent.indexOf("Chrome") > -1 ||
  61. navigator.userAgent.indexOf("CriOS") > -1) &&
  62. !sessionStorage.getItem("useragent_root_close")
  63. ) {
  64. this.userAgentTipShow = false;
  65. } else {
  66. this.userAgentTipShow = true;
  67. }
  68. },
  69. handleClickUserAgent() {
  70. sessionStorage.setItem("useragent_root_close", true);
  71. this.userAgentTipShow = false;
  72. },
  73. // 是否超时
  74. isTimeOut() {
  75. clearInterval(this.timeOut);
  76. const dataConfig = getConfig() ? JSON.parse(getConfig()) : null;
  77. if (dataConfig && dataConfig.user_connection_timeout_duration) {
  78. this.timeOut = setInterval(() => {
  79. const lastClickTime = sessionStorage.getItem("lastClickTime") * 1;
  80. const nowTime = new Date().getTime();
  81. if (
  82. nowTime - lastClickTime >
  83. 1000 * dataConfig.user_connection_timeout_duration
  84. ) {
  85. clearInterval(this.timeOut);
  86. removeSession("SysList");
  87. removeToken();
  88. Cookies.remove("JSESSIONID");
  89. this.userShow = false;
  90. this.userMessage = null;
  91. sessionStorage.removeItem("useragent_root_close");
  92. window.location.href = dataConfig.sys_home_url;
  93. }
  94. });
  95. }
  96. },
  97. },
  98. };
  99. </script>
  100. <style lang="scss" scoped>
  101. .userAgentTips {
  102. position: fixed;
  103. top: 62px;
  104. left: 50%;
  105. // width: 624px;
  106. margin-left: -312px;
  107. background: #ffffff;
  108. border-radius: 8px;
  109. padding: 12px 16px 12px 8px;
  110. display: flex;
  111. align-items: center;
  112. justify-content: space-between;
  113. font-size: 16px;
  114. line-height: 24px;
  115. z-index: 3;
  116. &-phone {
  117. width: 100%;
  118. left: 0;
  119. margin-left: 0;
  120. }
  121. :nth-child(1) {
  122. margin-right: 8px;
  123. }
  124. :nth-child(3) {
  125. cursor: pointer;
  126. }
  127. }
  128. </style>