loading.js 1.06 KB
// pages/loading/loading.js
Page({

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

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(__wxConfig)
    this.tabList = __wxConfig.tabBar.list
    wx.p.wxApi.showLoading()
    //scenc获取页面参数并跳转
    if (options.scene) {
      return 
    }
    if (options.url) {
      return this.jumpPage(options.url)
    }
    // 默认跳转到首页
    wx.p.router.goHome()
  },
  jumpPage(val){
    const targetPath = decodeURIComponent(val),
    {url, events} = this.setRouteData(targetPath),
    routeName = this.tabList.findIndex(e => `/${e.pagePath}` == `${url}.html`) > -1 ? 'switchTab' : 'redirectTo'
    wx.p.router[routeName](url,events)
  },
  setRouteData(targetPath) {
    let [url, query] = targetPath.split('?'),
      events = {}
    if (query) {
      let arr = query.split('&')
      arr.map(e => {
        const [key, val] = e.split('=')
        Object.assign(events, {
          [key]: val
        })
      })
    }
    return {
      url,
      events
    }
  }
})