import _ from '../../commons/js/commons' const app = getApp() Component({ /** * 组件的属性列表 */ properties: { isShow: { type: Boolean, value: false }, }, /** * 组件的初始数据 */ data: { code:'', isRunning:false, }, lifetimes: { attached: function () { wx.login({ success: res => { this.setData({ code: res.code, }) } }) }, }, /** * 组件的方法列表 */ methods: { //授权用户信息 getUserProfile(){ let that = this if(!!that.data.isRunning) return; that.setData({ isRunning:true }); wx.getUserProfile({ desc:'获取你的昵称、头像、地区及性别',//不写不弹提示框 success:function(res){ let params = {}; params['code'] = that.data.code; params['userInfo'] = res.userInfo; that.setData({ isShow: false, }) _.apiQuery.putAppUser(params).then(res => { that.setData({ isRunning:false }); wx.showToast({ title: '授权成功', icon: 'success', duration: 2000 }) }); }, fail:function(err){ that.setData({ isRunning:false }); console.log('拒绝授权') } }) }, } })