// Componet/Componet.js let app = getApp(); Component({ /** * 组件的属性列表 */ properties: { // 是否显示用户授权 showTele: { type: Boolean } }, /** * 组件的初始数据 */ data: { canIUse: wx.canIUse('button.open-type.getUserInfo'), isShow: true, wxIcon: app.globalData.imgUrl + '/images/wx_login.png' }, ready: function() { console.log('this.properties', this.properties); this.setData({ isShow: this.properties.showTele || true }) }, /** * 组件的方法列表 */ methods: { bindGetPhoneNumber: function(e) { let that = this; console.log('手机相关信息', e); if (e.detail.errMsg == 'getPhoneNumber:ok') { that.triggerEvent('onSetData', { showTele: false }); wx.setStorageSync('#phoneAuthorization#', 'phone' + Date.now()); }else { //用户按了拒绝按钮 wx.showModal({ title: '警告', content: '您点击了拒绝授权,将无法进入小程序,请授权之后再进入!', showCancel: false, confirmText: '返回授权', success: function (res) { // 用户没有授权成功,不需要改变 isHide 的值 if (res.confirm) { console.log('用户点击了“返回授权”'); } } }); } } } })