loading.js
1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// 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
}
}
})