getUser(e) {
let that = this
let flag = 0
// 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
wx.getUserProfile({
desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
this.getOpenid()
console.log(res)
this.setData({
userInfo: res.userInfo,
tempName: res.userInfo.nickName,
avatarU: res.userInfo.avatarUrl,
gender: res.userInfo.gender,
})
// console.log(this.data.openidh)
},
})
//**重点问题代码段**
if(this.data.hasOpi ==true){
that.hasReg(flag)
if(flag == 0){
that.Reg()
}else{
wx.showToast({
title: '欢迎回来',
})
}
this.setData({
hasUserInfo:true
})
}
//**重点问题代码段**
return e
}
怎么能让重点问题代码段,在获取用户openid后再执行hasReg()方法,判断这个用户是否曾经注册。(猜是代码执行顺序理解错)
这种写法,在用hasOpi判断的时候hasOpi肯定一直是初始值
let result = await this.getUserProfile()
console.log(result)
console.log(this.data.openidh)
let that = this
let flag = 0
//**重点问题代码段**
if (this.data.hasOpi == true) {
that.hasReg(flag)
if (flag == 0) {
that.Reg()
} else {
wx.showToast({
title: '欢迎回来',
})
}
this.setData({
hasUserInfo: true
})
}
//**重点问题代码段**
return e
},
getUserProfile() {
let that = this;
let resu = new Promise((resolve, reject) => {
wx.getUserProfile({
desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
that.getOpenid()
console.log(res)
that.setData({
userInfo: res.userInfo,
tempName: res.userInfo.nickName,
avatarU: res.userInfo.avatarUrl,
gender: res.userInfo.gender,
})
// console.log(that.data.openidh)
resolve(res)
},
fail(res) {
resolve(res)
}
})
})
return resu
},