<template>
  <div id="app">
    <keep-alive>
      <router-view />
    </keep-alive>
  </div>
</template>

<script>
import { mapGetters, mapActions } from 'vuex'
import Dms from '@/mixins/Dms' // mixins - dms 连接

export default {
  computed: {
    ...mapGetters({
      userInfo: 'userInfo'
    })
  },
  watch: {
    $route: {
      handler: function(nVal, oVal) {
        if ('uin' in nVal.query && nVal.query.uin && oVal && nVal.query.uin !== oVal.query.uin) {
          this.sourceInit()
        }
      },
      immediate: true
    }
  },
  mixins: [Dms],
  methods: {
    ...mapActions({
      postInfo: 'postInfo',
      getUerInfo: 'getUerInfo'
    }),
    sourceInit() {
      const { uin, id: channelId } = this.$route.query
      // 设置uin
      this.$store.commit('SET_UIN', uin)
      // 获取dms消息
      this.mixinsDmsEntry(uin)
      // sentry
      if (uin && process.env.NODE_ENV === 'production' && !process.env.private) {
        this.$report.setUser('', uin)
      }
      // 获取登录用户信息
      this.getUerInfo({ uin })
        .then(data => {
          // pv统计
          this.postInfo({
            channelId, // 资源id
            uin,
            userId: data.id || 0
          })
        })
        .catch(err => {
          console.error(err)
        })
    }
  }
}
</script>
<style lang="less">
html {
  width: 100%;
  height: 100%;
  body {
    width: 100%;
    height: 100%;
    #app {
      width: 100%;
      height: 100%;
    }
  }
}
</style>
