const btnNodeUiTransform = btnNode.getComponent(UITransform);
const btnSize = btnNodeUiTransform;
const winSize = screen.windowSize;
// 适配不同机型来创建微信授权按钮
const ratio = screen.devicePixelRatio
const scale = view.getScaleX()
const factor = scale / ratio
const width = btnSize.width * factor;
const height = btnSize.height * factor;
const top = winSize.height / ratio - height - (80 * factor)
const left = winSize.width / ratio - width - (33 * factor)
this.userInfoButton = wx.createUserInfoButton({
type: 'text',
text: '',
// @ts-ignore
style: {
left: left,
top: top,
width: width,
height: height,
backgroundColor: 'rgba(255, 255, 255, 0)',
}
})
this.userInfoButton.onTap((res) => {
if (res.userInfo) {
console.log(res.userInfo)
this.userInfoButton.hide();
} else {
Toast.toast('用户信息授权失败')
}
});