在线直播系统源码,用户登录时获取到用户已有的账号信息

在线直播系统源码,用户登录时获取到用户已有的账号信息
1、用户未授权(首次登录)

button open-type=‘getUserInfo’

2、用户已经授权(再次登录)

wx.getUserInfo

html文件:

<view class="indexContainer">
    <image wx:if='{
    
    {
    
    userInfo.avatarUrl}}' class="avatarUrl"  src="{
    
    {userInfo.avatarUrl}}"></image>
    <button wx:else bindgetuserinfo='handleGetUserInfo' open-type="getUserInfo">获取用户信息</button>
    <text class="userName">{
    
    {
    
    userInfo.nickName}}</text>
    <!-- 测试事件绑定 -->
  <!-- <view class="goStudy" catchtap="handleParent">
    <text catchtap="handleChild">Hello World</text>
  </view> -->
 
  <view class="goStudy" catchtap="toLogs">
    <text >Hello World</text>
  </view>
</view>

css文件:

.indexContainer{
    
    
  display: flex;
  flex-direction:column;
  align-items: center;
  justify-content: center;
}
 
.avatarUrl{
    
    
  width: 200rpx;
  height: 200rpx;
  border-radius: 50%;
  margin:100rpx 0;
}
 
button{
    
    
  width: 200rpx;
  height: 200rpx;
  border-radius: 50%;
  margin: 100px 0;
  font-size: 24rpx;
  line-height: 200rpx;
  text-align: center;
  background-color: skyblue;
}
.userName{
    
    
  font-size: 32rpx;
  margin: 100rpx 0;
}
.goStudy{
    
    
  width: 300rpx;
  height: 80rpx;
  line-height: 80rpx;
  text-align: center;
  font-size: 28rpx;
  border: 1rpx solid #333;
  border-radius: 10rpx;
}
 

js文件:

Page({
    
    
 
  /**
   * 页面的初始数据
   */
  data: {
    
    
     msg:'初始化数据',
     userInfo:{
    
    }   //存放用户的基本信息
  },
 
},
 
 
  /**
   * 生命周期函数--监听页面加载  页面加载就会执行
   */
  onLoad: function (options) {
    
    
     //修改msg数据  语法  this.setData()  this代表当前页面的实例对象
    // console.log(this.data.msg)
    //  this.setData({
    
    
    //    msg:'修改之后的数据'
    //  })
     //console.log(this.data.msg)
     //授权以后获取用户的信息
     wx.getUserInfo({
    
    
       success:(res)=>{
    
    
         console.log(res);
         this.setData({
    
    
           userInfo:res.userInfo
         })
 
       },
       fail:(err)=>{
    
    
          console.log(err)
       }
     })
  },
  //获取用户信息的回调
  handleGetUserInfo(res){
    
    
    console.log(res)
    if(res.detail.userInfo){
    
      //允许修改userinfo的数据
      this.setData({
    
    
        userInfo:res.detail.userInfo
      })
    }
  },

以上就是 在线直播系统源码,用户登录时获取到用户已有的账号信息,更多内容欢迎关注之后的文章

猜你喜欢

转载自blog.csdn.net/yb1314111/article/details/125145929