-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
59 lines (55 loc) · 1.86 KB
/
Copy pathapp.js
File metadata and controls
59 lines (55 loc) · 1.86 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
App({
globalData: {
userInfo: null,
selectedUniversity: null,
userActivities: [],
createdActivities: [],
chatrooms: [],
friends: [],
messages: {}
},
onLaunch() {
this.loadData();
},
loadData() {
try {
const userInfo = wx.getStorageSync('userInfo');
const selectedUniversity = wx.getStorageSync('selectedUniversity');
const userActivities = wx.getStorageSync('userActivities') || [];
const createdActivities = wx.getStorageSync('createdActivities') || [];
const chatrooms = wx.getStorageSync('chatrooms') || [];
const friends = wx.getStorageSync('friends') || [];
const messages = wx.getStorageSync('messages') || {};
if (userInfo) {
this.globalData.userInfo = userInfo;
}
if (selectedUniversity) {
this.globalData.selectedUniversity = selectedUniversity;
}
this.globalData.userActivities = userActivities;
this.globalData.createdActivities = createdActivities;
this.globalData.chatrooms = chatrooms;
this.globalData.friends = friends;
this.globalData.messages = messages;
} catch (e) {
console.error('加载数据失败', e);
}
},
saveData() {
try {
if (this.globalData.userInfo) {
wx.setStorageSync('userInfo', this.globalData.userInfo);
}
if (this.globalData.selectedUniversity) {
wx.setStorageSync('selectedUniversity', this.globalData.selectedUniversity);
}
wx.setStorageSync('userActivities', this.globalData.userActivities);
wx.setStorageSync('createdActivities', this.globalData.createdActivities);
wx.setStorageSync('chatrooms', this.globalData.chatrooms);
wx.setStorageSync('friends', this.globalData.friends);
wx.setStorageSync('messages', this.globalData.messages);
} catch (e) {
console.error('保存数据失败', e);
}
}
})