index.vue 1020 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <template>
  2. <page-loading class="index-page" :loading="loading">
  3. <index-logged v-if="isLogin" />
  4. <index-login v-else />
  5. </page-loading>
  6. </template>
  7. <script>
  8. import IndexLogged from '../components/Index/Logged'
  9. import IndexLogin from '../components/Index/Login'
  10. import PageLoading from '../components/PageLoading'
  11. export default {
  12. name: 'Index',
  13. components: { PageLoading, IndexLogged, IndexLogin },
  14. data() {
  15. return {
  16. isLogin: false,
  17. loading: true
  18. }
  19. },
  20. computed: {},
  21. methods: {
  22. async authorize() {
  23. this.$loading('小程序授权中...')
  24. await this.$api.user.authorize().then(async res => {
  25. this.$hideLoading()
  26. await this.$store.dispatch('user/authorize')
  27. })
  28. }
  29. },
  30. async onShow() {
  31. if (!this.$api.user.isAuthorize()) {
  32. await this.authorize()
  33. }
  34. this.isLogin = this.$api.user.isLogin()
  35. setTimeout(() => {
  36. this.loading = false
  37. }, 500)
  38. }
  39. }
  40. </script>
  41. <style lang="scss" scoped>
  42. .index-page {
  43. }
  44. </style>