微信小程序微商城(九):微信授权并实现个人中心页面页面

IT实战联盟博客:http://blog.100boot.cn

上一篇:微信小程序微商城(八):缓存实现商品购物车功能

看效果

 

 

开发计划

1、实现微信授权并获取用户信息
2、个人中心页面布局

一、实现微信授权并获取用户信息

mine.js

onLoad: function () {    
    if (app.globalData.userInfo) {      
        this.setData({        
        userInfo: app.globalData.userInfo,        
        hasUserInfo: true
      })
    } else if (this.data.canIUse) {      // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {        this.setData({          userInfo: res.userInfo,          hasUserInfo: true
        })
      }
    } else {      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({        success: res => {
          app.globalData.userInfo = res.userInfo          this.setData({            userInfo: res.userInfo,            hasUserInfo: true
          })
        }
      })
    }
  },  
getUserInfo: function (e) {    
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo    
    this.setData({      
        userInfo: e.detail.userInfo,      
        hasUserInfo: true
    })
  }

二、实现微信授权并获取用户信息

mine.wxml

<view class="userinfo">
  <button wx:if="{{!hasUserInfo && canIUse}}" open-type="getUserInfo" bindgetuserinfo="getUserInfo" class="userinfo-btn"> 点击微信授权 </button>
  <block wx:else>
    <image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" background-size="cover"></image>
    <text class="userinfo-nickname">{{userInfo.nickName}}</text>
  </block></view><view class="separate"></view><view class="order" catchtap="toOrder">
  <text class="myorder-text">我的订单</text>
  <text class="myorderlook-text">查看全部订单</text></view><view class="line"></view><view class="navs">
  <block wx:for-items="{{orderItems}}" wx:key="name">
    <view class="nav-item" catchtap="toOrder" data-type="{{item.name}}" data-typeid="{{item.typeId}}">
      <image src="{{item.imageurl}}" class="nav-image" />
      <text>{{item.name}}</text>
    </view>
  </block></view><view class="separate"></view><view class="person-list">

  <view class="list-item">
    <image class="item-image" src="../../images/person/personal_card.png"></image>
    <text class="item-text">优惠券</text>
  </view>
  <view class="person-line"></view>
  <view class="list-item">
    <image class="item-image" src="../../images/person/personal_favorite.png"></image>
    <text class="item-text">我的收藏</text>
  </view>
  <view class="person-line"></view>
  <view class="list-item">
    <image class="item-image" src="../../images/person/personal_site.png"></image>
    <text class="item-text">收货地址</text>
  </view>
  <view class="person-line"></view>
  <view class="list-item">
    <image class="item-image" src="../../images/person/personal_sale_record.png"></image>
    <text class="item-text">售后记录</text>
  </view>
  <view class="person-line"></view>
  <view class="list-item">
    <image class="item-image" src="../../images/person/personal_evaluated.png"></image>
    <text class="item-text">我的评价</text>
  </view>
  <view class="person-line"></view>
  <view class="list-item">
    <image class="item-image" src="../../images/person/personal_customer.png"></image>
    <text class="item-text">在线客服</text>
  </view></view><view class="separate"></view>

mine.wxss

.userinfo {  
    display: flex;  
    flex-direction: column;  
    align-items: center;  
    background: #f0145a;   
    width: 100%; 
    height: 300rpx;
}
.userinfo-btn{  
    margin-top: 50rpx;  
    background: none !important;  
    color: #fff !important;  
    font-size: 40rpx;
}
.account-bg {  
    width: 100%;  
    height: 150rpx;
}
.userinfo-avatar {  
    width: 108rpx;  
    height: 108rpx;  
    margin: 40rpx;  
    border-radius: 50%;
}
.userinfo-nickname {  
    color: #fff;
}
/* 订单 */
.order {  
    display: flex;  
    flex-direction: row;  
    align-items: center;  
    width: 100%;  
    height: 90rpx;
}
.myorder-text {  
    font-size: 34rpx;  
    color: gray;  
    margin: 20rpx;  
    width: 40%;
}
.myorderlook-text {  
    font-size: 32rpx;  
    color: gray;  
    position: relative;  
    right: 20rpx;  
    width: 60%;  
    text-align: right;
}
.next-image {  
    width: 20rpx;  
    height: 25rpx;  
    position: relative;  
    right: 10rpx;
}
.navs {  
    display: flex;
}
.nav-item {  
    width: 25%;  
    display: flex;  
    align-items: center;  
    flex-direction: column;  
    padding: 20rpx;
}
.nav-item .nav-image {  
    width: 55rpx;  
    height: 55rpx;  
    margin: 5rpx;
}
.nav-item text {  
    margin-top: 20rpx;  
    font-size: 28rpx;  
    color: gray;
}
/* 列表 */
.person-list {  
    display: flex;  
    flex-direction: column;  
    align-items: left;
}
.list-item {      
    display: flex;  
    flex-direction: row;  
    align-items: center;  
    height: 80rpx;
}
.item-image {  
    width: 40rpx;  
    height: 40rpx;  
    margin: 20rpx;
}
.item-text {  
    color: gray;  
    font-size: 30rpx;  
    margin-left: 20rpx;
}
.person-line {  
    width: 80%;  
    height: 2rpx;  
    background: lightgray;  
    margin-left: 90rpx;
}

mine.js

