You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.5 KiB

10 months ago
10 months ago
10 months ago
  1. <template>
  2. <transition name="fade">
  3. <router-view></router-view>
  4. </transition>
  5. </template>
  6. <script>
  7. export default {
  8. data() {
  9. return {
  10. query: {},
  11. version: '1.3.3'
  12. }
  13. },
  14. created () {
  15. this.versionReload()
  16. },
  17. mounted() {
  18. // 监听浏览器关闭事件,自动退出登录 - rqrq
  19. window.addEventListener('beforeunload', this.handleBeforeUnload)
  20. },
  21. beforeDestroy() {
  22. // 移除事件监听 - rqrq
  23. window.removeEventListener('beforeunload', this.handleBeforeUnload)
  24. },
  25. methods: {
  26. versionReload(){
  27. let version = this.version //版本号(每次上线前需要更新下版本号)
  28. console.log('最新系统版本: ',version)
  29. console.log('当前系统版本: ',this.version)
  30. let versionLocal = localStorage.getItem('_version_');
  31. if(version!=versionLocal){
  32. localStorage.setItem('_version_',version);
  33. this.version=versionLocal;
  34. location.reload();
  35. }
  36. },
  37. // 浏览器关闭时自动退出登录 - rqrq
  38. handleBeforeUnload() {
  39. const token = this.$cookie.get('token')
  40. if (token && token.trim()) {
  41. // 使用 sendBeacon 发送退出请求,可靠性高 - rqrq
  42. const url = this.$http.adornUrl('/sys/logout')
  43. navigator.sendBeacon(url, new Blob([JSON.stringify({ token })], { type: 'application/json' }))
  44. }
  45. }
  46. }
  47. }
  48. </script>