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