App.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <div id="app">
  3. <router-view />
  4. <div class="userAgentTips" v-if="userAgentTipShow">
  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. console.log("2024-03-11 npc");
  32. this.handleUserAgentRoot();
  33. window.addEventListener("click", () => {
  34. sessionStorage.setItem("lastClickTime", new Date().getTime());
  35. });
  36. window.addEventListener("mousewheel", () => {
  37. sessionStorage.setItem("lastClickTime", new Date().getTime());
  38. });
  39. window.addEventListener("mousemove", () => {
  40. sessionStorage.setItem("lastClickTime", new Date().getTime());
  41. });
  42. },
  43. methods: {
  44. // 判断是否为chrome浏览器
  45. handleUserAgentRoot() {
  46. if (
  47. !sessionStorage.getItem("useragent_root_close") &&
  48. navigator.userAgent.indexOf("Chrome") == -1
  49. ) {
  50. this.userAgentTipShow = true;
  51. }
  52. },
  53. handleClickUserAgent() {
  54. sessionStorage.setItem("useragent_root_close", true);
  55. this.userAgentTipShow = false;
  56. },
  57. // 是否超时
  58. isTimeOut() {
  59. clearInterval(this.timeOut);
  60. const dataConfig = getConfig() ? JSON.parse(getConfig()) : null;
  61. if (dataConfig && dataConfig.user_connection_timeout_duration) {
  62. this.timeOut = setInterval(() => {
  63. let lastClickTime = sessionStorage.getItem("lastClickTime") * 1;
  64. let nowTime = new Date().getTime();
  65. if (
  66. nowTime - lastClickTime >
  67. 1000 * dataConfig.user_connection_timeout_duration
  68. ) {
  69. clearInterval(this.timeOut);
  70. removeSession("SysList");
  71. removeToken();
  72. Cookies.remove("JSESSIONID");
  73. this.userShow = false;
  74. this.userMessage = null;
  75. sessionStorage.removeItem("useragent_root_close");
  76. window.location.href = dataConfig.sys_home_url;
  77. }
  78. });
  79. }
  80. }
  81. },
  82. mounted() {
  83. sessionStorage.setItem("lastClickTime", new Date().getTime());
  84. this.isTimeOut();
  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>