分享一個微信小程式的登入頁面
<!--miniprogram/pages/login/login.wxml-->
<button bindgetuserinfo='login_first' open-type='getUserInfo' type='primary'>一鍵登入</button>
// miniprogram/pages/login/login.js
......
login_first:function(res){
if(res.detail.errMsg == "getUserInfo:fail auth deny"){
//如果使用者點選了拒絕授權,則顯示警告模态框
wx.showModal({
title: '警告',
content: '使用者公開資訊擷取失敗,不能進入主系統',
cancelText:'拒絕授權',
confirmText:'去允許',
success(res){
if(res.confirm){
wx.showToast({
title: '謝謝合作',
})
}
else
{
//如果使用者執迷不悟,那就和他說拜拜,給他10s考慮時間,萬一迷途知返呢
wx.showLoading({
title: '拜拜',
mask: true,
})
setTimeout(function(){
wx.hideLoading()
},10000)
}
}
})
}else{
//使用者授權後,就打開首頁
wx.reLaunch({
url: '../first/first'
})
}
}
小程式碼附上,微信掃碼即可體驗:
