• 微信小程序自定义组件及会议管理与个人中心界面搭建


    一、自定义tabs组件

    1.1 创建自定义组件

    新建一个components文件夹 --> tabs文件夹 --> tabs文件

    创建好之后win7 以上的系统会报个错误:提示代码分析错误,已经被其他模块引用,只需要在

    在project.config.json文件里添加两行配置

    1. "ignoreDevUnusedFiles": false,
    2. "ignoreUploadUnusedFiles": false,

    1.2 tabs.wxml 编写组件界面

    1. <view class="tabs">
    2. <view class="tabs_title">
    3. <view wx:for="{{tabList}}" wx:key="id" class="title_item {{index==tabIndex?'item_active':''}}" bindtap="handleItemTap" data-index="{{index}}">
    4. <view style="margin-bottom:5rpx">{{item}}view>
    5. <view style="width:30px" class="{{index==tabIndex?'item_active1':''}}">view>
    6. view>
    7. view>
    8. <view class="tabs_content">
    9. <slot>slot>
    10. view>
    11. view>

    1.3 tabs.wxss 设计样式

    1. /* components/tabs/tabs.wxss */
    2. .tabs {
    3. position: fixed;
    4. top: 0;
    5. width: 100%;
    6. background-color: #fff;
    7. z-index: 99;
    8. border-bottom: 3px solid #efefef;
    9. padding-bottom: 20rpx;
    10. }
    11. .tabs_title {
    12. /* width: 400rpx; */
    13. width: 95%;
    14. display: flex;
    15. font-size: 13pt;
    16. padding: 0 20rpx
    17. }
    18. .title_item {
    19. color: #999;
    20. padding: 15rpx 0;
    21. display: flex;
    22. flex: 1;
    23. flex-flow: column nowrap;
    24. justify-content: center;
    25. align-items: center;
    26. }
    27. .item_active {
    28. /* color:#ED8137; */
    29. color: #000000;
    30. font-size: 11pt;
    31. font-weight: 800;
    32. }
    33. .item_active1 {
    34. /* color:#ED8137; */
    35. color: #000000;
    36. font-size: 11pt;
    37. font-weight: 800;
    38. border-bottom: 6rpx solid #333;
    39. border-radius: 2px;
    40. }

    1.4 tabs.js 定义组件的属性及事件

    1. // components/tabs/tabs.js
    2. var App = getApp();
    3. Component({
    4. /**
    5. * 组件的属性列表
    6. */
    7. properties: {
    8. tabList:Object
    9. },
    10. /**
    11. * 组件的初始数据
    12. */
    13. data: {
    14. tabIndex:0
    15. },
    16. /**
    17. * 组件的方法列表
    18. */
    19. methods: {
    20. handleItemTap(e){
    21. // 获取索引
    22. const {index} = e.currentTarget.dataset;
    23. // 触发 父组件的事件
    24. this.triggerEvent("tabsItemChange",{index})
    25. this.setData({
    26. tabIndex:index
    27. })
    28. }
    29. }
    30. })

    二、自定义组件使用

    2.1 引用组件

    在需要使用自定义组件的json中进行配置引用路径

    1. //list.json
    2. {
    3. "usingComponents": {
    4. "tabs":"/components/tabs/tabs"
    5. }
    6. }

    2.2 编写会议界面内容

    在界面使用组件并添加事件:

    <tabs tabList="{{tabs}}"  bindtabsItemChange="tabsItemChange">
    1. <tabs tabList="{{tabs}}" bindtabsItemChange="tabsItemChange">
    2. tabs>
    3. <view style="height: 100rpx;">view>
    4. <block wx:for-items="{{lists}}" wx:for-item="item" wx:key="item.id">
    5. <view class="list" data-id="{{item.id}}">
    6. <view class="list-img al-center">
    7. <image class="video-img" mode="scaleToFill" src="{{item.image}}">image>
    8. view>
    9. <view class="list-detail">
    10. <view class="list-title"><text>{{item.title}}text>view>
    11. <view class="list-tag">
    12. <view class="state al-center">{{item.state}}view>
    13. <view class="join al-center"><text class="list-num">{{item.num}}text>人报名view>
    14. view>
    15. <view class="list-info"><text>{{item.address}}text>|<text>{{item.time}}text>view>
    16. view>
    17. view>
    18. block>

    2.3 设计样式

    1. .list{
    2. display: flex;
    3. border-bottom: rgb(233, 231, 231) solid 3px;
    4. }
    5. .list-img{
    6. display: flex;
    7. align-items: center;
    8. margin-right: 15px;
    9. }
    10. .video-img{
    11. width: 120rpx;
    12. height: 120rpx;
    13. }
    14. .list-title{
    15. font-weight: bold;
    16. }
    17. .list-tag{
    18. display: flex;
    19. }
    20. .state{
    21. border: rgb(35, 171, 224) solid 1px;
    22. color: rgb(35, 171, 224);
    23. align-items: center;
    24. width: 65px;
    25. display: flex;
    26. justify-content: center;
    27. }
    28. .join{
    29. margin-left: 8px;
    30. color: lightgray;
    31. }
    32. .list-num{
    33. color: red;
    34. font-weight: 600;
    35. }
    36. .list-info{
    37. display: flex;
    38. color: lightgray;
    39. margin-top: 10px;
    40. }
    41. .mysection{
    42. display: flex;
    43. justify-content: center;
    44. }
    45. .userinfo {
    46. display: flex;
    47. flex-direction: column;
    48. align-items: center;
    49. color: #aaa;
    50. }
    51. .userinfo-avatar {
    52. overflow: hidden;
    53. width: 128rpx;
    54. height: 128rpx;
    55. margin: 20rpx;
    56. border-radius: 50%;
    57. }
    58. .usermotto {
    59. margin-top: 200px;
    60. }

    2.4 模拟数据并实现切换tabs方法

    1. // pages/meeting/list/list.js
    2. Page({
    3. /**
    4. * 页面的初始数据
    5. */
    6. data: {
    7. tabs:['会议中','已完成','已取消','全部会议'],
    8. lists: [
    9. {
    10. 'id': '1',
    11. 'image': '/static/persons/1.jpg',
    12. 'title': '对话产品总监 | 深圳·北京PM大会 【深度对话小米/京东/等产品总监】',
    13. 'num':'304',
    14. 'state':'进行中',
    15. 'time': '10月09日 17:59',
    16. 'address': '深圳市·南山区'
    17. },
    18. {
    19. 'id': '1',
    20. 'image': '/static/persons/2.jpg',
    21. 'title': 'AI WORLD 2016世界人工智能大会',
    22. 'num':'380',
    23. 'state':'已结束',
    24. 'time': '10月09日 17:39',
    25. 'address': '北京市·朝阳区'
    26. },
    27. {
    28. 'id': '1',
    29. 'image': '/static/persons/3.jpg',
    30. 'title': 'H100太空商业大会',
    31. 'num':'500',
    32. 'state':'进行中',
    33. 'time': '10月09日 17:31',
    34. 'address': '大连市'
    35. },
    36. {
    37. 'id': '1',
    38. 'image': '/static/persons/4.jpg',
    39. 'title': '报名年度盛事,大咖云集!2016凤凰国际论坛邀您“与世界对话”',
    40. 'num':'150',
    41. 'state':'已结束',
    42. 'time': '10月09日 17:21',
    43. 'address': '北京市·朝阳区'
    44. },
    45. {
    46. 'id': '1',
    47. 'image': '/static/persons/5.jpg',
    48. 'title': '新质生活 · 品质时代 2016消费升级创新大会',
    49. 'num':'217',
    50. 'state':'进行中',
    51. 'time': '10月09日 16:59',
    52. 'address': '北京市·朝阳区'
    53. }
    54. ],
    55. lists1: [
    56. {
    57. 'id': '1',
    58. 'image': '/static/persons/1.jpg',
    59. 'title': '对话产品总监 | 深圳·北京PM大会 【深度对话小米/京东/等产品总监】',
    60. 'num':'304',
    61. 'state':'进行中',
    62. 'time': '10月09日 17:59',
    63. 'address': '深圳市·南山区'
    64. },
    65. {
    66. 'id': '1',
    67. 'image': '/static/persons/2.jpg',
    68. 'title': 'AI WORLD 2016世界人工智能大会',
    69. 'num':'380',
    70. 'state':'已结束',
    71. 'time': '10月09日 17:39',
    72. 'address': '北京市·朝阳区'
    73. },
    74. {
    75. 'id': '1',
    76. 'image': '/static/persons/3.jpg',
    77. 'title': 'H100太空商业大会',
    78. 'num':'500',
    79. 'state':'进行中',
    80. 'time': '10月09日 17:31',
    81. 'address': '大连市'
    82. }
    83. ],
    84. lists2: [
    85. {
    86. 'id': '1',
    87. 'image': '/static/persons/1.jpg',
    88. 'title': '对话产品总监 | 深圳·北京PM大会 【深度对话小米/京东/等产品总监】',
    89. 'num':'304',
    90. 'state':'进行中',
    91. 'time': '10月09日 17:59',
    92. 'address': '深圳市·南山区'
    93. },
    94. {
    95. 'id': '1',
    96. 'image': '/static/persons/2.jpg',
    97. 'title': 'AI WORLD 2016世界人工智能大会',
    98. 'num':'380',
    99. 'state':'已结束',
    100. 'time': '10月09日 17:39',
    101. 'address': '北京市·朝阳区'
    102. }
    103. ],
    104. lists3: [
    105. {
    106. 'id': '1',
    107. 'image': '/static/persons/1.jpg',
    108. 'title': '对话产品总监 | 深圳·北京PM大会 【深度对话小米/京东/等产品总监】',
    109. 'num':'304',
    110. 'state':'进行中',
    111. 'time': '10月09日 17:59',
    112. 'address': '深圳市·南山区'
    113. },
    114. {
    115. 'id': '1',
    116. 'image': '/static/persons/2.jpg',
    117. 'title': 'AI WORLD 2016世界人工智能大会',
    118. 'num':'380',
    119. 'state':'已结束',
    120. 'time': '10月09日 17:39',
    121. 'address': '北京市·朝阳区'
    122. },
    123. {
    124. 'id': '1',
    125. 'image': '/static/persons/3.jpg',
    126. 'title': 'H100太空商业大会',
    127. 'num':'500',
    128. 'state':'进行中',
    129. 'time': '10月09日 17:31',
    130. 'address': '大连市'
    131. },
    132. {
    133. 'id': '1',
    134. 'image': '/static/persons/4.jpg',
    135. 'title': '报名年度盛事,大咖云集!2016凤凰国际论坛邀您“与世界对话”',
    136. 'num':'150',
    137. 'state':'已结束',
    138. 'time': '10月09日 17:21',
    139. 'address': '北京市·朝阳区'
    140. },
    141. {
    142. 'id': '1',
    143. 'image': '/static/persons/5.jpg',
    144. 'title': '新质生活 · 品质时代 2016消费升级创新大会',
    145. 'num':'217',
    146. 'state':'进行中',
    147. 'time': '10月09日 16:59',
    148. 'address': '北京市·朝阳区'
    149. }
    150. ]
    151. },
    152. /**
    153. * 生命周期函数--监听页面加载
    154. */
    155. onLoad(options) {
    156. },
    157. /**
    158. * 生命周期函数--监听页面显示
    159. */
    160. onShow() {
    161. },
    162. tabsItemChange(e){
    163. let tolists;
    164. if(e.detail.index==1){
    165. tolists = this.data.lists1;
    166. }else if(e.detail.index==2){
    167. tolists = this.data.lists2;
    168. }else{
    169. tolists = this.data.lists3;
    170. }
    171. this.setData({
    172. lists: tolists
    173. })
    174. }
    175. })

    2.5 效果展示

    三、个人中心界面搭建

    3.1 WXML

    1. <view class="userInfo">
    2. <image class="userInfo-head" src="/static/persons/1.jpg">image>
    3. <text class="userInfo-login">用户登录text>
    4. <image class="userInfo-set" src="/static/tabBar/component.png">image>
    5. view>
    6. <view class="cells">
    7. <view class="cell-items">
    8. <image src="/static/tabBar/coding-active.png" class="cell-items-icon">image>
    9. <text class="cell-items-title">我主持的会议text>
    10. <text class="cell-items-num">1text>
    11. <text class="cell-items-detail">text>
    12. view>
    13. <hr/>
    14. <view class="cell-items">
    15. <image src="/static/tabBar/component-active.png" class="cell-items-icon">image>
    16. <text class="cell-items-title">我参与的会议text>
    17. <text class="cell-items-num">1text>
    18. <text class="cell-items-detail">text>
    19. view>
    20. view>
    21. <view class="cells">
    22. <view class="cell-items">
    23. <image src="/static/tabBar/component-active.png" class="cell-items-icon">image>
    24. <text class="cell-items-title">我发布的投票text>
    25. <text class="cell-items-num">1text>
    26. <text class="cell-items-detail">text>
    27. view>
    28. <hr/>
    29. <view class="cell-items">
    30. <image src="/static/tabBar/component-active.png" class="cell-items-icon">image>
    31. <text class="cell-items-title">我参与的投票text>
    32. <text class="cell-items-num">1text>
    33. <text class="cell-items-detail">text>
    34. view>
    35. view>
    36. <view class="cells">
    37. <view class="cell-items">
    38. <image src="/static/tabBar/component-active.png" class="cell-items-icon">image>
    39. <text space="ensp" class="cell-items-title">消 息text>
    40. <text class="cell-items-num">1text>
    41. <text class="cell-items-detail">text>
    42. view>
    43. <hr/>
    44. <view class="cell-items">
    45. <image src="/static/tabBar/component-active.png" class="cell-items-icon">image>
    46. <text space="ensp" class="cell-items-title">设 置text>
    47. <text class="cell-items-num">1text>
    48. <text class="cell-items-detail">text>
    49. view>
    50. view>

    3.2 WXSS

    1. /* pages/ucenter/index/index.wxss */
    2. Page{
    3. background-color: rgba(135, 206, 250, 0.075);
    4. }
    5. .userInfo{
    6. display: flex;
    7. height: 400rpx;
    8. width: 100%;
    9. background-color: #fff;
    10. margin-bottom: 20rpx;
    11. }
    12. .userInfo-head{
    13. height: 300rpx;
    14. width: 300rpx;
    15. margin: 20rpx;
    16. }
    17. .userInfo-login{
    18. width: 400rpx;
    19. margin:150rpx 20rpx;
    20. }
    21. .userInfo-set{
    22. height: 100rpx;
    23. width: 100rpx;
    24. margin:120rpx 20rpx;
    25. }
    26. .cells{
    27. background-color: #fff;
    28. height: 270rpx;
    29. }
    30. .cell-items{
    31. height: 120rpx;
    32. display: flex;
    33. margin: 30rpx 0 0 0;
    34. /* border-bottom: 1px solid lightskyblue; */
    35. }
    36. .cell-items-icon{
    37. height: 100rpx;
    38. width: 100rpx;
    39. }
    40. .cell-items-title{
    41. font-weight: 700;
    42. font-size: 18px;
    43. margin: 20rpx 0 0 50rpx;
    44. }
    45. .cell-items-num{
    46. margin: 20rpx 0 0 300rpx;
    47. }
    48. .cell-items-detail{
    49. margin: 20rpx 0 0 20rpx;
    50. }
    51. .cells > hr{
    52. display: block;
    53. height: 1px;
    54. background-color: rgba(135, 206, 250, 0.075);
    55. }

     

  • 相关阅读:
    Qt编写物联网管理平台44-告警邮件转发
    关于binwalk->sasquatch插件安装错误的缓解方案
    visual studio 如何建立 C 语言项目
    wordpress 上传附件中文文件名乱码解决办法(for Windows)
    多个Bean自动注入成Map @Autowired @Service 策略模式
    seaborn
    (附源码)计算机毕业设计SSM基于框架的报修系统
    算法导论笔记5:贪心算法
    另眼旁观 Linkerd 2.12 的发布:服务网格标准的曙光?
    王杰国庆作业day6
  • 原文地址:https://blog.csdn.net/Ying_hao_kun/article/details/133943632