diff --git a/Pages/login/index.js b/Pages/login/index.js index 1f2505f..76e3fcb 100644 --- a/Pages/login/index.js +++ b/Pages/login/index.js @@ -129,37 +129,47 @@ Page({ let THIS=this; let usertype = wx.getStorageSync('usertype'); let next_url = wx.getStorageSync('next_url'); - wx.login({ - success (res) { - if (res.code) { - console.log('登录成功!' + res.errMsg) - var params = { - phone_code: e.detail.code, - user_type: usertype, - wx_code: res.code - } - api.wechatMobileLogin(params).then(response => { - console.log(response); - wx.setStorageSync('AUTH_TOKEN_'+usertype, response.data.token); - wx.setStorageSync('user_id_'+usertype, response.data.user_id); - wx.setStorageSync('client_user_id_'+usertype, response.data.client_user_id); - app.globalData.config.userID = response.data.user_id; - app.globalData.isLogin=true; - let handleGo=function(){ - wx.switchTab({ - url: next_url - }) + if(e.detail.errMsg == 'getPhoneNumber:ok'){ + wx.login({ + success (res) { + if (res.code) { + console.log('登录成功!' + res.errMsg) + var params = { + phone_code: e.detail.code, + user_type: usertype, + wx_code: res.code } - app.imInit({path:'Pages/login/index'},1,handleGo); - //跳转页面 - - }).catch(errors => { - console.error(errors); - }) - } else { - console.log('登录失败!' + res.errMsg) - } - } - }) + api.wechatMobileLogin(params).then(response => { + console.log(response); + wx.setStorageSync('AUTH_TOKEN_'+usertype, response.data.token); + wx.setStorageSync('user_id_'+usertype, response.data.user_id); + wx.setStorageSync('client_user_id_'+usertype, response.data.client_user_id); + app.globalData.config.userID = response.data.user_id; + app.globalData.isLogin=true; + let handleGo=function(){ + wx.switchTab({ + url: next_url + }) + } + app.imInit({path:'Pages/login/index'},1,handleGo); + //跳转页面 + + }).catch(errors => { + console.error(errors); + }) + } else { + console.log('登录失败!' + res.errMsg) + } + } + }) + }else if(e.detail.errMsg == 'getPhoneNumber:fail user deny'){ + console.log('您拒绝手机号授权') + }else{ + wx.showToast({ + title: '手机号授权失败', + icon:'none' + }) + } + }, }) \ No newline at end of file diff --git a/Pages/login/index.wxml b/Pages/login/index.wxml index 8c29100..d9e0cc7 100644 --- a/Pages/login/index.wxml +++ b/Pages/login/index.wxml @@ -18,11 +18,11 @@ wx:if="{{ checked }}" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber" - color="#09BB07" custom-style="font-size: 36rpx;" type="primary" round block>微信授权手机号登录 + color="#09BB07" custom-style="font-size: 36rpx;" type="primary" round block>手机号快捷登录 微信授权手机号登录 + color="#09BB07" custom-style="font-size: 36rpx;" type="primary" round block>手机号快捷登录