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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<template>
<view>
<uni-popup ref="authorization" background-color="#fff">
<view class="content-page" @touchmove="stopTouchMove">
<view class="img-box">
<image style="width: 100rpx; height: 100rpx;margin:22rpx;" mode="aspectFill" src="../static/images/logo.png"></image>
</view>
<view class="text">为了更完美的体验,请授权获取电话</view>
<button v-if="checked" class="login-btn" type="primary" open-type="getPhoneNumber" @getphonenumber="onGetPhoneNumber" hover-class="none">手机号登录/注册</button>
<button v-else class="login-btn" type="primary" @click="verifyPolicy" hover-class="none">手机号登录/注册</button>
<view class="refuse" @click="refuse">取消</view>
<view class="policy-fixed">
<checkbox-group @change="changePolicy">
<label>
<view class="policy-box">
<checkbox value="true" :checked="checked" color="#1677FF" style="transform:scale(0.7)" />
<text class="text">我已阅读并同意</text>
<text class="policy" @click.stop="readAgreement">《用户服务协议》</text>
<text class="text">和</text>
<text class="policy" @click.stop="readPolicy">《隐私政策》</text>
</view>
</label>
</checkbox-group>
</view>
</view>
</uni-popup>
</view>
</template>
<script>
import {
analysisMobileApi,
getPropertyLoginApi,
bindingUserInfoApi
} from "@/config/api.js"
export default {
data() {
return {
checked: false,
result: {}
}
},
watch: {
checked(newV) {
if(newV) {
let _this = this
wx.login({
success (res) {
if (res.code) {
_this.getCode(res.code)
}
}
})
}
}
},
methods: {
async getCode(code) {
let {result} = await getPropertyLoginApi({code}, {custom: {load: false}})
this.result = {...result}
},
onOpenLogin() {
this.$refs.authorization.open('center')
},
stopTouchMove() {
return false
},
refuse() {
this.$emit('refuse')
this.$refs.authorization.close()
uni.showToast({
icon: "none",
title: '您拒绝了授权,登录失败!'
})
},
verifyPolicy(e) {
if(!this.checked) {
uni.showToast({
title: '请先同意协议和政策',
icon: 'none'
});
return
}
},
//获取手机号
onGetPhoneNumber(e) {
let _this = this
if (e.detail.errMsg === "getPhoneNumber:fail user deny") { //用户决绝授权
//拒绝授权后弹出一些提示
uni.showModal({
content: '您拒绝了授权,登录失败!',
showCancel: false
})
} else { //允许授权
_this.getUserPhone(e)
}
},
// 获取手机号
async getUserPhone(e) {
let res = await analysisMobileApi({
code: e.detail.code,
iv: e.detail.iv,
encryptedData: e.detail.encryptedData,
sessionKey: this.result.sessionKey
})
if (res.code === 200 && res.result) {
uni.setStorageSync('openid', this.result.openid);
let data = JSON.parse(res.result)
uni.setStorageSync('user_phone', data.purePhoneNumber);
this.$emit('loginEnd')
this.$refs.authorization.close()
}
},
// 绑定用户
// async onbindingUserInfo(openId, phone) {
// let res = await bindingUserInfoApi({openId, phone})
// if(res.code === 200 && res.result) {
// uni.setStorageSync('openid', res.result.communityUser.openid);
// if(res.result.communityOwners && res.result.communityOwners.length) { // 业主
// this.$emit('loginEnd', true)
// } else if(res.result.employeeVos && res.result.employeeVos.comList.length) { // 维修员
// this.$emit('loginEnd', true)
// } else {
// this.$emit('loginEnd', false)
// }
// this.$refs.authorization.close()
// }
// },
changePolicy(e) {
this.checked = e.detail.value.length === 1
},
readPolicy() {
uni.navigateTo({
url: '/pages/policy/policy'
})
},
readAgreement() {
uni.navigateTo({
url: '/pages/policy/agreement'
})
}
}
}
</script>
<style lang="scss">
.content-page {
width: 100vw;
height: 100vh;
overflow: hidden;
display: flex;
flex-direction: column;
align-items: center;
position: relative;
.img-box {
width: 144rpx;
height: 144rpx;
border: 2rpx solid #E4E6E9;
border-radius: 50%;
margin-top: 200rpx;
}
.text {
font-size: 28rpx;
color: #3D3D3D;
line-height: 50rpx;
margin-top: 50rpx;
}
.login-btn {
width: 578rpx;
height: 80rpx;
line-height: 80rpx;
font-size: 28rpx;
color: #FFFFFF;
background: #6799F1;
border-radius: 200rpx;
margin-top: 72rpx;
}
.refuse {
font-size: 28rpx;
color: #767676;
line-height: 33rpx;
margin-top: 34rpx;
}
.policy-fixed {
position: fixed;
bottom: 160rpx;
left: 0;
right: 0;
z-index: 11;
.policy-box {
padding: 0 30rpx;
font-size: 14px;
vertical-align: middle;
.text {
color: #191A23;
vertical-align: middle;
}
.policy {
color: #1677FF;
vertical-align: middle;
}
}
}
}
</style>