var app = getApp()
Page({  
    data: {    
        userInfo: {},    
        hasUserInfo: false,        
        canIUse: wx.canIUse('button.open-type.getUserInfo'),    
        orderItems: [
      {        
        typeId: 0,        
        name: '待付款',        
        url: 'bill',        
        imageurl: '../../images/person/personal_pay.png',
      },
      {        
        typeId: 1,        
        name: '待收货',        
        url: 'bill',        
        imageurl: '../../images/person/personal_receipt.png',
      },
      {        
        typeId: 2,        
        name: '待评价',        
        url: 'bill',        
        imageurl: '../../images/person/personal_comment.png'
      },
      {        
        typeId: 3,        
        name: '退换/售后',        
        url: 'bill',        
        imageurl: '../../images/person/personal_service.png'
      }
    ],
  },  
    //事件处理函数
  toOrder: function () {
    wx.navigateTo({      url: '../order/order'
    })
  }
}

mine.json

{  "navigationBarTitleText": "个人中心"}

备注

微信小程序微商城系列 都是通过https 动态获取数据并展示的,建议从第一篇开始阅读。大家多多支持本系列文章会继续更新下去,谢谢各位!大家在使用过程中有哪些建议可以提出来,我们一起学习哈~~~

微信小程序微商城系列

微信小程序微商城:开发者key获取
微信小程序微商城(一):https框架搭建并实现导航功能
微信小程序微商城(二):电商首页轮播、分类导航和新品特卖实现
微信小程序微商城(三):电商首页福利专场无限下拉刷新动态API数据实现
微信小程序微商城(四):动态API实现商品详情页(上)
微信小程序微商城(五):动态API实现商品详情页(下)
微信小程序微商城(六):动态API实现新品特卖商品流式布局
微信小程序微商城(七):动态API实现商品分类
微信小程序微商城(八):缓存实现商品购物车功能

关注我们

如果需要源码和素材可以关注“IT实战联盟”公*众*号并留言(微商城源码,5个字会收到源码下载地址,一定要看源码里面的操作手册会少走很多弯路),也可以加入交流群和作者互撩哦~~~

IT实战联盟博客:http://blog.100boot.cn 

├── api │   └── api.js //接口 ├── app.wpy //入口文件 ├── components //组件 │   ├── address_add.wpy //新增地址组件 │   ├── address_edit.wpy //编辑地址组件 │   ├── address_list.wpy //地址列表组件 │   ├── bomb_screen.wpy //首页弹屏组件 │   ├── collection_list.wpy //收藏列表组件 │   ├── comment_list.wpy //评论列表组件 │   ├── common //公共组件 │   │   ├── bottomLoadMore.wpy //底部加载更多组件 │   │   ├── placeholder.wpy //空列表显示组件 │   │   ├── timer.wpy //倒计时组件 │   │   ├── wepy-area-picker.wpy //省市区组件 │   │   ├── wepy-sign-time.wpy //签到组件 │   │   └── wepy-swipe-delete.wpy //左滑删除组件 │   ├── discover.wpy //发现列表 │   ├── filterSlider.wpy //筛选右侧栏组件 │   ├── filter_bar.wpy //分类排序组件 │   ├── order_item.wpy //订单列表组件 │   ├── points_detail.wpy //列表组件 │   ├── points_rule.wpy //列表组件 │   ├── rate.wpy //评分组件 │   ├── search.wpy //搜索组件 │   ├── shop_cart.wpy //购物车组件 │   ├── shop_grid_list.wpy //矩阵列表 │   ├── shop_item_list.wpy //条形列表 │   └── tab.wpy //选项卡组件 ├── images //图片文件夹 ├── pages //页面 │   ├── address.wpy //地址 │   ├── classify.wpy //分类 │   ├── collection.wpy //收藏 │   ├── comfire_order.wpy //确认订单 │   ├── comment.wpy //评论列表 │   ├── comment_add.wpy //添加评论 │   ├── exchange_goods.wpy //换货 │   ├── filter.wpy //筛选 │   ├── goods_detail.wpy //商品详情 │   ├── home.wpy //首页 │   ├── home_detail.wpy //首页详情 │   ├── info.wpy //我的 │   ├── logistics.wpy //物流 │   ├── messages.wpy //我的消息 │   ├── order.wpy //订单列表 │   ├── order_detail.wpy //订单详情 │   ├── pay_success.wpy //支付结果 │   ├── points.wpy //积分 │   ├── points_more.wpy //更多积分 │   ├── points_rule.wpy //积分规则 │   ├── register.wpy //注册 │   ├── reorder.wpy //-- │   ├── replenishment_goods.wpy //补货 │   ├── search.wpy //搜索 │   ├── setting.wpy //设置 │   ├── shop_cart.wpy //购物车 │   ├── sign_in.wpy //签到 │   ├── test.wpy //--- │   └── wholesale.wpy //现货批发 ├── plugins //插件 │   └── wxParse //富文本 │   ├── html2json.js │   ├── htmlparser.js │   ├── showdown.js │   ├── wxDiscode.js │   ├── wxParse.js │   ├── wxParse.wxml │   └── wxParse.wxss ├── styles //样式 │   ├── base.less │   ├── icon.less // 图标文件 │   └── style.less └── utils //工具类 ├── constant.js //常量 ├── md5.js //md5 ├── regions.js //省市区数据 ├── tip.js //提示弹框组件 ├── util.js //工具 └── wxRequest.js //ajax请求
评论 20
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值