-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
125 lines (108 loc) · 3.35 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//app.js
App({
onLaunch: function () {
// 展示本地存储能力
var that = this;
//获取屏幕设备属性
wx.getSystemInfo({
success: e => {
that.globalData.StatusBar = e.statusBarHeight;
let custom = wx.getMenuButtonBoundingClientRect();
that.globalData.Custom = custom;
let CustomBar = custom.bottom + custom.top - e.statusBarHeight;
if (CustomBar < 0) {
CustomBar = 80
}
that.globalData.CustomBar = CustomBar;
//适配全面屏底部距离
if (CustomBar > 75) {
that.globalData.tabbar_bottom = "y"
}
},
fail: e => {
console.log('failed ')
that.globalData.StatusBar = 22
that.globalData.CustomBar = 66
that.globalData = false
}
})
// 登录
wx.login({
success: res => {
//code 用于获取openID的条件之一
var code = res.code;
wx.request({
url: that.globalData.urlPath + 'wxgetopenid/',
method: "POST",
data: {
code: code,
},
header: {
'content-type': 'application/x-www-form-urlencoded' // 默认值
},
success: function (res) { //后端返回的数据
//console.log(res.data)
let uid = res.data.uid;
let sessionid = res.data.sessionid;
let role = res.data.role;
that.globalData.openid = uid
that.globalData.sessionid = sessionid
that.globalData.role = role
console.log('init role='+role)
wx.setStorageSync('openid', uid)
wx.setStorageSync('sessionid', sessionid)
wx.setStorageSync('role', role)
},
fail: res => {
toast.show({ content: '微信登录失败' });
}
});
}
}) // end of login
// 获取用户信息
wx.getSetting({
success: res => {
//console.log('wx.getsetting')
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId
// console.log(res.userInfo)
this.globalData.userInfo = res.userInfo
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (that.userInfoReadyCallback) {
that.userInfoReadyCallback(res)
}
},
fail: function () {
// fail
console.log("获取失败!")
},
complete: function () {
// complete
// console.log("获取用户信息完成!")
}
})
} else {
//弹出授权框
// console.log('要求授权')
//wx.showLoading()
}
}
})
},
globalData: {
userInfo: null,
urlPath: 'https://fg.heyishe.cn/wx/',
openid: null,
sessionid:null,
role:null,
Custom: null,
StatusBar: '20',
CustomBar: '65',
tabbar_bottom: '',
state: true,
}
})