-
Notifications
You must be signed in to change notification settings - Fork 17
/
app.js
171 lines (164 loc) · 4.81 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
const api = require('./utils/api');
const storage = require('./utils/storage');
const eventBus = require('./utils/eventBus');
App({
require: path => require(path),
api: api,
storage: storage,
eventBus: eventBus,
globalData: {},
onLaunch: function () {
storage.setKey('isQQ', typeof qq !== 'undefined');
// 初始化云函数
if (!storage.getKey('isQQ')) {
wx.cloud.init({
env: 'nuc-code-eeed10',
traceUser: true,
});
}
wx.getSystemInfo({
success: e => {
storage.setKey('statusBarHeight', e.statusBarHeight);
let custom = {
width: 80,
height: 30,
left: e.windowWidth - 12 - 80,
right: e.windowWidth - 12,
top: e.statusBarHeight + 10,
bottom: e.statusBarHeight + 10 + 30,
};
try {
if (!storage.getKey('isQQ')) {
custom = wx.getMenuButtonBoundingClientRect();
}
} catch (error) {}
storage.setKey(
'customBarHeight',
custom.bottom + custom.top - e.statusBarHeight
);
},
});
// 学期第一天
api.request({
dontShowLoading: true,
rawData: true,
url: 'static/firstWeekDateTime',
data: {},
callBack: res => {
storage.setKey('firstWeekDateTime', res);
},
});
if (!storage.getKey('version')) {
storage.setKey('updated', wx.getStorageSync('updated'));
storage.setKey('name', wx.getStorageSync('name'));
storage.setKey('password', wx.getStorageSync('passwd'));
storage.setKey('mapModalShowed', wx.getStorageSync('mapShowed'));
storage.setKey('openId', wx.getStorageSync('openId'));
storage.setKey('updatedPassword', wx.getStorageSync('updatedPasswd'));
storage.setKey('lastShowNoticeID', wx.getStorageSync('lastShowNoticeID'));
storage.setKey(
'dontShowLatestNotice',
wx.getStorageSync('dontShowLatestNotice')
);
eventBus.emit('updateKey');
// 需要重新登录
if (storage.getKey('name') && !storage.getKey('updatedPassword')) {
// storage.removeKey('customTimetable')
storage.removeKey('accountList');
storage.removeKey('name');
storage.removeKey('password');
wx.showModal({
title: '需重新登录',
content: '已适配新教务系统,需重新登录,默认密码“zbdx+身份证后六位”',
confirmText: '去登陆',
confirmColor: '#79bd9a',
showCancel: false,
success: function (res) {
if (res.confirm) {
wx.navigateTo({
url: '/pages/my/login/login',
});
}
},
});
}
}
if (storage.getKey('name') === 'guest') {
storage.removeKey('name');
storage.removeKey('password');
}
// 向下兼容
if (storage.getKey('name') && storage.getKey('version') < '2.2.1') {
storage.setKey('accounts', [
{
name: storage.getKey('name'),
password: storage.getKey('password'),
},
]);
}
if (!storage.getKey('name')) {
storage.setKey('accounts', []);
}
storage.setKey('version', '2.3.3');
// 新版本检查
const updateManager = wx.getUpdateManager();
updateManager.onCheckForUpdate(function (res) {
if (res.hasUpdate) {
console.log('检测到新版本');
}
});
updateManager.onUpdateReady(function () {
storage.setKey('updated', true);
updateManager.applyUpdate();
});
updateManager.onUpdateFailed(function () {
wx.showToast({
title: '版本更新失败',
});
});
// 获取 OpenID
this.getOpenId();
if (storage.getKey('updated') === true) {
storage.setKey('updated', false);
wx.showModal({
title: '更新完成',
content: '已更新到最新版本,是否查看版本说明?',
success: function (res) {
if (res.confirm) {
wx.navigateTo({
url: '/pages/more/releaseNote/releaseNote',
});
}
},
});
}
if (storage.getKey('insider')) {
api.request({
dontShowLoading: true,
url: `v3/insiders/${storage.getKey('openId')}`,
data: {},
callBack: data => {
if (data.status === -3 || data.status === -2 || data.status == -1) {
storage.removeKey('insider');
return;
}
storage.setKey('insider', data);
},
});
}
},
getOpenId: function () {
if (storage.getKey('isQQ')) {
return;
}
if (!storage.getKey('openId')) {
wx.cloud.callFunction({
name: 'getOpenId',
complete: res => {
storage.setKey('openId', res.result.openId);
eventBus.emit('updateKey');
},
});
}
},
});