const windowInfo = wx.getWindowInfo();
let button = wx.createUserInfoButton({
type: 'text',
text: '',
style: {
left: 0,
top: 0,
width: windowInfo.windowWidth,
height: windowInfo.windowHeight,
lineHeight: 0,
backgroundColor: 'transparent',
color: 'transparent',
textAlign: 'center',
fontSize: 0,
borderRadius: 0,
borderWidth: 0,
borderColor: 'transparent'
}
})
button.onTap(() => {
wx.getUserInfo({
success: (res) => {
console.log('授权成功,用户信息:', res.userInfo);
GlobalData.userInfo = res.userInfo;
button.destroy();
},
fail: (err) => {
console.log('用户拒绝授权或获取失败:', err);
wx.showToast({title: '请授权才能继续', icon: 'none'});
}
});
});
