qidong.vue
3.0 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<template>
<div class="box">
<div class="topimg">
<image src="../../static/img/logo.png"></image>
</div>
<div class="bottom">
<div class="bottom_btn">
<button class='bottom_anniu' open-type="getUserInfo" withCredentials="true" lang="zh_CN" @getuserinfo="wxGetUserInfo"
hover-class="none">
授权登录
</button>
</div>
<div class="quxiao" @click="cancel">取消</div>
</div>
</div>
</template>
<script>
import app from "../../App.vue"
export default {
data() {
return {
code: "",
nickname: "",
avatar: "",
}
},
methods: {
// 暂不授权
no_grant() {
uni.navigateBack();
},
// 获取到code
get_code() {
let t = this;
uni.login({
provider: "weixin",
success(r) {
console.log(r.code)
t.code = r.code
}
})
},
// 用code换去sessionkey和openid
//第一授权获取用户信息===》按钮触发
wxGetUserInfo() {
let t = this;
uni.getUserInfo({
provider: 'weixin',
success: function(infoRes) {
console.log(infoRes)
let param = {
code: t.code,
nickname: infoRes.userInfo.nickName,
avatar: infoRes.userInfo.avatarUrl
}
// t.nickname = infoRes.nickname;
// t.avatar=infoRes.userInfo.avatarUrl
app.post("api/user/login", param, 'post')
.then(res => {
console.log(res,"返回token");
uni.setStorageSync('token', res.userInfo.token);
uni.setStorageSync("openid",res.openid);
uni.setStorageSync("re_id",1);
// if(res.userInfo.re_id == 0){
// uni.navigateTo({
// url: '/pages/binding/binding'
// });
// }else{
uni.switchTab({
url: '/pages/taocangoumai/taocangoumai'
});
// }
})
.catch(err => {});
// t avatar = infoRes.userInfo.avatarUrl;
},
fail(res) {}
});
},
// 取消登录
cancel() {
uni.switchTab({
url: '/pages/taocangoumai/taocangoumai'
})
}
},
onLoad() {
this.get_code()
}
}
</script>
<style>
page {
background: #fff;
}
.box {
background: #fff;
}
.topimg {
width: 180rpx;
height: 200rpx;
font-size: 0;
margin: 250rpx auto 0;
}
.topimg image {
width: 100%;
height: 100%;
}
.bottom_btn {
width: 580rpx;
height: 100rpx;
background: rgba(243, 152, 0, 1);
box-shadow: 0rpx 4rpx 18rpx rgba(0, 0, 0, 0.04);
opacity: 1;
border-radius: 10rpx;
color: #fff;
font-size: 32rpx;
text-align: center;
line-height: 100rpx;
margin: 454rpx auto 0;
}
button {
width: 580rpx;
height: 100rpx;
text-align: center;
line-height: 100rpx;
border: none;
outline: none;
background: transparent;
color: #fff;
font-size: 32rpx;
}
button::after {
border: none;
background: transparent;
}
.quxiao {
width: 580rpx;
height: 100rpx;
border: 2rpx solid rgba(243, 152, 0, 1);
opacity: 1;
border-radius: 10rpx;
color: #F39800;
font-size: 32rpx;
text-align: center;
line-height: 100rpx;
margin: 40rpx auto 0;
}
</style>