index.js
2.9 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
107
108
109
110
111
112
113
114
115
116
117
118
119
import {
request
} from "../../request/index.js"
const a = getApp()
Component({
/**
* 组件的属性列表
*/
properties: {
},
/**
* 组件的初始数据
*/
data: {
imagesUrl: a.globalData.baseUrl,
canIUseGetUserProfile: false,
showDialog: false
},
onload() {
},
/**
* 组件的方法列表
*/
methods: {
getLogin(dens) {
console.log(dens);
if (wx.getUserProfile) {
this.setData({
canIUseGetUserProfile: true
})
}
this.toggleDialog()
},
bindGetUserInfo(e) { // 立即授权
let that = this;
wx.login({
success(res) {
console.log(res);
that.setData({
code: res.code
})
request({
url: 'api/common/login',
method: "POST",
data: {
rawData: e.detail.rawData,
code: that.data.code,
}
})
.then(res => {
console.log(res);
if (res.data.code == 1) {
wx.setStorageSync('token', res.data.data.userInfo.token);
wx.setStorageSync('avatar', res.data.data.userInfo.avatar);
wx.setStorageSync('name', res.data.data.userInfo.nickname);
wx.setStorageSync('user_id', res.data.data.userInfo.user_id);
}
console.log(res.data.data.userInfo.token);
that.toggleDialog()
a.popSuccessTest(res.data.msg);
that.getDetailsContent()
}).catch(err => {
console.log(err);
})
}
})
},
getUserProfile() {
let that = this
wx.login({
success(res) {
console.log(res);
that.setData({
code: res.code
})
}
})
wx.getUserProfile({
desc: '用于完善会员资料',
success: async (res) => {
console.log(res);
try {
const {
data
} = await request({
url: 'api/common/newLogin',
method: "POST",
data: {
userInfo: res.userInfo,
code: that.data.code,
}
})
console.log(data);
wx.setStorageSync('token', data.data.userInfo.token);
wx.setStorageSync('avatar', data.data.userInfo.avatar);
wx.setStorageSync('name', data.data.userInfo.nickname);
wx.setStorageSync('user_id', data.data.userInfo.user_id);
that.setData({
showDialog: false
})
a.popSuccessTest(data.msg)
that.triggerEvent('istoken', '李四')
} catch (err) {
console.log(err);
}
}
})
},
toggleDialog() {
this.setData({
showDialog: !this.data.showDialog
})
},
}
})