【bug】- 解决线上版本首次不能授权登录的bug
This commit is contained in:
+62
-36
@@ -97,6 +97,7 @@ Page({
|
|||||||
wx.getStorage({
|
wx.getStorage({
|
||||||
key: 'authorize',
|
key: 'authorize',
|
||||||
success(result){
|
success(result){
|
||||||
|
console.log('result=======', result)
|
||||||
// 做过查看微信用户信息
|
// 做过查看微信用户信息
|
||||||
if(result.data){ // 做过用户信息获取
|
if(result.data){ // 做过用户信息获取
|
||||||
wx.showToast({
|
wx.showToast({
|
||||||
@@ -137,6 +138,7 @@ Page({
|
|||||||
},
|
},
|
||||||
fail(err){
|
fail(err){
|
||||||
// 没有做过查看微信用户信息
|
// 没有做过查看微信用户信息
|
||||||
|
console.log('err========', err)
|
||||||
that.getUserInfo()
|
that.getUserInfo()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -144,51 +146,75 @@ Page({
|
|||||||
// 获取用户信息,微信登录
|
// 获取用户信息,微信登录
|
||||||
getUserInfo(){
|
getUserInfo(){
|
||||||
const that = this
|
const that = this
|
||||||
wx.getUserProfile({
|
wx.showModal({
|
||||||
desc: '用于完善用户信息',
|
title: '温馨提示',
|
||||||
success(result){
|
content: `亲,授权微信登录后才能正常使用小程序功能`,
|
||||||
let userInfoTemp = JSON.parse(result.rawData)
|
cancelColor: 'cancelColor',
|
||||||
wx.setStorage({
|
success(res) {
|
||||||
key: 'userInfoTemp',
|
if (res.confirm) {
|
||||||
data: userInfoTemp
|
wx.getUserProfile({
|
||||||
})
|
desc: '获取你的昵称、头像、地区及性别',
|
||||||
that.setData({
|
success(result){
|
||||||
userInfoTemp
|
console.log('result用于完善用户信息', result)
|
||||||
})
|
let userInfoTemp = JSON.parse(result.rawData)
|
||||||
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({
|
wx.setStorage({
|
||||||
key: 'X-Access-Token',
|
key: 'userInfoTemp',
|
||||||
data: res.result.token
|
data: userInfoTemp
|
||||||
})
|
})
|
||||||
wx.switchTab({
|
that.setData({
|
||||||
url: '../home/home',
|
userInfoTemp
|
||||||
})
|
})
|
||||||
wx.setStorageSync('authorize', true) // 设置有过微信授权
|
|
||||||
wx.setStorageSync('avatarUrl', that.data.userInfoTemp.avatarUrl)
|
|
||||||
}else{ // 首次登录不能直接用微信快捷登录
|
|
||||||
wx.showToast({
|
wx.showToast({
|
||||||
title: '暂无授权手机号',
|
title: '登录中...',
|
||||||
icon: 'none'
|
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){
|
||||||
|
console.log('err===========', err)
|
||||||
|
wx.setStorageSync('authorize', false)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
} else {
|
||||||
},
|
|
||||||
fail(err){
|
}
|
||||||
wx.setStorageSync('authorize', false)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
// wx.showModal({
|
||||||
|
// title: '错误提示',
|
||||||
|
// content: `图片大于${that.data.maxSize}MB`,
|
||||||
|
// showCancel: false,
|
||||||
|
// success(res) {
|
||||||
|
// if (res.confirm) {
|
||||||
|
// console.log('用户点击确定')
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
|
||||||
},
|
},
|
||||||
// 登录
|
// 登录
|
||||||
formSubmit(e) {
|
formSubmit(e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user