forked from munmust/work-master
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
97 lines (91 loc) · 2.77 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//函数列表
//onLunch 小程序初始化监听函数
//getCode 获取code并执行callback
//warning 弹窗提示(为了缩减代码,用一个函数调用代替wx.showModal)
//getDateStrByTimeStr 将后台传入的数据库字符串转换为“-年-月-日-时-分”的字符串
App({
globalData: {
roleInfo: null,
timeTure: true,
localSetTime: null,
power:null,
code: null,
stuId: null,
realName: null,
major:null,
classId:null,
grade:null,
apiUrl: 'https://project.supersuperz.top'
// apiUrl: 'http://120.79.91.97:8666'
// apiUrl: 'http://47.100.214.92:7009'
},
onLaunch: function () {
if (wx.canIUse('getUpdateManager')) {
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
// 请求完新版本信息的回调
if (res.hasUpdate) {
updateManager.onUpdateReady(function () {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: function (res) {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(function () {
// 新的版本下载失败
wx.showModal({
title: '已经有新版本了哟~',
content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
})
})
}
})
}
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now());
wx.setStorageSync('logs', logs);
/**
* 作为图传次数保护
*/
let now = new Date();
now = now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + now.getDate();
wx.setStorageSync('date', now);
wx.setStorageSync('timeMap',{});
},
getCode:function(callback){
wx.login({
success: function (res) {
callback(res.code);
}
})
},
warning:function(content){
wx.showModal({
content: ''+content,
showCancel: false
});
},
reLaunchLoginPage: function () {
//token不正确时,清除本地token并跳转至登录界面
wx.removeStorageSync('server_token');
wx.reLaunch({
url: '/pages/login/index',
})
},
getDateStrByTimeStr:function(time){
var dateTime = new Date(time);
var dateStr = '';
dateStr += dateTime.getFullYear() + '年';
dateStr += (dateTime.getMonth()+1) + '月';
dateStr += dateTime.getDate() + '日';
dateStr += dateTime.getHours() + '时';
dateStr += dateTime.getMinutes() + '分';
return dateStr;
}
})