App.vue 3.0 KB

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