Commit 77a29f17 authored by Aivs's avatar Aivs

登陆要求必须绑定手机号

parent c7d8800f
......@@ -4,6 +4,10 @@ var user = require('../../../utils/user.js');
var app = getApp();
Page({
data:{
hasLogin: false,
phoneshow:false
},
onLoad: function(options) {
// 页面初始化 options为页面跳转所带来的参数
// 页面渲染完成
......@@ -20,6 +24,9 @@ Page({
},
onUnload: function() {
// 页面关闭
if(!this.data.phoneshow){
wx.clearStorageSync('token')
}
},
wxLogin: function(e) {
......@@ -36,7 +43,58 @@ Page({
})
user.loginByWeixin(e.detail.userInfo).then(res => {
app.globalData.hasLogin = true;
if (getCurrentPages().length>1) {
this.setData({
hasLogin:true
})
// if (getCurrentPages().length>1) {
// wx.navigateBack({
// delta: 1
// })
// } else {
// wx.reLaunch({
// url: '/pages/ucenter/index/index',
// })
// }
wx.hideLoading();
}).catch((err) => {
console.log(err)
app.globalData.hasLogin = false;
util.showErrorToast('微信登录失败');
});
});
},
bindPhoneNumber: function(e) {
let that = this;
if (e.detail.errMsg !== "getPhoneNumber:ok") {
// 拒绝授权
wx.clearStorageSync('token')
return;
}
if (!this.data.hasLogin) {
wx.showToast({
title: '绑定失败:请先登录',
icon: 'none',
duration: 2000
});
return;
}
util.request(api.AuthBindPhone, {
iv: e.detail.iv,
encryptedData: e.detail.encryptedData
}, 'POST').then(function(res) {
if (res.errno === 0) {
that.setData({
phoneshow: true
})
wx.showToast({
title: '绑定手机号成功',
icon: 'success',
duration: 2000
});
if (getCurrentPages().length>1) {
wx.navigateBack({
delta: 1
})
......@@ -45,13 +103,7 @@ Page({
url: '/pages/ucenter/index/index',
})
}
wx.hideLoading();
}).catch((err) => {
console.log(err)
app.globalData.hasLogin = false;
util.showErrorToast('微信登录失败');
});
}
});
},
accountLogin: function() {
......
<view class="container">
<view class="login-box">
<view wx:if='{{hasLogin}}' class="login-box">
<button class="wx-login-btn" open-type="getPhoneNumber" bindgetphonenumber="bindPhoneNumber">绑定手机号</button>
</view>
<view wx:else class="login-box">
<button open-type="getUserInfo" class="wx-login-btn" bindgetuserinfo="wxLogin">微信直接登录</button>
<button class="account-login-btn" bindtap="accountLogin">账号登录</button>
</view>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment