login-button.js
2.56 KB
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
import { GET, POST } from '../../libs/request';
import { API_HOST } from '../../libs/config';
Component({
// externalClasses: ['login-class'],
/**
* 组件的属性列表
*/
properties: {
openType: {
type: String,
value: '',
observer(newVal) {
if (newVal === 'getPhoneNumber') {
let app = getApp()
let param = {
method: 'app.passport.signinByOpenID',
openId: app.globalData.WXUnion_ID,
nickname: app.globalData.userInfo.nickName || '',
}
POST(API_HOST, param)
.then(data => {
if (data && data.data.is_bind === 'Y') {
this.setData({
myOpenType: '',
goBind: false
})
} else {
this.setData({
myOpenType: newVal,
goBind: true
})
}
}).catch(error => {
this.setData({
myOpenType: newVal,
goBind: true
});
});
} else {
this.setData({
myOpenType: newVal,
goBind: true
})
}
}
},
plain: {
type: Boolean,
value: false
}
},
/**
* 组件的初始数据
*/
data: {
myOpenType: '',
goBind: true
},
/**
* 组件的方法列表
*/
methods: {
getUserInfo(e) {
console.log(e.detail);
this.triggerEvent('getuserinfo', e.detail);
},
wechatBindUnionId() {
if (this.data.goBind) return;
let app = getApp()
let param = {
method: 'app.passport.signinByOpenID',
openId: app.globalData.WXUnion_ID,
nickname: app.globalData.userInfo.nickName || '',
}
POST(API_HOST, param)
.then(data => {
if (data && data.data.is_bind === 'Y') {
let resData = data.data;
let userInfo = app.globalData.userInfo;
userInfo.is_bind = resData.is_bind;
userInfo.mobile = resData.mobile;
userInfo.ssouid = resData.ssouid;
userInfo.uid = resData.uid;
app.setUserInfo(userInfo);
app.setSessionkey(resData.session_key);
this.triggerEvent('updateuserinfo', userInfo);
} else {
this.setData({
myOpenType: 'getPhoneNumber',
goBind: true
});
}
});
},
getPhoneNumber(e) {
console.log(e.detail);
this.triggerEvent('getphonenumber', e.detail);
}
}
})