-
Notifications
You must be signed in to change notification settings - Fork 63
/
app.js
63 lines (62 loc) · 2.12 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
var config = require('config.js')
var http = require('./utils/httpHelper.js')
var util = require('./utils/util.js')
//app.js
App({
onLaunch: function () {
//调用API从本地缓存中获取数据
var that = this;
this.getUserInfo(null);
},
getUserInfo:function(cb){
var that = this
if(this.globalData.userInfo){
typeof cb == "function" && cb(this.globalData.userInfo)
}else{
//调用登录接口
wx.login({
success: function(res) {
if (res.code) {
var code = res.code;
wx.getUserInfo({
success: function (res) {
//发起网络请求
var userInfo = res.userInfo;
that.globalData.userInfo = userInfo;
var data ={ username:userInfo.nickName,avatar:userInfo.avatarUrl,code: code,appid:config.APPID}
http.httpGet("?c=user&a=wxlogin" ,data,function(res){
if(res.code == '200' && res.msg == 'success'){
userInfo.id = res.data.id;
that.globalData.userInfo = userInfo;
typeof cb == "function" && cb(userInfo)
}
});
}
});
} else {
console.log('获取用户登录态失败!' + res.errMsg)
}
}
});
}
},
getAppInfo:function(cb){
//获取商品信息
var that = this;
if(this.globalData.appInfo){
typeof cb == "function" && cb(this.globalData.appInfo)
}else{
var data = {appid:config.APPID}
http.httpGet("?c=myapp&a=getmyapp" ,data,function(res){
if(res.code == '200' && res.msg == 'success'){
that.globalData.appInfo = res.data;
typeof cb == "function" && cb(that.globalData.appInfo)
}
});
}
},
globalData:{
userInfo:null,
appInfo:null,
}
})