108 lines
2.0 KiB
JavaScript
108 lines
2.0 KiB
JavaScript
|
// pages/get-user-info/get-user-info.js
|
||
|
|
||
|
const app = getApp()
|
||
|
|
||
|
Page({
|
||
|
|
||
|
/**
|
||
|
* 页面的初始数据
|
||
|
*/
|
||
|
data: {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面加载
|
||
|
*/
|
||
|
onLoad: function (options) {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面初次渲染完成
|
||
|
*/
|
||
|
onReady: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面显示
|
||
|
*/
|
||
|
onShow: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面隐藏
|
||
|
*/
|
||
|
onHide: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面卸载
|
||
|
*/
|
||
|
onUnload: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 页面相关事件处理函数--监听用户下拉动作
|
||
|
*/
|
||
|
onPullDownRefresh: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 页面上拉触底事件的处理函数
|
||
|
*/
|
||
|
onReachBottom: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 用户点击右上角分享
|
||
|
*/
|
||
|
onShareAppMessage: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
bindGetUserInfo: function (e) {
|
||
|
|
||
|
if (e.detail.userInfo) {
|
||
|
// 用户按了允许授权按钮
|
||
|
var that = this;
|
||
|
// 插入登录的用户的相关信息到数据库
|
||
|
|
||
|
new Promise((resolve, reject) => {
|
||
|
const eventChannel = this.getOpenerEventChannel()
|
||
|
eventChannel.emit('acceptDataFromOpenedPage', {data: 'refresh'})
|
||
|
resolve(e.detail.userInfo)
|
||
|
}).then((userInfo)=> {
|
||
|
// 设置账户基本信息
|
||
|
app.globalData.userInfo = userInfo
|
||
|
}).then(() => {
|
||
|
// 授权成功后,跳转进入小程序首页
|
||
|
wx.navigateTo({
|
||
|
url: '/pages/index/index'
|
||
|
})
|
||
|
})
|
||
|
|
||
|
|
||
|
|
||
|
} else {
|
||
|
//用户按了拒绝按钮
|
||
|
wx.showModal({
|
||
|
title:'警告',
|
||
|
content:'您点击了拒绝授权,将无法进入小程序,请授权之后再进入!!!',
|
||
|
showCancel:false,
|
||
|
confirmText:'返回授权',
|
||
|
success:function(res){
|
||
|
if (res.confirm) {
|
||
|
console.log('用户点击了“返回授权”')
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
},
|
||
|
})
|