-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
103 lines (98 loc) · 2.3 KB
/
Copy pathapp.js
File metadata and controls
103 lines (98 loc) · 2.3 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* 运行时全局变量
*/
let _globalData = {
userInfo:null,
toname:'',
wishes:'',
// in case
// 在更多页面中选则某条祝福话后,直接覆盖上面的wishes字段,而用户却在自定义页面选择了取消或返回
tempwishes:'',
temptoname:'',
tempnickname:''
}
//app.js
App({
onLaunch: function () {
//调用API从本地缓存中获取数据
/*var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)*/
/*wx.clearStorage()*/
},
/**
* 读取与修改运行时全局变量的方法
*/
getUserInfo:function(cb){
var that = this
if(_globalData.userInfo){
typeof cb == "function" && cb(_globalData.userInfo)
}else{
//调用登录接口
wx.login({
success: function () {
wx.getUserInfo({
success: function (res) {
_globalData.userInfo = res.userInfo
typeof cb == "function" && cb(_globalData.userInfo)
}
})
}
})
}
},
setUserInfo:function(userInfo){
var that = this;
if (_globalData.userInfo){
_globalData.userInfo = userInfo;
return;
}
that.getUserInfo();
},
getTempNickName : function(){
return _globalData.tempnickname
},
setTempNickName : function(nickname){
_globalData.tempnickname = nickname;
},
clearTempNickName :function(){
_globalData.tempnickname = '';
},
getToName : function(isTemp){
if (isTemp){
return _globalData.temptoname
}else{
return _globalData.toname;
}
},
setToName : function(toname,isTemp){
if (isTemp){
_globalData.temptoname = toname;
}else{
_globalData.toname = toname;
}
},
clearTempToName: function(){
_globalData.temptoname = '';
},
setWishes : function(content,isTemp){
if (isTemp){
_globalData.tempwishes = content;
}else{
_globalData.wishes = content;
}
},
getWishes : function(isTemp){
if (isTemp){
return _globalData.tempwishes;
}
return _globalData.wishes;
},
clearWishes: function(isTemp){
if (isTemp){
_globalData.tempwishes = '';
}else{
_globalData.wishes = '';
}
}
})