-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathapp.js
96 lines (96 loc) · 2.3 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
//app.js
App({
onLaunch: function () {
wx.getNetworkType({
success: function(res) {
var networkType = res.networkType // 返回网络类型2g,3g,4g,wifi
console.log(networkType)
if(networkType!="4g" && networkType!="wifi"){
wx.showToast({
title: "您的"+networkType+"网络较慢",
icon: 'loading',
duration: 10000
});
}
}
})
},
getUserInfo:function(cb){
var that = this
if(this.globalData.userInfo){
typeof cb == "function" && cb(this.globalData.userInfo)
}else{
//调用登录接口
wx.login({
success: function (res) {
wx.getUserInfo({
success: function(info){
var edata = {code: res.code, encryptedData: info.encryptedData, iv: info.iv};
if (res.code) {
//发起网络请求
wx.request({
url: that.globalData.domain+'/api/v1/getWxUser',
data: edata,
method: 'POST',
success: function(data) {
that.globalData.userInfo = data.data;
typeof cb == "function" && cb(that.globalData.userInfo)
}
})
} else {
console.log('获取用户登录态失败!' + res.errMsg)
}
}
})
}
})
}
},
globalData:{
userInfo:null,
domain: "",//输入你的https地址:如 https://xxx.com
//TODO:cates这里最好是用接口获取数据,这样能和网站同步
cates: [
{
id: "all",
name: "全部",
selected: true
},
{
id: "h5",
name: "HTML/CSS",
selected: false
},
{
id: "js",
name: "JavaScript",
selected: false
},
{
id: "jquery",
name: "jQuery",
selected: false
},
{
id: "nodejs",
name: "Node.js",
selected: false
},
{
id: "wx",
name: "微信开发",
selected: false
},
{
id: "job",
name: "招聘",
selected: false
},
{
id: "career",
name: "职业生涯",
selected: false
}
]
}
})