forked from choyri/WeGifun
-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.js
111 lines (104 loc) · 2.97 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
let appParams = {
SERVER_URL: 'https://mydlpu.xu42.cn',
VERSION: 'v0.1.0',
event: require('./utils/event'),
cache: {},
week: 0,
semester: '2016-2017-2'
};
appParams.onLaunch = function() {
try {
let data = wx.getStorageInfoSync();
if (data.keys.length) {
data.keys.forEach((key) => {
try {
this.cache[key] = wx.getStorageSync(key);
} catch(e) {
console.error('getStorage 失败。详细信息:' + e.message);
}
});
}
} catch(e) {
console.error('getStorageInfo 失败。详细信息:' + e.message);
}
};
appParams.saveData = function(obj) {
for (let key in obj) {
this.cache[key] = obj[key];
wx.setStorage({
key: key,
data: obj[key],
})
}
}
appParams.getTime = function() {
wx.request({
url: this.SERVER_URL + '/api/mina/time',
method: 'get',
success: (res) => {
if (res.statusCode != 200) {
wx.showModal({
title: '啊喔',
content: res.data.errmsg,
showCancel: false
});
} else { //正确获取数据
let data = res.data;
this.saveData({
'semester': data.semester,
'week': data.week,
'timeUpdateTime': (new Date()).getTime()
});
}
},
fail: () => {
wx.showModal({
title: '啊喔',
content: '要么是你网络问题, 要么是服务器挂了~',
showCancel: false
});
}
});
}
appParams.getCourses = function(id, pwd) {
wx.clearStorage();
this.getTime();
wx.request({
url: this.SERVER_URL + '/api/mina/timetable',
data: {
stuid: id,
stupwd: pwd,
semester: this.cache.semester,
week: this.cache.week,
},
method: 'get',
success: (res) => {
if (res.statusCode != 200) {
wx.showModal({
title: '啊喔',
content: res.data.errmsg,
showCancel: false
});
} else { //正确获取数据
let data = res.data;
this.saveData({
'courses': data,
'stuInfo': [id, pwd],
'updateTime': (new Date()).getTime()
});
this.event.emit('getCoursesSuccess');
}
},
fail: () => {
wx.showModal({
title: '啊喔',
content: '要么是你网络问题, 要么是服务器挂了~',
showCancel: false
});
},
complete: () => {
this.event.emit('getCoursesComplete');
}
});
}
App(appParams);