forked from bstdn/Shares-MiniProgram
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
82 lines (79 loc) · 2 KB
/
app.js
File metadata and controls
82 lines (79 loc) · 2 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
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
77
78
79
80
81
82
//app.js
const WXAPI = require('apifm-wxapi')
const CONFIG = require('./config')
const AUTH = require('./utils/auth')
App({
onLaunch: function () {
WXAPI.init(CONFIG.subDomain)
// 检测新版本
const updateManager = wx.getUpdateManager()
updateManager.onUpdateReady(() => {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: res => {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
}
}
})
})
/**
* 初次加载判断网络情况
* 无网络状态下根据实际情况进行调整
*/
wx.getNetworkType({
success: res => {
if (res.networkType === 'none') {
this.globalData.isConnected = false
wx.showToast({
title: '当前无网络',
icon: 'loading',
duration: 2000
})
}
}
})
/**
* 监听网络状态变化
* 可根据业务需求进行调整
*/
wx.onNetworkStatusChange(res => {
if (!res.isConnected) {
this.globalData.isConnected = false
wx.showToast({
title: '网络已断开',
icon: 'loading',
duration: 2000
})
} else {
this.globalData.isConnected = true
wx.hideToast()
}
})
/**
* 获取系统参数
*/
WXAPI.queryConfigBatch('miniProgramName,shareTitle,answerCategoryId,answerPageSize,answerSuccess,aboutMe,imageAuthor,imageStar,signLogLength').then(res => {
if (res.code === 0) {
res.data.forEach(config => {
wx.setStorageSync(config.key, config.value)
})
}
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
AUTH.checkHasLoggedIn().then(loggedIn => {
if (!loggedIn) {
AUTH.login()
}
})
},
globalData: {
isConnected: true
}
})