forked from vincenth520/pinche_xcx_vip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
93 lines (86 loc) · 2.04 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
//app.js
var util = require('utils/util.js');
App({
onLaunch: function () {
// wx.setEnableDebug({
// enableDebug: true
// })
var that = this;
//小程序初始化先判断用户是否登录
wx.checkSession({
success: function(){
wx.getStorage({
key: 'sk',
success: function(res) {
var sk = res.data;
util.req('customer/vaild_sk', { "sk": sk }, function (data) {
if (data.status) {
that.globalData.sk = sk;
} else {
that.login();
return;
}
})
},
fail:function() {
that.login();
return;
}
})
wx.getStorage({
key: 'userInfo',
success: function(res) {
that.globalData.userInfo = res.data;
},
fail:function() {
that.login();
}
});
},
fail: function(){
//登录态过期
that.login() //重新登录
}
})
},
login:function(){
wx.reLaunch({
url: '/pages/toLogin/toLogin'
})
} ,
loginFail: function () {
var that = this;
wx.showModal({
content: '登录失败,请允许获取用户信息,如不显示请删除小程序重新进入',
showCancel: false
});
that.login();
},
setUserInfo:function(data){ //将用户信息缓存保存
this.globalData.userInfo = data;
wx.setStorage({
key:"userInfo",
data:data
})
},
setSk:function(data){ //将用户信息缓存保存
this.globalData.sk = data;
wx.setStorage({
key:"sk",
data:data
})
},
reflashUser:function(){
var that = this;
util.req('customer', [], function (data) {
if (data.data == null){
that.login();
}
that.setUserInfo(data.data);
})
},
globalData:{
userInfo:null,
sk:null
}
})