App.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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(
  49. 'click',()=>{
  50. sessionStorage.setItem('lastClickTime',new Date().getTime())
  51. }
  52. )
  53. window.addEventListener(
  54. 'mousewheel',()=>{
  55. sessionStorage.setItem('lastClickTime',new Date().getTime())
  56. }
  57. )
  58. window.addEventListener(
  59. 'mousemove',()=>{
  60. sessionStorage.setItem('lastClickTime',new Date().getTime())
  61. }
  62. )
  63. },
  64. methods: {
  65. // 判断是否为chrome浏览器
  66. handleUserAgentRoot() {
  67. if (
  68. !sessionStorage.getItem("useragent_root_close") &&
  69. navigator.userAgent.indexOf("Chrome") == -1
  70. ) {
  71. this.userAgentTipShow = true;
  72. }
  73. },
  74. handleClickUserAgent() {
  75. sessionStorage.setItem("useragent_root_close", true);
  76. this.userAgentTipShow = false;
  77. },
  78. // 是否超时
  79. isTimeOut(){
  80. clearInterval(this.timeOut)
  81. let dataConfig = JSON.parse(getConfig());
  82. if(dataConfig.user_connection_timeout_duration){
  83. this.timeOut = setInterval(()=>{
  84. let lastClickTime = sessionStorage.getItem('lastClickTime')*1
  85. let nowTime = new Date().getTime()
  86. if(nowTime - lastClickTime > 1000 * dataConfig.user_connection_timeout_duration){
  87. clearInterval(this.timeOut)
  88. removeSession("SysList");
  89. removeToken();
  90. Cookies.remove("JSESSIONID");
  91. this.userShow = false;
  92. this.userMessage = null;
  93. sessionStorage.removeItem("useragent_root_close");
  94. window.location.href = dataConfig.sys_home_url
  95. }
  96. })
  97. }
  98. }
  99. },
  100. mounted(){
  101. sessionStorage.setItem('lastClickTime',new Date().getTime())
  102. this.isTimeOut()
  103. },
  104. };
  105. </script>
  106. <style>
  107. * {
  108. margin: 0;
  109. padding: 0;
  110. }
  111. html,
  112. body {
  113. width: 100%;
  114. height: 100%;
  115. }
  116. #app {
  117. width: 100%;
  118. height: 100%;
  119. min-width: 1200px;
  120. }
  121. </style>
  122. <style lang="scss" scoped>
  123. .userAgentTips {
  124. position: fixed;
  125. top: 62px;
  126. left: 50%;
  127. // width: 624px;
  128. margin-left: -312px;
  129. background: #ffffff;
  130. border-radius: 8px;
  131. padding: 12px 16px 12px 8px;
  132. display: flex;
  133. align-items: center;
  134. justify-content: space-between;
  135. font-size: 16px;
  136. line-height: 24px;
  137. :nth-child(1) {
  138. margin-right: 8px;
  139. }
  140. :nth-child(3) {
  141. cursor: pointer;
  142. }
  143. }
  144. </style>