<template>
  <page-loading class="index-page" :loading="loading">
    <index-logged v-if="isLogin" />
    <index-login v-else />
  </page-loading>
</template>

<script>
import IndexLogged from '../components/Index/Logged'
import IndexLogin from '../components/Index/Login'
import PageLoading from '../components/PageLoading'
export default {
  name: 'Index',
  components: { PageLoading, IndexLogged, IndexLogin },
  data() {
    return {
      isLogin: false,
      loading: true
    }
  },
  computed: {},
  methods: {
    async authorize() {
      this.$loading('小程序授权中...')
      await this.$api.user.authorize().then(async res => {
        this.$hideLoading()
        await this.$store.dispatch('user/authorize')
      })
    }
  },
  async onShow() {
    if (!this.$api.user.isAuthorize()) {
      await this.authorize()
    }
    this.isLogin = this.$api.user.isLogin()
    setTimeout(() => {
      this.loading = false
    }, 500)
  }
}
</script>

<style lang="scss" scoped>
.index-page {
}
</style>
