小程序基礎庫2.0.7更新小程序組件 <button>
新增 open-type
屬性有效值 openSetting
,所以說,再也不能愉快的直接調用getUserInfo了。但是不想用官方的按鈕直接點擊授權,依舊想使用之前的點擊允許授權彈框怎么使用?
大概可以有以下思路:
我的自定義組件
<base-modal id="baseModal" modalSize="{{modalSize}}" animated="{{animated}}" backdrop="{{backdrop}}"> <view slot="header" class='modal-header'> <text>授權登錄</text> </view> <view slot="body" class='modal-body'> 小程序請求獲取你的公開信息(頭像,昵稱等) </view> <view slot="footer" class='modal-footer'> <view class="bod-right"> <button plain bindtap="_cancelModal">拒絕</button> </view> <view> <button plain open-type="getUserInfo" bindgetuserinfo="_confirmModal">同意</button>
//bindgetuserinfo在打開授權設置頁后的回調 </view> </view> </base-modal>
首先使用自定義彈框組件,在彈框按鈕處,【取消】:提示
wx.showModal({ title: '提示', content: '您點擊了拒絕授權,將無法使用該功能。請點擊【確定】設置授權,或者等10分鍾之后再次獲取授權。', success: (resp) => { if (resp.confirm) { console.log('用戶點擊確定') //打開設置頁面授權 wx.openSetting({ success: (succ) => {} }) } else if (resp.cancel) { console.log('用戶點擊取消')
//跳轉到選項卡指定頁面,關閉其他頁面 wx.switchTab({ url: "/pages/index/index" }) } }, fail: () => { console.log('fail') wx.switchTab({ url: "/pages/index/index" }) } })
點擊【確定】按鈕:
這回可以引用新的方法了,
跳轉設置頁面授權
wx.openSetting({ success: (succ) => {} })
emm……拖了好久才出來的文章,在剛發布時就已經寫得一半一半但是覺得不夠完善,一直待在草稿箱里
還有一種方法是,靜默登錄,晚些時候再來更新完善一下
可參考這個博客的自定義組件方法內的【增強模態窗】,使用(可點擊):微信小程序組件化 快速實現可用模態窗