怎么解决 bindGetUserInfo 重复执行问题
发布于 5 年前 作者 xiuyingfang 8881 次浏览 来自 问答

网络不好的时候,多次点击open-type getUserInfo 按钮,会导致该按钮事件执行多次。怎么解决呢

2 回复

bindGetUserInfo: function (e) {

console.log(e)

wx.showToast({

title: ‘点击了button’,

icon: ‘success’,

duration: 2000

})

console.log(“isclick=====bindGetUserInfo=======11111”, isclick)

var that = this

console.log(“userInfo===========”)

console.log(that.data.userInfo)

// var token = userInfo.token

// var unionid = userInfo.user.unionid

var encryptedData = e.detail.encryptedData;

var iv = e.detail.iv;

var laravelsession = publicUrl.globalData.laravelsession;

var xsrftoken = publicUrl.globalData.xsrftoken;

var sys_token = publicUrl.globalData.sys_token;

if (e.detail.userInfo != undefined) {

console.log(“isclick=======2222=”, isclick)

if (!that.data.userInfo.user.nickname) {

if(isclick==true){

wx.request({

url: url + ‘/miniprogram/registeruser’,

method: ‘POST’,

data: {

// unionid: unionid,

// token: token,

encryptedData: encryptedData,

iv: iv,

rawData: e.detail.rawData,

signature: e.detail.signature

//_token: sys_token

},

header: publicUrl.globalData.header,

success: function (res) {

console.log(“注册用户成功==============”)

console.log(res)

if (res.data.code == 0) {

isclick = false

console.log(“code================0”)

var laravelsession = res.header[“Set-Cookie”].match(/laravel_session=(.*?);/)[1]

var xsrftoken = res.header[“Set-Cookie”].match(/XSRF-TOKEN=(.*?);/)[1]

var sys_token = res.header[“xxvv”]

publicUrl.globalData.laravelsession = laravelsession

publicUrl.globalData.xsrftoken = xsrftoken

publicUrl.globalData.sys_token = sys_token

var header = {

‘Content-type’: ‘application/x-www-form-urlencoded’,

‘Cookie’: ‘XSRF-TOKEN=’ + xsrftoken + '; ’ + ‘laravel_session=’ + laravelsession,

‘X-CSRF-TOKEN’: sys_token,

‘X-Requested-With’: ‘XMLHttpRequest’,

‘uf’: ‘1’

}

publicUrl.globalData.header = header

that.setData({

userInfo: res.data.result

})

// userInfo = res.data.result

wx.setStorage({

key: “myuser”,

data: res.data.result

})

publicUrl.globalData.userInfo = res.data.result

wx.setStorage({

key: “userInfo”,

data: res.data.result

})

if (that.data.sid) {

if (that.data.share == 1) {

wx.reLaunch({

url: ‘/pages/ranking/ranking?storeid=’ + that.data.sid + ‘&share=1’

})

} else {

wx.reLaunch({

url: ‘/pages/ranking/ranking?storeid=’ + that.data.sid

})

}

} else if (that.data.uunionid) {

if (that.data.share == 1) {

wx.reLaunch({

url: ‘/pages/personal/personal?uunionid=’ + that.data.uunionid + ‘&share=1’

})

} else {

wx.reLaunch({

url: ‘/pages/personal/personal?uunionid=’ + that.data.uunionid

})

}

} else {

wx.reLaunch({

url: ‘/pages/city/city?source=login’,

})

}

} else if (res.data.code == 5588) {

login(that)

} else {

console.log(“code==============else=========”, res.data.code)

}

},

fail: function (res) {

console.log(“注册用户失败===============”)

}

})

}

} else {

var userInfo = publicUrl.globalData.userInfo

var myuser = wx.getStorageSync(‘myuser’);

if (that.data.sid) {

if (that.data.share == 1) {

wx.reLaunch({

url: ‘/pages/ranking/ranking?storeid=’ + that.data.sid + ‘&share=1’

})

} else {

wx.reLaunch({

url: ‘/pages/ranking/ranking?storeid=’ + that.data.sid

})

}

} else if (that.data.uunionid) {

if (that.data.share == 1) {

wx.reLaunch({

url: ‘/pages/personal/personal?uunionid=’ + that.data.uunionid + ‘&share=1’

})

} else {

wx.reLaunch({

url: ‘/pages/personal/personal?uunionid=’ + that.data.uunionid

})

}

} else {

wx.reLaunch({

url: ‘/pages/city/city?source=login’,

})

}

}

} else {

console.log(“您没有授权哦”)

wx.showToast({

title: ‘您没有授权哦~’,

icon: ‘none’,

duration: 2000

})

}

},

你自己写个事件节流。在getUserInfo绑定的事件里面。

根据取出的东西。如果取出来一遍之后。即使在点也不走接口

回到顶部