App.vue 1.81 KB
<template>
  <div id="app">
    <template v-if="showWindow">
      <transition name="fade">
        <keep-alive v-if="$route.meta.keepAlive">
          <router-view></router-view>
        </keep-alive>
      </transition>
      <transition name="fade">
        <router-view v-if="!$route.meta.keepAlive"></router-view>
      </transition>
    </template>
    <action v-show="$route.meta.showAction && !$store.state.app.isLiveFull"></action>
  </div>
</template>
<script>
import { bigdatautilApi } from '@/api'
export default {
  name: 'App',
  data() {
    return {
      timer: null
    }
  },
  watch: {
    watchFlag: {
      immediate: true,
      handler(newval) {
        this.showWindow = newval
        this.hideLoading()
      }
    },
    wacthLoginStatus: {
      immediate: true,
      handler(newval) {
        if (newval) {
          console.log('触发埋点')
          this.init()
        }
      }
    }
  },
  computed: {
    watchFlag() {
      return this.$store.state.app.showWindow
    },
    wacthLoginStatus() {
      return this.$store.state.app.loginStatus
    }
  },
  mounted() {},

  methods: {
    init() {
      this.openListener()
      window.addEventListener('pagehide', () => {
        this.leave()
        this.closeListener()
        // console.log('页面要关闭了')
      })
    },
    // 心跳检测
    openListener() {
      this.timer = setInterval(() => {
        this.heartbeat()
      }, 60 * 1000)
    },
    closeListener() {
      clearInterval(this.timer)
    },
    // 心跳检测
    heartbeat() {
      this.trackFn('heartbeat', 5)
    },
    //离开事件
    leave() {
      // console.log('离开时间')
      this.trackFn('leaveReportTrack', 5)
    },
    trackFn(name, actionType) {
      const { id } = this.getQuery()
      bigdatautilApi[name](id, actionType)
    }
  }
}
</script>