refactor: remove registration page and update login UI with agreement checkbox
This commit is contained in:
@@ -8,20 +8,20 @@ Page({
|
||||
data: {
|
||||
showUnclickMask: false,
|
||||
isGoHome: false,
|
||||
isLogin: false,
|
||||
isAgree: false
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad: function(options) {
|
||||
onLoad: function (options) {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady: function() {
|
||||
onReady: function () {
|
||||
let pages = getCurrentPages();
|
||||
this.setData({
|
||||
isGoHome: pages.length == 1
|
||||
@@ -31,7 +31,7 @@ Page({
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow: function() {
|
||||
onShow: function () {
|
||||
if (this.data.isLogin) {
|
||||
this.pushRoute()
|
||||
return;
|
||||
@@ -64,109 +64,106 @@ Page({
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide: function() {
|
||||
onHide: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload: function() {
|
||||
onUnload: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh: function() {
|
||||
onPullDownRefresh: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom: function() {
|
||||
onReachBottom: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage: function() {
|
||||
onShareAppMessage: function () {
|
||||
return {
|
||||
title: '智慧云馆'
|
||||
}
|
||||
},
|
||||
|
||||
// 登录
|
||||
loginClick() {
|
||||
// 跳转到协议
|
||||
pushAgreement() {
|
||||
wx.navigateTo({
|
||||
url: '/pages/loginIndex/index',
|
||||
url: '/pages/agreement/index',
|
||||
})
|
||||
},
|
||||
|
||||
// 注册
|
||||
registerClick(e) {
|
||||
wx.redirectTo({
|
||||
url: '/pages/register/index?codeType=' + 2,
|
||||
checkboxChange(e) {
|
||||
this.setData({
|
||||
isAgree: e.detail.value.length > 0
|
||||
})
|
||||
},
|
||||
|
||||
// 微信登录
|
||||
wxLogin(e) {
|
||||
if (e.detail.errMsg == 'getUserInfo:fail auth deny') {
|
||||
|
||||
|
||||
// 手机号一键登录/注册
|
||||
onGetPhoneNumber(e) {
|
||||
if (!this.data.isAgree) {
|
||||
wx.showToast({
|
||||
title: '请阅读并同意服务条款及隐私政策',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
return;
|
||||
}
|
||||
this.setData({
|
||||
showUnclickMask: true
|
||||
})
|
||||
|
||||
if (e.detail.errMsg === 'getPhoneNumber:fail user deny') {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setData({ showUnclickMask: true });
|
||||
let that = this;
|
||||
wx.getUserProfile({
|
||||
desc: '用于完善会员资料',
|
||||
success: (res) => {
|
||||
wx.login({
|
||||
success: function(r){
|
||||
app.$api.memberLoginWX({
|
||||
avatar: res.userInfo.avatarUrl,
|
||||
code: r.code,
|
||||
nickname: res.userInfo.nickName
|
||||
}).then(res => {
|
||||
wx.setStorageSync('information', res.information);
|
||||
if (!res.authorization) {
|
||||
wx.redirectTo({
|
||||
url: '/pages/register/index?codeType=' + 1,
|
||||
})
|
||||
return;
|
||||
}
|
||||
wx.setStorageSync('accessToken', res.authorization.accessToken);
|
||||
let route = wx.getStorageSync('history');
|
||||
wx.removeStorageSync('history');
|
||||
if (!route || route == '/pages/login/index') {
|
||||
return wx.redirectTo({
|
||||
url: '/pages/mine/index',
|
||||
})
|
||||
}
|
||||
wx.redirectTo({
|
||||
url: route,
|
||||
})
|
||||
}, err => {
|
||||
that.setData({
|
||||
showUnclickMask: false
|
||||
})
|
||||
});
|
||||
},
|
||||
fail: function(res) {
|
||||
that.setData({
|
||||
showUnclickMask: false
|
||||
})
|
||||
},
|
||||
})
|
||||
},
|
||||
fail: (res) => {
|
||||
that.setData({
|
||||
showUnclickMask: false
|
||||
})
|
||||
|
||||
// 前端获取到手机号授权 code 后,再去获取 wx.login 的 code
|
||||
wx.login({
|
||||
success: function (r) {
|
||||
// 调用后端接口。
|
||||
// 注意:这里复用了 memberLoginWXPhone。请让后端把接收参数改为 phoneCode 和 loginCode,
|
||||
// 或者您自己在 api.js 里新建一个专属的一键登录接口。后端收到 phoneCode 后去微信服换取真实手机号并完成注册登录。
|
||||
app.$api.memberLoginWXPhone({
|
||||
loginCode: r.code,
|
||||
phoneCode: e.detail.code
|
||||
}).then(res => {
|
||||
if (!res.authorization) {
|
||||
that.setData({ showUnclickMask: false });
|
||||
wx.showToast({ title: '登录失败,未返回Token', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
wx.setStorageSync('information', res.information);
|
||||
wx.setStorageSync('accessToken', res.authorization.accessToken);
|
||||
|
||||
|
||||
that.setData({ showUnclickMask: false });
|
||||
let route = wx.getStorageSync('history');
|
||||
wx.removeStorageSync('history');
|
||||
if (!route || route == '/pages/login/index') {
|
||||
return wx.redirectTo({ url: '/pages/mine/index' })
|
||||
}
|
||||
wx.redirectTo({ url: route })
|
||||
}).catch(err => {
|
||||
that.setData({ showUnclickMask: false });
|
||||
});
|
||||
},
|
||||
fail: function (res) {
|
||||
that.setData({ showUnclickMask: false });
|
||||
}
|
||||
})
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user