App.vue 3.4 KB

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