<template>
  <transition name="fade">
    <router-view></router-view>
  </transition>
</template>

<script>


  export default {
    data() {
      return {
        query: {},
        version: '1.3.3'
      }
    },
    created () {
      this.versionReload()
    },
    mounted() {
      // 监听浏览器关闭事件，自动退出登录 - rqrq
      window.addEventListener('beforeunload', this.handleBeforeUnload)
    },
    beforeDestroy() {
      // 移除事件监听 - rqrq
      window.removeEventListener('beforeunload', this.handleBeforeUnload)
    },
    methods: {
      versionReload(){
        let version = this.version          //版本号（每次上线前需要更新下版本号）
        console.log('最新系统版本: ',version)
        console.log('当前系统版本: ',this.version)
        let versionLocal = localStorage.getItem('_version_');
        if(version!=versionLocal){
          localStorage.setItem('_version_',version);
          this.version=versionLocal;
          location.reload();
        }
      },
      // 浏览器关闭时自动退出登录 - rqrq
      handleBeforeUnload() {
        const token = this.$cookie.get('token')
        if (token && token.trim()) {
          // 使用 sendBeacon 发送退出请求，可靠性高 - rqrq
          const url = this.$http.adornUrl('/sys/logout')
          navigator.sendBeacon(url, new Blob([JSON.stringify({ token })], { type: 'application/json' }))
        }
      }
    }
  }

</script>
