登录逻辑修改,扫码签到逻辑完善

This commit is contained in:
姚亚男
2021-10-14 20:04:19 +08:00
parent 2f3f9aba1d
commit 7895fc5191
26 changed files with 864 additions and 172 deletions
+76 -34
View File
@@ -6,6 +6,7 @@ Page({
data: {
phone: '',
captcha: '',
openId: '',
count: 60,
rsaPublicKey: '',
showGetCaptcha: true
@@ -21,13 +22,14 @@ Page({
countdown = 60
if (/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/.test(this.data.phone)) {
UserApi.sendCode({
phone: this.data.phone
phone: this.data.phone,
codeType: 1
}).then(res => {
// 获取成功,倒计时 start
if (res.success) {
this.countDown()
wx.showToast({
title: res.message,
title: '发送成功',
icon: 'none',
duration: 2000
})
@@ -69,6 +71,35 @@ Page({
}, 1000)
// 倒计时 end
},
// 手机号密码登录页
phonePassword(){
wx.navigateTo({
url: '../phonePassword/phonePassword',
})
},
// 微信登录
wxLogin(){
let params = {
openId: this.data.openid,
rsaPublicKey: this.data.rsaPublicKey
}
UserApi.wxLogin(params).then(res=>{
if(res.success) {// 已经用手机号登录过,此时用微信快捷登录时,把微信的个人信息存进缓存(微信信息在缓存的userInfoTemp)
wx.getStorage({
key: 'userInfoTemp',
success(result){
console.log(result)
}
})
}else{ // 首次登录不能直接用微信快捷登录
wx.showToast({
title: '暂未授权手机号',
duration: 2000,
icon: "none",
})
}
})
},
// 登录
formSubmit(e) {
if (e.detail.value.phone && e.detail.value.captcha) {
@@ -80,16 +111,16 @@ Page({
// 请求短信登录start
UserApi.codeLogin(params).then(res => {
if (res.success) {
// 存临时token和userInfo
wx.setStorage({
key: 'token-temp',
data: res.result.token
})
wx.setStorage({
key: 'userInfo',
data: res.result.userInfo
})
if(res.message === "updatePassword") {
// 存临时token
wx.setStorage({
key: 'token-temp',
data: res.result.token
})
// 跳转设置密码页
wx.navigateTo({
url: '../setPassword/setPassword',
@@ -100,6 +131,8 @@ Page({
key: 'X-Access-Token',
data: res.result.token
})
// 绑定微信
this.wxBind()
// 跳转首页
wx.switchTab({
url: '../home/home',
@@ -122,21 +155,44 @@ Page({
})
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
// 忘记密码
updateInfo(){
wx.navigateTo({
url: '../forgetPassword/forgetPassword',
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
// 绑定微信
wxBind(){
const that = this
// 获取openid进行手机号和微信的绑定
wx.login({
success (res) {
if (res.code) {
//发起网络请求
wx.request({
url: 'https://api.weixin.qq.com/sns/jscode2session',
data: {
appid: 'wx24914e866df035fb',
secret: '0d2830f26f57722716249f2b2236f409',
js_code: res.code,
grant_type: 'authorization_code'
},
success (res) { // 成功拿到openId
// 微信和该账号绑定
let params = {
openId: res.openId,
rsaPublicKey: that.data.rsaPublicKey
}
UserApi.wxBind(params).then(res=>{})
}
})
} else {
console.log('授权失败!' + res.errMsg)
}
}
})
},
/**
* 生命周期函数--监听页面显示
*/
@@ -152,19 +208,5 @@ Page({
})
}
})
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
}
})