loading.vue 1.72 KB
<template>
  <view class="loading-page">
    <text class="loading-text">正在启动...</text>
    <review-probe-bar />
  </view>
</template>

<script type='text/ecmascript-6'>
import ReviewProbeBar from '@/components/ReviewProbeBar.vue'

export default {
  components: { ReviewProbeBar },
  name: '',
  data () {
    return {}
  },
  mounted () {
    console.warn('[boot] loading.mounted start')
    this._bootFallbackTimer = setTimeout(() => {
      console.warn('[boot] loading 5s fallback -> login')
      this.toLogin()
    }, 5000)

    try {
      const userInfo = uni.$storage.get('userInfo')
      if (userInfo) {
        console.warn('[boot] loading -> equity')
        if (this._bootFallbackTimer) {
          clearTimeout(this._bootFallbackTimer)
          this._bootFallbackTimer = null
        }
        uni.reLaunch({
          url: '/pages/equity/index'
        })
      } else {
        console.warn('[boot] loading -> login (no userInfo)')
        this.toLogin()
      }
    } catch (e) {
      console.warn('[boot] loading error -> login', e)
      this.toLogin()
    }
  },
  beforeDestroy () {
    if (this._bootFallbackTimer) {
      clearTimeout(this._bootFallbackTimer)
      this._bootFallbackTimer = null
    }
  },
  methods: {
    async toLogin () {
      if (this._bootFallbackTimer) {
        clearTimeout(this._bootFallbackTimer)
        this._bootFallbackTimer = null
      }
      await uni.$storage.rm("userInfo")
      uni.reLaunch({
        url: '/pages/common/login'
      })
    }
  }
}
</script>

<style scoped lang='scss'>
.loading-page {
  width: 100%;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f7f8fa;
}
.loading-text {
  font-size: 32rpx;
  color: #666;
}
</style>