login.vue
3.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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<template>
<view class="Login">
<view class="" style="padding-top:216rpx;box-sizing: border-box;text-align: center;">
<image src="/static/image/logo.png" mode="" style="width: 160rpx;height: 160rpx;"></image>
<view class="title">
社区淘
</view>
<view class="desc">
来到社区淘,闲置就近卖
</view>
</view>
<view class="btn" v-if="checked">
登录
<button class="sys_btn" open-type="getUserInfo" lang="zh_CN" @getuserinfo="appLoginWx"></button>
</view>
<view class="btn1" v-if="!checked" @click="login">
登录
</view>
<view class="uni-padding-wrap">
<view style="text-align: center;font-size: 24rpx;">
<label class="radio" @change="radioChange"
style="display: flex;align-items: center;justify-content: center;">
<radio value="r1" :checked="checked" @click="radioChange" color="#FF834D" />
<text @click="radioText">我已阅读并同意</text><text style="color:#FF834D;" @click.stop="goUserDeal">《用户服务协议》</text>
</label>
</view>
</view>
</view>
</template>
<script>
import request from '../../utils/request.js'
export default {
data() {
return {
checked: false
}
},
methods: {
radioChange(e) {
this.checked = !this.checked
},
radioText(){
this.checked = !this.checked
},
//用户协议
goUserDeal() {
uni.navigateTo({
url: '/myPackage/pages/me/user-deal'
})
},
login() {
uni.showToast({
title: '请选择用户协议',
icon: "none"
})
},
appLoginWx() {
uni.getProvider({
service: 'oauth',
success: function(res) {
if (~res.provider.indexOf('weixin')) {
uni.login({
provider: 'weixin',
success: function(loginRes) {
console.log(loginRes)
// 获取用户信息
uni.getUserInfo({
provider: 'weixin',
success: function(infoRes) {
uni.setStorageSync('userInfo', infoRes
.userInfo)
request.post('/api/common/login', {
code: loginRes.code,
rawData: JSON.stringify(uni
.getStorageSync(
'userInfo')),
pid: uni.getStorageSync('pid')
}).then(res => {
if (res.code == 1) {
uni.setStorageSync(
'userInfo', res
.data.userInfo)
uni.setStorageSync('token',
res.data.userInfo
.token)
uni.navigateTo({
url: '/pages/index/index'
})
}
})
},
fail: () => {
uni.showToast({
title: "微信登录授权失败",
icon: "none"
});
}
});
},
fail: () => {
uni.showToast({
title: "微信登录授权失败",
icon: "none"
});
}
});
}
}
});
}
}
}
</script>
<style>
@import url("/common/uni.css");
.Login {
min-height: 100vh;
background-color: #fff;
}
.btn {
margin: 0 auto;
margin-top: 320rpx;
width: 424rpx;
height: 80rpx;
background: #ff834d;
border: 2rpx solid #FF834D;
position: relative;
font-size: 32rpx;
color: #fff;
text-align: center;
line-height: 80rpx;
border-radius: 48rpx;
position: relative;
}
.btn1 {
margin: 0 auto;
margin-top: 320rpx;
width: 424rpx;
height: 80rpx;
background: #ff834d;
border: 2rpx solid #FF834D;
position: relative;
font-size: 32rpx;
color: #fff;
text-align: center;
line-height: 80rpx;
border-radius: 48rpx;
opacity: 0.5;
}
button {
width: 426rpx;
height: 84rpx;
position: absolute;
top: 0;
left: 0;
background: transparent;
border-radius: 48rpx;
}
radio {
transform: scale(0.6);
}
.uni-padding-wrap {
margin-top: 40rpx;
}
.title {
font-size: 40rpx;
color: #3ba3e0;
}
.desc {
color: #969799;
font-size: 26rpx;
}
</style>