App.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. let dataConfig = JSON.parse(getConfig());
  57. if(dataConfig.user_connection_timeout_duration){
  58. this.timeOut = setInterval(()=>{
  59. let lastClickTime = sessionStorage.getItem('lastClickTime')*1
  60. let nowTime = new Date().getTime()
  61. if(nowTime - lastClickTime > 1000 * dataConfig.user_connection_timeout_duration){
  62. clearInterval(this.timeOut)
  63. removeSession("SysList");
  64. removeToken();
  65. Cookies.remove("JSESSIONID");
  66. this.userShow = false;
  67. this.userMessage = null;
  68. sessionStorage.removeItem("useragent_root_close");
  69. window.location.href = dataConfig.sys_home_url
  70. }
  71. })
  72. }
  73. }
  74. },
  75. mounted(){
  76. sessionStorage.setItem('lastClickTime',new Date().getTime())
  77. this.isTimeOut()
  78. },
  79. };
  80. </script>
  81. <style lang="scss" scoped>
  82. .userAgentTips{
  83. position: fixed;
  84. top: 62px;
  85. left: 50%;
  86. // width: 624px;
  87. margin-left: -312px;
  88. background: #FFFFFF;
  89. border-radius: 8px;
  90. padding: 12px 16px 12px 8px;
  91. display: flex;
  92. align-items: center;
  93. justify-content: space-between;
  94. font-size: 16px;
  95. line-height: 24px;
  96. :nth-child(1){
  97. margin-right: 8px;
  98. }
  99. :nth-child(3){
  100. cursor: pointer;
  101. }
  102. }
  103. </style>