loading.js 1.31 KB
import {
  setRouteData
} from '../lib/index'
import {
  getSessionId,
} from '~/utils/cache/storageApi'
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    wx.$api.showLoading()
    const sessionId = getSessionId(),
      {
        url,
        targetPath = url ? decodeURIComponent(url) : ''
      } = this.options
    wx.nextTick(() => {
      if (sessionId) {
        let url = 'pages.index',
          obj = {}
        if (targetPath) {
          url = setRouteData(targetPath).url
          obj = setRouteData(targetPath).obj
        }
        wx.$router.reLaunch(url, obj)
      } else {
        let obj = {}
        if (targetPath) obj.targetPath = targetPath
        wx.$router.reLaunch('login.index', obj)
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  }
})