|
|
@@ -31,7 +31,8 @@
|
|
|
<button
|
|
|
class="wechat-btn"
|
|
|
:loading="loading"
|
|
|
- @click="handleWechatLogin"
|
|
|
+ open-type="getPhoneNumber"
|
|
|
+ @getphonenumber="onGetPhoneNumber"
|
|
|
>
|
|
|
<text class="wechat-icon">微信</text>
|
|
|
<text>一键登录</text>
|
|
|
@@ -63,6 +64,7 @@ export default {
|
|
|
agreed: false,
|
|
|
nickname: '',
|
|
|
avatar: '',
|
|
|
+ phoneCode: '',
|
|
|
redirectUrl: ''
|
|
|
}
|
|
|
},
|
|
|
@@ -94,6 +96,13 @@ export default {
|
|
|
url: '/pages/policy/privacy'
|
|
|
})
|
|
|
},
|
|
|
+ onGetPhoneNumber(e) {
|
|
|
+ if (e.detail && e.detail.code) {
|
|
|
+ this.phoneCode = e.detail.code
|
|
|
+ }
|
|
|
+ // 无论是否授权手机号,都执行微信登录
|
|
|
+ this.handleWechatLogin()
|
|
|
+ },
|
|
|
handleWechatLogin() {
|
|
|
if (!this.agreed) {
|
|
|
uni.showToast({ title: '请先同意用户协议', icon: 'none' })
|
|
|
@@ -117,10 +126,12 @@ export default {
|
|
|
fail: function() { reject(new Error('微信登录失败')) }
|
|
|
})
|
|
|
})]).then(function(loginRes) {
|
|
|
+ var phoneCodeToSend = self.phoneCode
|
|
|
+ self.phoneCode = '' // 使用后清空
|
|
|
wechatLogin(loginRes.code, {
|
|
|
nickname: self.nickname || '用户',
|
|
|
avatar: self.avatar || ''
|
|
|
- }).then(function(res) {
|
|
|
+ }, phoneCodeToSend).then(function(res) {
|
|
|
// 保存 token 和用户信息(只写一次)
|
|
|
uni.setStorageSync('token', res.data.token)
|
|
|
uni.setStorageSync('userId', res.data.userId)
|