App.vue 3.5 KB

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