第63讲个人中心用户信息动态显示实现

个人中心页面实现

(补充前面的取消按钮逻辑)

个人中心用户信息动态显示实现

index.wxml

<view class="user_info">
  <!-- 用户背景信息开始 -->
  <view class="user_info_bg">
    <view class="user_info_wrap">
      <image class="user_icon" src="{
   {userInfo.avatarUrl}}"></image>
      <view class="user_name">{
   {
   userInfo.nickName}}</view>
    </view>
  </view>
  <!-- 用户背景信息结束 -->

  <!-- 用户操作菜单开始 -->
  <view class="user_menu">
  </view>
  <!-- 用户操作菜单结束 -->



</view>

index.less

page{
   
  background-color: #F6F6F4;
}

.user_info{
   
  .user_info_bg{
   
    position: relative;
    height: 40vh;
    background-color: var(--themeColor);
    .user_info_wrap{
   
      position: relative;
      top: 30%;
      text-align: center;
      .user_icon{
   
        width: 150rpx;
        height: 150rpx;
        border-radius: 50%;
      }
      .user_name{
   
        color: #fff;
      }
    }
  }
}

index.js

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   
    // 判断缓存中是否有token
    const token=wx.getStorageSync('token');
    if(!token){
   
      wx.showModal({
   
        title:'友情提示',
        content:'微信授权登录后,才可进入个人中心',
        success:(res)=>{
   
          Promise.all([getWxLogin(),getUserProfile()]).then((res)=>{
   
            console.log(res[0].code)
            console.log(res[1].userInfo.nickName,res[1].userInfo.avatarUrl)
            let loginParam={
   
              code:res[0].code,
              nickName:res[1].userInfo.nickName,
              avatarUrl:res[1].userInfo.avatarUrl
            }
            console.log(loginParam)
            // 把用户信息放到缓存中
            wx.setStorageSync('userInfo', res[1].userInfo);
            this.wxlogin(loginParam);
            this.setData({
   
              userInfo:res[1].userInfo
            })
          })
        }
      })
    }else{
   
      console.log("token存在"+token);
      const userInfo=wx.getStorageSync('userInfo');
      this.setData({
   
        userInfo
      })
    }
  },

      /**
   * 请求后端获取用户token
   * @param {
   } loginParam 
   */
  async wxlogin(loginParam){
   
    // 发送请求 获取用户的token
    const result=await requestUtil({
   url:"/user/wxlogin",data:loginParam,method:"post"});
    let token=result.token;
    if(result.code==0){
   
      // 存储token到缓存
      wx.setStorageSync('token', token);
    
    }
  },

相关推荐

  1. 63个人中心用户信息动态显示实现

    2024-02-08 23:30:03       54 阅读
  2. 58 动态数据渲染订单查询实现

    2024-02-08 23:30:03       46 阅读
  3. 69后端登录逻辑实现

    2024-02-08 23:30:03       38 阅读
  4. _css元素显示模式

    2024-02-08 23:30:03       60 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-08 23:30:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-08 23:30:03       101 阅读
  3. 在Django里面运行非项目文件

    2024-02-08 23:30:03       82 阅读
  4. Python语言-面向对象

    2024-02-08 23:30:03       91 阅读

热门阅读

  1. 设计模式(行为型模式)观察者模式

    2024-02-08 23:30:03       50 阅读
  2. 打卡今天学习的命令 (linux

    2024-02-08 23:30:03       54 阅读
  3. 【运维】htop 安装及使用

    2024-02-08 23:30:03       58 阅读
  4. 深入学习Prometheus! 一款开源的监控和警报工具!

    2024-02-08 23:30:03       45 阅读
  5. Hyper-V 调整 设置 Ubuntu 虚拟机的分辨率

    2024-02-08 23:30:03       50 阅读
  6. <网络安全>《20 工业防火墙》

    2024-02-08 23:30:03       48 阅读
  7. C#的Char 结构的像IsLetterOrDigit(Char)等常见的方法

    2024-02-08 23:30:03       42 阅读
  8. 游戏如何选择服务器

    2024-02-08 23:30:03       48 阅读
  9. 《C++ Primer Plus》《2、开始学习C++》

    2024-02-08 23:30:03       59 阅读
  10. 面试复盘7——后端开发

    2024-02-08 23:30:03       51 阅读
  11. C语言数组语法解剖

    2024-02-08 23:30:03       50 阅读
  12. 2024/2/7

    2024-02-08 23:30:03       38 阅读
  13. C++生成动态库给C#使用

    2024-02-08 23:30:03       55 阅读
  14. LeetCode 491 递增序列

    2024-02-08 23:30:03       52 阅读
  15. 感觉 sheet.setDefaultColumnStyle 存在 bug

    2024-02-08 23:30:03       53 阅读