App.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <div id="app">
  3. <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  4. <router-view />
  5. <div
  6. class="userAgentTips"
  7. :class="[isPhone ? 'userAgentTips-phone' : '']"
  8. v-if="userAgentTipShow"
  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. methods: {
  51. // 判断是否为chrome浏览器
  52. handleUserAgentRoot() {
  53. if (
  54. navigator.userAgent.indexOf("Chrome") > -1 ||
  55. navigator.userAgent.indexOf("CriOS") > -1 ||
  56. sessionStorage.getItem("useragent_root_close")
  57. ) {
  58. this.userAgentTipShow = false;
  59. } else {
  60. this.userAgentTipShow = true;
  61. }
  62. },
  63. handleClickUserAgent() {
  64. sessionStorage.setItem("useragent_root_close", true);
  65. this.userAgentTipShow = false;
  66. },
  67. // 是否超时
  68. isTimeOut() {
  69. clearInterval(this.timeOut);
  70. const dataConfig = getConfig() ? JSON.parse(getConfig()) : null;
  71. if (dataConfig && dataConfig.user_connection_timeout_duration) {
  72. this.timeOut = setInterval(() => {
  73. let lastClickTime = sessionStorage.getItem("lastClickTime") * 1;
  74. let nowTime = new Date().getTime();
  75. if (
  76. nowTime - lastClickTime >
  77. 1000 * dataConfig.user_connection_timeout_duration
  78. ) {
  79. clearInterval(this.timeOut);
  80. removeSession("SysList");
  81. removeToken();
  82. Cookies.remove("JSESSIONID");
  83. this.userShow = false;
  84. this.userMessage = null;
  85. sessionStorage.removeItem("useragent_root_close");
  86. window.location.href = dataConfig.sys_home_url;
  87. }
  88. });
  89. }
  90. }
  91. },
  92. mounted() {
  93. sessionStorage.setItem("lastClickTime", new Date().getTime());
  94. this.isTimeOut();
  95. document.addEventListener("contextmenu", event => event.preventDefault());
  96. }
  97. };
  98. </script>
  99. <style lang="scss" scoped>
  100. .userAgentTips {
  101. position: fixed;
  102. top: 62px;
  103. left: 50%;
  104. // width: 624px;
  105. margin-left: -312px;
  106. background: #ffffff;
  107. border-radius: 8px;
  108. padding: 12px 16px 12px 8px;
  109. display: flex;
  110. align-items: center;
  111. justify-content: space-between;
  112. font-size: 16px;
  113. line-height: 24px;
  114. z-index: 3;
  115. &-phone {
  116. width: 100%;
  117. left: 0;
  118. margin-left: 0;
  119. }
  120. :nth-child(1) {
  121. margin-right: 8px;
  122. }
  123. :nth-child(3) {
  124. cursor: pointer;
  125. }
  126. }
  127. </style>