bug修改

This commit is contained in:
姚亚男
2021-10-26 14:04:29 +08:00
parent 15f270faf2
commit ad6c0afd9e
36 changed files with 294 additions and 122 deletions
+100 -25
View File
@@ -9,8 +9,10 @@ Page({
captcha: '',
openId: '',
count: 60,
userInfoTemp: '',
rsaPublicKey: '',
showGetCaptcha: true
showGetCaptcha: true,
authorize: false // 默认没有微信授权
},
bindInputPhone(e) {
@@ -87,33 +89,98 @@ Page({
},
// 微信登录
wxLogin(){
wx.showToast({
title: '登录中...',
icon: 'loading'
})
const that = this
wxBind((res)=>{
let params = {
openId: res.data.openid,
rsaPublicKey: that.data.rsaPublicKey
}
UserApi.wxLogin(params).then(res=>{
if(res.success) {// 已经用手机号登录过,此时用微信快捷登录时,把微信的个人信息存进缓存(微信信息在缓存的userInfoTemp)
wx.setStorageSync('userInfo', res.result.userInfo)
wx.setStorage({
key: 'X-Access-Token',
data: res.result.token
})
wx.switchTab({
url: '../home/home',
})
}else{ // 首次登录不能直接用微信快捷登录
wx.getStorage({
key: 'authorize',
success(result){
// 做过查看微信用户信息
if(result.data){ // 做过用户信息获取
wx.showToast({
title: '暂无授权手机号',
icon: 'none'
title: '登录中...',
icon: 'loading'
})
wxBind((res)=>{
let params = {
openId: res.data.openid,
rsaPublicKey: that.data.rsaPublicKey
}
UserApi.wxLogin(params).then(res=>{
if(res.success) {// 已经用手机号登录过,此时用微信快捷登录时,把微信的个人信息存进缓存(微信信息在缓存的userInfoTemp)
wx.setStorageSync('userInfo', res.result.userInfo)
wx.setStorage({
key: 'X-Access-Token',
data: res.result.token
})
wx.switchTab({
url: '../home/home',
})
wx.setStorageSync('authorize', true) // 设置有过微信授权
wx.setStorageSync('avatarUrl', that.data.userInfoTemp.avatarUrl)
}else{ // 首次登录不能直接用微信快捷登录
wx.showToast({
title: '暂无授权手机号',
icon: 'none'
})
}
})
})
}else{
that.getUserInfo()
}
})
},
fail(err){
// 没有做过查看微信用户信息
that.getUserInfo()
}
})
},
// 获取用户信息,微信登录
getUserInfo(){
const that = this
wx.getUserProfile({
desc: '用于完善用户信息',
success(result){
let userInfoTemp = JSON.parse(result.rawData)
wx.setStorage({
key: 'userInfoTemp',
data: userInfoTemp
})
that.setData({
userInfoTemp
})
wx.showToast({
title: '登录中...',
icon: 'loading'
})
wxBind((res)=>{
let params = {
openId: res.data.openid,
rsaPublicKey: that.data.rsaPublicKey
}
UserApi.wxLogin(params).then(res=>{
if(res.success) {// 已经用手机号登录过,此时用微信快捷登录时,把微信的个人信息存进缓存(微信信息在缓存的userInfoTemp)
wx.setStorageSync('userInfo', res.result.userInfo)
wx.setStorage({
key: 'X-Access-Token',
data: res.result.token
})
wx.switchTab({
url: '../home/home',
})
wx.setStorageSync('authorize', true) // 设置有过微信授权
wx.setStorageSync('avatarUrl', that.data.userInfoTemp.avatarUrl)
}else{ // 首次登录不能直接用微信快捷登录
wx.showToast({
title: '暂无授权手机号',
icon: 'none'
})
}
})
})
},
fail(err){
wx.setStorageSync('authorize', false)
}
})
},
// 登录
@@ -201,7 +268,15 @@ Page({
})
},
onLoad(){
const that = this
wx.getStorage({
key: 'userInfoTemp',
success(res){
that.setData({
userInfoTemp: res.data
})
}
})
},
/**
* 生命周期函数--监听页面显示