<template>
<div>

</div>
</template>

<script>
export default {
  methods: {
    login () {
      this.$api.get('/weChat/pc/login').then(res => {
        location.href = res.object
      })
    },
    getUserInfo () {
      let {
        code,
        state
      } = this.$route.query
      this.$api.get(`/weChat/callback/pc?code=${code}&state=${state}`).then(res => {
        localStorage.setItem('user', JSON.stringify(res.object))
        let time = setTimeout(() => {
          location.href = location.origin + '/contest'
          clearTimeout(time)
        }, 500)
      })
    }
  },
  created () {
    // let user = localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user')) : {}
    // this.$route.query.code || ((user && user.id) || this.login())
    this.$route.query.code && this.getUserInfo()
  }
}
</script>

<style lang="scss" scoped>

</style>
