|
@@ -13,36 +13,45 @@ Page({ |
|
@@ -13,36 +13,45 @@ Page({ |
13
|
// 获取用户信息
|
13
|
// 获取用户信息
|
14
|
start(e) {
|
14
|
start(e) {
|
15
|
let self = this;
|
15
|
let self = this;
|
16
|
- wx.checkSession({
|
|
|
17
|
- success: function () {
|
|
|
18
|
- console.log('未过期');
|
|
|
19
|
- //session_key 未过期,并且在本生命周期一直有效
|
|
|
20
|
- let url = '/wxapp/public/login';
|
|
|
21
|
- let params = {
|
|
|
22
|
- encrypted_data: e.detail.encryptedData,
|
|
|
23
|
- iv: e.detail.iv,
|
|
|
24
|
- raw_data: e.detail.rawData,
|
|
|
25
|
- signature: e.detail.signature,
|
|
|
26
|
- openid: self.data.openid,
|
|
|
27
|
- session_key: self.data.session_key,
|
|
|
28
|
- };
|
|
|
29
|
- app.post(url, params).then((ret) => {
|
|
|
30
|
- wx.setStorageSync('token', ret.token);
|
|
|
31
|
- app.globalData.userInfo = ret.user_type;
|
|
|
32
|
- if (wx.getStorageSync('token') !== '') {
|
|
|
33
|
- self.checkMobile();
|
|
|
34
|
-
|
|
|
35
|
-
|
|
|
36
|
- }
|
|
|
37
|
- // console.log('userInfo',app.globalData.userInfo,ret);
|
|
|
38
|
- })
|
|
|
39
|
- },
|
|
|
40
|
- fail: function () {
|
|
|
41
|
- console.log('session_key 已经失效');
|
|
|
42
|
- // session_key 已经失效,需要重新执行登录流程
|
|
|
43
|
- self.login() //重新登录
|
|
|
44
|
- }
|
|
|
45
|
- })
|
16
|
+ // console.log(self.data.openid === '', self.data.session_key === '');
|
|
|
17
|
+ if(self.data.openid === '' || self.data.session_key === '') {
|
|
|
18
|
+ wx.showLoading({title: '请稍候', mask: true});
|
|
|
19
|
+ self.login();
|
|
|
20
|
+ setTimeout(function () {
|
|
|
21
|
+ wx.hideLoading()
|
|
|
22
|
+ }, 1000);
|
|
|
23
|
+ }else {
|
|
|
24
|
+ wx.checkSession({
|
|
|
25
|
+ success: function () {
|
|
|
26
|
+ console.log('未过期');
|
|
|
27
|
+ //session_key 未过期,并且在本生命周期一直有效
|
|
|
28
|
+ let url = '/wxapp/public/login';
|
|
|
29
|
+ let params = {
|
|
|
30
|
+ encrypted_data: e.detail.encryptedData,
|
|
|
31
|
+ iv: e.detail.iv,
|
|
|
32
|
+ raw_data: e.detail.rawData,
|
|
|
33
|
+ signature: e.detail.signature,
|
|
|
34
|
+ openid: self.data.openid,
|
|
|
35
|
+ session_key: self.data.session_key,
|
|
|
36
|
+ };
|
|
|
37
|
+ app.post(url, params).then((ret) => {
|
|
|
38
|
+ wx.setStorageSync('token', ret.token);
|
|
|
39
|
+ app.globalData.userInfo = ret.user_type;
|
|
|
40
|
+ if (wx.getStorageSync('token') !== '') {
|
|
|
41
|
+ self.checkMobile();
|
|
|
42
|
+
|
|
|
43
|
+
|
|
|
44
|
+ }
|
|
|
45
|
+ // console.log('userInfo',app.globalData.userInfo,ret);
|
|
|
46
|
+ })
|
|
|
47
|
+ },
|
|
|
48
|
+ fail: function () {
|
|
|
49
|
+ console.log('session_key 已经失效');
|
|
|
50
|
+ // session_key 已经失效,需要重新执行登录流程
|
|
|
51
|
+ self.login() //重新登录
|
|
|
52
|
+ }
|
|
|
53
|
+ })
|
|
|
54
|
+ }
|
46
|
},
|
55
|
},
|
47
|
login() {
|
56
|
login() {
|
48
|
let self = this;
|
57
|
let self = this;
|