App.vue 2.9 KB

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