-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
76 lines (74 loc) · 2.25 KB
/
app.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//app.js
App({
onLaunch: function () {
// 展示本地存储能力
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
// 登录
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
}
})
},
onShow: function (options) {
// wx.showModal({
// title: JSON.stringify(options),
// })
if (options.query.q) {
// 普通二维码扫描
this.globalData.entry_url = decodeURIComponent(options.query.q)
} else if (options.query.url) {
// 参数跳转:包括分享卡片
this.globalData.entry_url = decodeURIComponent(options.query.url)
} else {
this.globalData.entry_url = null
}
this.changeTabBarItem()
},
globalData: {
entry_url: null,
DEFAULT_ONLINE_URL: "https://sustech.online/index-wx.html?utm_source=wx&utm_medium=miniapp",
DEFAULT_DAILY_URL: "https://daily.sustech.online/?utm_source=wx&utm_medium=miniapp",
DEFAULT_BUS_URL: "https://sustech.online/transport/bustimer-wx.html?utm_source=wx&utm_medium=miniapp",
DEFAULT_CANTEEN_URL: "https://sustech.online/canteen/canteen-wx.html?utm_source=wx&utm_medium=miniapp"
},
changeTabBarItem: function () {
wx.getSystemInfo({
success: (res) => {
var lang = res.language.substring(0, 2) || 'en'
console.log("current language " + lang)
if (lang === 'zh') {
console.log("use chinese as default")
this.setTabBarItems([
{ index: 0, text: '饭堂' },
{ index: 1, text: '手册' },
{ index: 2, text: '巴士' }
])
} else {
console.log("use english as default")
this.setTabBarItems([
{ index: 0, text: 'Canteen' },
{ index: 1, text: 'Home' },
{ index: 2, text: 'Bus' }
])
}
}
})
},
setTabBarItems: function (items) {
items.forEach(function (item) {
wx.setTabBarItem({
index: item.index,
text: item.text,
success: function (res) {
console.log('设置TabBar成功', res)
},
fail: function (res) {
console.log('设置TabBar失败', res)
}
})
})
}
})