微信小程序实战篇-个人中心

哈喽,大家好,又到周五啦,有木有期待今天的更新呀~今天要教大家的是制作个人中心界面,先上效果图


个人中心.gif

个人中心制作

1. mine.js

// pages/mine/mine.js
var app = getApp()
Page({
  data: {
    userInfo: {},
    motto: 'Hello World',
    // orderItems
    orderItems: [
      {
        typeId: 0,
        name: '待付款',
        url: 'bill',
        imageurl: '../../images/person/personal_pay.png',
      },
      {
        typeId: 1,
        name: '待发货',
        url: 'bill',
        imageurl: '../../images/person/personal_shipped.png',
      },
      {
        typeId: 2,
        name: '待收货',
        url: 'bill',
        imageurl: '../../images/person/personal_receipt.png'
      },
      {
        typeId: 3,
        name: '待评价',
        url: 'bill',
        imageurl: '../../images/person/personal_comment.png'
      }
    ],
  },
  //事件处理函数
  toOrder: function () {
    wx.navigateTo({
      url: '../order/order'
    })
  },
  onLoad: function () {
    console.log('onLoad')
    var that = this
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function (userInfo) {
      //更新数据
      that.setData({
        userInfo: userInfo
      })
    })
  }
})

toOrder :事件监听,跳转到我的订单界面
onLoad:在加载过程中,获取用户的信息

2. mine.wxml

<!--pages/mine/mine.wxml-->
<view class="container">

  <view class="userinfo">
    <image class="userinfo-avatar" src="{{userInfo.avatarUrl}}" background-size="cover"></image>
    <text class="userinfo-nickname">{{userInfo.nickName}}</text>
    <image src="../../images/person/account_bg.png" class="account-bg">
    </image>
  </view>
  
  <view class="separate"></view>

  <view class="order" catchtap="toOrder">
    <text class="myorder-text">我的订单</text>
    <text class="myorderlook-text">查看全部订单</text>
    <image class="next-image" src="../../images/person/next.png"></image>
  </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_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_share.png"></image>
      <text class="item-text">推广邀请</text>
    </view>
  </view>
  <view class="separate"></view>
</view>

布局分为三个模块,用户信息模块、我的订单模块、功能列表模块,布局不是很难,相信看源码就可以理解

3. mine.wxss

/* pages/mine/mine.wxss */
.userinfo {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #f0145a;
}
.account-bg {
  width: 100%;
  height: 150rpx;
}
.userinfo-avatar {
  width: 108rpx;
  height: 108rpx;
  margin: 20rpx;
  border-radius: 50%;
}
.userinfo-nickname {
  color: #fff;
}
/* 订单 */
.order {
  display: flex;
  flex-direction: row;
  align-items: center;
  width: 100%;
  height: 90rpx;
}
.myorder-text {
  font-size: 30rpx;
  color: gray;
  margin: 20rpx;
  width: 40%;
}
.myorderlook-text {
  font-size: 30rpx;
  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: 40rpx;
  height: 40rpx;
  margin: 5rpx;
}
.nav-item text {
  margin-top: 20rpx;
  font-size: 25rpx;
  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: 25rpx;
  margin-left: 20rpx;
}
.person-line {
  width: 100%;
  height: 2rpx;
  background: lightgray;
  margin-left: 90rpx;
}

样式列表我重点讲解一下 userinfo-avatar 类中的 border-radius 属性,大家看一下效果就知道他的作用,没错设置圆角图片,正常我们都是方方正正的图片,有了这个属性,可以轻松实现圆角图片了

我的订单制作

我的订单,其实界面的实现原理和首页的导航栏是一样的,只不过换了一下内容以及导航栏标题罢了,所以这里我就不细讲了,不懂的朋友可以看我首页导航栏是怎么制作的,模仿写出来就好

1. order.js

// pages/order/order.js
var Zan = require('../../template/contract.js');
Page(Object.assign({}, Zan.Tab, {
  data: {
    tab1: {
      list: [{
        id: 0,
        title: '全部'
      }, {
        id: 1,
        title: '待付款'
      }, {
        id: 2,
        title: '待发货'
      }, {
        id: 3,
        title: '待收货'
      }, {
        id: 4,
        title: '待评价'
      }],
      selectedId: 0,
      scroll: false,
    },
  },
  handleZanTabChange(e) {
    var componentId = e.componentId;
    var selectedId = e.selectedId;
    this.setData({
      `${componentId}.selectedId`: selectedId
    });
  }
}));

2. order.wxml

<!--pages/order/order.wxml-->
<import src="/template/tab/tab.wxml" />
 <view class="tab">
    <template is="zan-tab" data="{{tab: tab1, componentId: 'tab1'}}"></template>
  </view>
<view class="tab-content1" >
<image class="tab-image" src="../../images/order/non_cart.png"></image>
<text>您还没有相关订单哦!</text>
</view>

3. order.wxss

/* pages/order/order.wxss */
.tab-content1
{
  display: flex;
  flex-direction: column;
  align-items: center;
}
.tab-image
{
  width: 50%;
  margin-top: 130rpx;
  margin-bottom: 50rpx;
}

总结

界面布局差不多就讲到这里了,大家也看到了,其实越到后面,要讲的界面内容知识就越少,万变不离其中吧,后续的话,代码君打算讲一下微信小程序的网络请求框架,敬请期待,最后祝大家周末愉快~

上一篇:微信小程序实战篇-购物车

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 151,829评论 1 331
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 64,603评论 1 273
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 101,846评论 0 226
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 42,600评论 0 191
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 50,780评论 3 272
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 39,695评论 1 192
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,136评论 2 293
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 29,862评论 0 182
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 33,453评论 0 229
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 29,942评论 2 233
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,347评论 1 242
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 27,790评论 2 236
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,293评论 3 221
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 25,839评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,448评论 0 181
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 34,564评论 2 249
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 34,623评论 2 249

推荐阅读更多精彩内容