1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
getUserInfo(btnNode, cb) { if (cc.sys.platform != cc.sys.WECHAT_GAME) { return } wx.getSetting({ success(res) { if(!res.authSetting['scope.userInfo']) {
let btnSize = cc.size(btnNode.width+10,btnNode.height+10); let frameSize = cc.view.getFrameSize(); let winSize = cc.director.getWinSize(); let left = (winSize.width*0.5+btnNode.x-btnSize.width*0.5)/winSize.width*frameSize.width; let top = (winSize.height*0.5-btnNode.y-btnSize.height*0.5)/winSize.height*frameSize.height; let width = btnSize.width/winSize.width*frameSize.width; let height = btnSize.height/winSize.height*frameSize.height;
const button = wx.createUserInfoButton({ type: 'text', text: '', style: { left: left, top: top, width: width, height: height, lineHeight: 0, backgroundColor: '', color: '#ffffff', textAlign: 'center', fontSize: 16, borderRadius: 4 } }) button.onTap((res) => { if (cb) { if(res.userInfo) { cb(null, res) button.hide() } else { cb('没有允许获取用户权限') } } }) } else { wx.getUserInfo({ success(res) { if (cb) { cb(null, res) } } }) } } }) }
|