• 小程序之自定义组件 结合案例


                                                      🎬 艳艳耶✌️:个人主页

                                                      🔥 个人专栏 :《Spring与Mybatis集成整合》《Vue.js使用》

                                                      ⛺️ 越努力 ,越幸运。

    1.自定义组件

        开发者可以将页面内的功能模块抽象成自定义组件,以便在不同的页面中重复使用;也可以将复杂的页面拆分成多个低耦合的模块,有助于代码维护。自定义组件在使用时与基础组件非常相似。

    1.1创建 

    在项目中创建一个名为 : components 的文件,来存放组件

    再在components文件夹中创建一个组件,名为 : tabs 

    如图所示 : 

    1.2.定义 

    类似于页面,一个自定义组件由 json wxml wxss js 4个文件组成。要编写一个自定义组件,首先需要在 json 文件中进行自定义组件声明(将 component 字段设为 true 可将这一组文件设为自定义组件):

    在 tabs.json 中编写: 

    1. {
    2. "component": true,
    3. "usingComponents": {}
    4. }

    同时,还要在 wxml 文件中编写组件模板,在 wxss 文件中加入组件样式,它们的写法与页面的写法类似。具体细节和注意事项参见 组件模板和样式 。

     1.3.编写

    在 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>

    在 tabs.js 中进行编写功能 :

    1. // components/tabs/tabs.js
    2. Component({
    3. /**
    4. * 组件的属性列表
    5. */
    6. properties: {
    7. // 这里定义了innerText属性,属性值可以在组件使用时指定
    8. innerText: {
    9. type: String,
    10. value: 'default value'
    11. },
    12. tabList:Object
    13. },
    14. /**
    15. * 组件的初始数据
    16. */
    17. data: {
    18. tabIndex:1
    19. },
    20. /**
    21. * 组件的方法列表
    22. */
    23. methods: {
    24. handleItemTap(e){
    25. // 获取索引
    26. const {index} = e.currentTarget.dataset;
    27. // 触发 父组件的事件
    28. this.triggerEvent("tabsItemChange",{index})
    29. this.setData({
    30. tabIndex:index
    31. })
    32. }
    33. }
    34. })

    在 tabs.wxss 中进行编写样式:

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

    1.4. 使用

    在项目的 project.config.json 文件中的setting属性中进行配置,增加以下两个配置 :

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

    需要在哪个页面中进行使用,就需要在哪个页面中进行引用配置

    比如说 : 需要在会议页面中进行使用,就要在  会议页面.json (meeting/list/list.json)

     中增加以下设置

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

    然后再 list.js 中进行初始化数据,在data属性中编写 : 

    1. data: {
    2. tabs:['会议中','已完成','已取消','全部会议']
    3. }

    在 list.wxml中使用 

    1. <tabs tabList="{{tabs}}" bindtabsItemChange="tabsItemChange">
    2. tabs>

    效果展示:

    注意事项: 

    因为 WXML 节点标签名只能是小写字母、中划线和下划线的组合,所以自定义组件的标签名也只能包含这些字符。
    自定义组件也是可以引用自定义组件的,引用方法类似于页面引用自定义组件的方式(使用 usingComponents 字段)。
    自定义组件和页面所在项目根目录名不能以“wx-”为前缀,否则会报错。

    2.会议

    2.1. 数据

    在会议的 list.js 中进行初始化数据进行页面显示效果 :

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

    2.2. 显示 

    在会议的 list.wxml  中进行编写 :

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

    2.3. 样式

    在会议的 list.wxss  中进行编写样式,美化页面 :

    1. /* pages/meeting/list/list.wxss */
    2. .list {
    3. display: flex;
    4. flex-direction: row;
    5. width: 100%;
    6. padding: 0 20rpx 0 0;
    7. border-top: 1px solid #eeeeee;
    8. background-color: #fff;
    9. margin-bottom: 5rpx;
    10. /* border-radius: 20rpx;
    11. box-shadow: 0px 0px 10px 6px rgba(0,0,0,0.1); */
    12. }
    13. .list-img {
    14. display: flex;
    15. margin: 10rpx 10rpx;
    16. width: 150rpx;
    17. height: 220rpx;
    18. justify-content: center;
    19. align-items: center;
    20. }
    21. .list-img .video-img {
    22. width: 120rpx;
    23. height: 120rpx;
    24. }
    25. .list-detail {
    26. margin: 10rpx 10rpx;
    27. display: flex;
    28. flex-direction: column;
    29. width: 600rpx;
    30. height: 220rpx;
    31. }
    32. .list-title text {
    33. font-size: 11pt;
    34. color: #333;
    35. font-weight: bold;
    36. }
    37. .list-detail .list-tag {
    38. display: flex;
    39. height: 70rpx;
    40. }
    41. .list-tag .state {
    42. font-size: 9pt;
    43. color: #81aaf7;
    44. width: 120rpx;
    45. border: 1px solid #93b9ff;
    46. border-radius: 2px;
    47. margin: 10rpx 0rpx;
    48. display: flex;
    49. justify-content: center;
    50. align-items: center;
    51. }
    52. .list-tag .join {
    53. font-size: 11pt;
    54. color: #bbb;
    55. margin-left: 20rpx;
    56. display: flex;
    57. justify-content: center;
    58. align-items: center;
    59. }
    60. .list-tag .list-num {
    61. font-size: 11pt;
    62. color: #ff6666;
    63. }
    64. .list-info {
    65. font-size: 9pt;
    66. color: #bbb;
    67. margin-top: 20rpx;
    68. }
    69. .bottom-line{
    70. display: flex;
    71. height: 60rpx;
    72. justify-content: center;
    73. align-items: center;
    74. background-color: #f3f3f3;
    75. }
    76. .bottom-line text{
    77. font-size: 9pt;
    78. color: #666;
    79. }

    效果展示:

    3个人中心

    3.1. 页面

    在个人中心页面中编写 .wxml 文件(如 : ucenter/index/index.wxml) 进行页面显示

    1. <view class="user">
    2. <image class="user-img" src="/static/persons/2.jpg"></image>
    3. <view class="user-name">ಥ诗雅ಥ</view>
    4. <text class="user-up">修改</text>
    5. </view>
    6. <view class="cells">
    7. <view class="cell-items">
    8. <image src="/static/tabBar/sdk.png" class="cell-items-icon"></image>
    9. <text class="cell-items-title">我主持的会议</text>
    10. <text class="cell-items-num">1</text>
    11. <text class="cell-items-detail">👉</text>
    12. </view>
    13. <view style="height: 5rpx;background-color: rgba(135, 206, 250, 0.075);"></view>
    14. <view class="cell-items">
    15. <image src="/static/tabBar/sdk.png" class="cell-items-icon"></image>
    16. <text class="cell-items-title">我参与的会议</text>
    17. <text class="cell-items-num">10</text>
    18. <text class="cell-items-detail">👉</text>
    19. </view>
    20. </view>
    21. <view style="height: 27rpx;background-color: rgba(135, 206, 250, 0.075);"></view>
    22. <view class="cells">
    23. <view class="cell-items">
    24. <image src="/static/tabBar/sdk.png" class="cell-items-icon"></image>
    25. <text class="cell-items-title">我发布的投票</text>
    26. <text class="cell-items-num">1</text>
    27. <text class="cell-items-detail">👉</text>
    28. </view>
    29. <view style="height: 5rpx;background-color: rgba(135, 206, 250, 0.075);"></view>
    30. <view class="cell-items">
    31. <image src="/static/tabBar/sdk.png" class="cell-items-icon"></image>
    32. <text class="cell-items-title">我参与的投票</text>
    33. <text class="cell-items-num">10</text>
    34. <text class="cell-items-detail">👉</text>
    35. </view>
    36. </view>
    37. <view style="height: 27rpx;background-color: rgba(135, 206, 250, 0.075);"></view>
    38. <view class="cells">
    39. <view class="cell-items">
    40. <image src="/static/tabBar/template.png" class="cell-items-icon"></image>
    41. <text class="cell-items-title">信息</text>
    42. <text class="cell-items-ion">👉</text>
    43. </view>
    44. <view style="height: 5rpx;background-color: rgba(135, 206, 250, 0.075);"></view>
    45. <view class="cell-items">
    46. <image src="/static/tabBar/component.png" class="cell-items-icon"></image>
    47. <text class="cell-items-title">设置</text>
    48. <text class="cell-items-ion">👉</text>
    49. </view>
    50. </view>

    3.2. 样式

    在个人中心的 .wxss 样式文件 中进行编写样式,来美化布局的页面效果(如 : ucenter/index/index.wxss)

    1. /* pages/ucenter/index/index.wxss */
    2. Page{
    3. background-color: rgba(135, 206, 250, 0.075);
    4. }
    5. .user{
    6. display: flex;
    7. width: 100%;
    8. align-items:center;
    9. background-color: white;
    10. margin-bottom: 28rpx;
    11. }
    12. .user-img{
    13. height: 170rpx;
    14. width: 170rpx;
    15. margin: 30rpx;
    16. border: 1px solid #cdd7ee;
    17. border-radius: 6px;
    18. }
    19. .user-name{
    20. width: 380rpx;
    21. margin-left: 20rpx;
    22. font-weight: 550;
    23. }
    24. .user-up{
    25. color: rgb(136, 133, 133);
    26. }
    27. .cells{
    28. background-color: white;
    29. }
    30. .cell-items{
    31. display: flex;
    32. align-items:center;
    33. height: 110rpx;
    34. }
    35. .cell-items-title{
    36. width: 290rpx;
    37. }
    38. .cell-items-icon{
    39. width: 50rpx;
    40. height: 50rpx;
    41. margin: 20rpx;
    42. }
    43. .cell-items-num{
    44. padding-left: 30rpx;
    45. margin-left: 200rpx;
    46. width: 70rpx;
    47. }
    48. .cell-items-ion{
    49. margin-left: 295rpx;
    50. }

    效果展示:

    4.投票管理

    4.1. 引用

    在 投票页面的 .json 文件( 如: vote/list/list.json )中进行编写 :

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

    4.2. 数据

    在 投票页面的 .js 文件( 如: vote/list/list.js )中进行编写初始化数据及方法功能 :

    1. // pages/vote/list/list.js
    2. Page({
    3. /**
    4. * 页面的初始数据
    5. */
    6. data: {
    7. tabs:['全部投票','已发起','已投票','未投票'],
    8. lists: [
    9. {
    10. 'id': '1',
    11. 'image': '/static/persons/9.jpg',
    12. 'title': '北京PM大会',
    13. 'name' : '彪总',
    14. 'vote' : '是否认同与京东进行产品合作',
    15. 'num' : '204',
    16. 'state':'未投票',
    17. 'time' : '10月09日 17:59',
    18. 'address': '深圳市·南山区'
    19. },
    20. {
    21. 'id': '2',
    22. 'image': '/static/persons/12.jpg',
    23. 'name' : '李总',
    24. 'title': 'AIWORLD人工智能大会',
    25. 'vote' : '是否投资AI发展',
    26. 'num' : '380',
    27. 'state':'已投票',
    28. 'time' : '10月09日 17:39',
    29. 'address': '北京市·朝阳区'
    30. },
    31. {
    32. 'id': '3',
    33. 'image': '/static/persons/13.jpg',
    34. 'name' : '刘总',
    35. 'title': 'H100太空商业大会',
    36. 'vote' : '是否太空商业进行合作',
    37. 'num' : '830',
    38. 'state': '未参与',
    39. 'time' : '10月09日 17:31',
    40. 'address': '大连市'
    41. },
    42. {
    43. 'id': '4',
    44. 'image': '/static/persons/14.jpg',
    45. 'name' : ' 杨总监 ',
    46. 'title': '2023消费升级创新大会',
    47. 'vote' : '是否对本次创新持续升级',
    48. 'num':'117',
    49. 'state':'已投票',
    50. 'time': '11月20日 16:59',
    51. 'address': '北京市·朝阳区'
    52. }
    53. ],
    54. lists1: [
    55. {
    56. 'id': '1',
    57. 'image': '/static/persons/9.jpg',
    58. 'name' : '彪总',
    59. 'title': '深圳·北京PM大会',
    60. 'vote' : '是否认同与京东进行产品合作',
    61. 'num' : '204',
    62. 'state':'未投票',
    63. 'time' : '10月09日 17:59',
    64. 'address': '深圳市·南山区'
    65. },
    66. {
    67. 'id': '2',
    68. 'image': '/static/persons/9.jpg',
    69. 'name' : '王总监',
    70. 'title': 'AIWORLD人工智能大会',
    71. 'vote' : '是否投资AI发展',
    72. 'num' : '280',
    73. 'state':'已投票',
    74. 'time' : '10月09日 17:39',
    75. 'address': '北京市·朝阳区'
    76. },
    77. {
    78. 'id': '3',
    79. 'image': '/static/persons/16.jpg',
    80. 'name' : '陈总',
    81. 'title': 'H100太空商业大会',
    82. 'vote' : '是否太空商业进行合作',
    83. 'num' : '300',
    84. 'state': '已参与',
    85. 'time' : '10月09日 17:31',
    86. 'address': '大连市'
    87. },
    88. {
    89. 'id': '4',
    90. 'image': '/static/persons/15.jpg',
    91. 'name' : ' 尹总 ',
    92. 'title': '2023消费升级创新大会',
    93. 'vote' : '是否对本次创新持续升级',
    94. 'num':'217',
    95. 'state':'已投票',
    96. 'time': '11月20日 16:59',
    97. 'address': '北京市·朝阳区'
    98. }
    99. ],
    100. lists2: [
    101. {
    102. 'id': '1',
    103. 'image': '/static/persons/14.jpg',
    104. 'name' : '邓总',
    105. 'title': '深圳·北京PM大会',
    106. 'vote' : '是否认同与京东进行产品合作',
    107. 'num' : '422',
    108. 'state':'已投票',
    109. 'time' : '10月09日 17:59',
    110. 'address': '深圳市·南山区'
    111. },
    112. {
    113. 'id': '2',
    114. 'image': '/static/persons/13.jpg',
    115. 'name' : '黄总',
    116. 'title': 'AIWORLD人工智能大会',
    117. 'vote' : '是否投资AI发展',
    118. 'num' : '377',
    119. 'state':'已投票',
    120. 'time' : '10月09日 17:39',
    121. 'address': '北京市·朝阳区'
    122. },
    123. {
    124. 'id': '3',
    125. 'image': '/static/persons/12.jpg',
    126. 'name' : '李总',
    127. 'title': 'H100太空商业大会',
    128. 'vote' : '是否太空商业进行合作',
    129. 'num' : '463',
    130. 'state': '已投票',
    131. 'time' : '10月09日 17:31',
    132. 'address': '大连市'
    133. },
    134. {
    135. 'id': '4',
    136. 'image': '/static/persons/11.jpg',
    137. 'name' : ' 王总 ',
    138. 'title': '2023消费升级创新大会',
    139. 'vote' : '是否对本次创新持续升级',
    140. 'num':'543',
    141. 'state':'已投票',
    142. 'time': '11月20日 16:59',
    143. 'address': '北京市·朝阳区'
    144. }
    145. ],
    146. lists3: [
    147. {
    148. 'id': '1',
    149. 'image': '/static/persons/12.jpg',
    150. 'name' : '邓总',
    151. 'title': '深圳·北京PM大会',
    152. 'vote' : '是否认同与京东进行产品合作',
    153. 'num' : '422',
    154. 'state':'未投票',
    155. 'time' : '10月09日 17:59',
    156. 'address': '深圳市·南山区'
    157. },
    158. {
    159. 'id': '2',
    160. 'image': '/static/persons/13.jpg',
    161. 'name' : '黄总',
    162. 'title': 'AIWORLD人工智能大会',
    163. 'vote' : '是否投资AI发展',
    164. 'num' : '377',
    165. 'state':'未投票',
    166. 'time' : '10月09日 17:39',
    167. 'address': '北京市·朝阳区'
    168. },
    169. {
    170. 'id': '3',
    171. 'image': '/static/persons/14.jpg',
    172. 'name' : '李总',
    173. 'title': 'H100太空商业大会',
    174. 'vote' : '是否太空商业进行合作',
    175. 'num' : '463',
    176. 'state': '未参与',
    177. 'time' : '10月09日 17:31',
    178. 'address': '大连市'
    179. },
    180. {
    181. 'id': '4',
    182. 'image': '/static/persons/15.jpg',
    183. 'name' : ' 王总 ',
    184. 'title': '2023消费升级创新大会',
    185. 'vote' : '是否对本次创新持续升级',
    186. 'num':'543',
    187. 'state':'未投票',
    188. 'time': '11月20日 16:59',
    189. 'address': '北京市·朝阳区'
    190. }
    191. ]
    192. },
    193. tabsItemChange(e){
    194. console.log(e.detail);
    195. let tolists;
    196. if(e.detail.index==1){
    197. tolists = this.data.lists1;
    198. }else if(e.detail.index==2){
    199. tolists = this.data.lists2;
    200. }else if(e.detail.index==3){
    201. tolists = this.data.lists3;
    202. }else{
    203. tolists = this.data.lists;
    204. }
    205. this.setData({
    206. lists: tolists
    207. })
    208. },
    209. /**
    210. * 生命周期函数--监听页面加载
    211. */
    212. onLoad(options) {
    213. },
    214. /**
    215. * 生命周期函数--监听页面初次渲染完成
    216. */
    217. onReady() {
    218. },
    219. /**
    220. * 生命周期函数--监听页面显示
    221. */
    222. onShow() {
    223. },
    224. /**
    225. * 生命周期函数--监听页面隐藏
    226. */
    227. onHide() {
    228. },
    229. /**
    230. * 生命周期函数--监听页面卸载
    231. */
    232. onUnload() {
    233. },
    234. /**
    235. * 页面相关事件处理函数--监听用户下拉动作
    236. */
    237. onPullDownRefresh() {
    238. },
    239. /**
    240. * 页面上拉触底事件的处理函数
    241. */
    242. onReachBottom() {
    243. },
    244. /**
    245. * 用户点击右上角分享
    246. */
    247. onShareAppMessage() {
    248. }
    249. })

    4.3. 页面

    在投票页面的 wxml 文件( 如: vote/list/list.wxml )中进行编写页面标签显示数据及效果 :

    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><text style="margin-right: 13rpx;"> 发 起 人</text> : {{item.name}}</text></view>
    11. <view class="list-title"><text>会议名称 : {{item.title}}</text></view>
    12. <view class="list-title"><text>投票标题 : [ {{item.vote}} ]</text></view>
    13. <view class="list-tag">
    14. <view class="state al-center">{{item.state}}</view>
    15. <view class="join al-center"><text class="list-num" >{{item.num}}</text>人参与投票</view>
    16. </view>
    17. <view class="list-info"><text>{{item.address}}</text> | <text>{{item.time}}</text></view>
    18. </view>
    19. </view>
    20. </block>
    21. <view class="section bottom-line">
    22. <text>到底啦</text>
    23. </view>

    4. 样式

    在投票页面的 .wxss 文件( 如: vote/list/list.wxss)中进行美化效果 :

    1. .list {
    2. display: flex;
    3. flex-direction: row;
    4. width: 100%;
    5. padding: 0 20rpx 0 0;
    6. border-top: 1px solid #eeeeee;
    7. background-color: #fff;
    8. margin-bottom: 5rpx;
    9. height: 270rpx;
    10. /* border-radius: 20rpx;
    11. box-shadow: 0px 0px 10px 6px rgba(0,0,0,0.1); */
    12. }
    13. .list-img {
    14. display: flex;
    15. margin: 10rpx 10rpx;
    16. width: 160rpx;
    17. height: 250rpx;
    18. justify-content: center;
    19. align-items: center;
    20. flex-direction:column;
    21. }
    22. .list-img .video-img {
    23. width: 140rpx;
    24. height: 160rpx;
    25. border-radius: 6px;
    26. }
    27. .list-detail {
    28. margin: 10rpx 10rpx;
    29. display: flex;
    30. flex-direction: column;
    31. width: 600rpx;
    32. height: 300rpx;
    33. }
    34. .list-title text {
    35. font-size: 9pt;
    36. color: #333;
    37. font-weight: bold;
    38. }
    39. .list-detail {
    40. display: flex;
    41. height: 100rpx;
    42. }
    43. .list-tag{
    44. display: flex;
    45. }
    46. .state {
    47. font-size: 9pt;
    48. color: #81aaf7;
    49. width: 120rpx;
    50. height: 40rpx;
    51. border: 1px solid #93b9ff;
    52. border-radius: 2px;
    53. margin: 10rpx 0rpx;
    54. display: flex;
    55. justify-content: center;
    56. align-items: center;
    57. }
    58. .join {
    59. font-size: 11pt;
    60. color: #bbb;
    61. margin-left: 20rpx;
    62. display: flex;
    63. justify-content: center;
    64. align-items: center;
    65. }
    66. .list-num {
    67. margin-right: 10rpx;
    68. font-size: 11pt;
    69. color: #ff6666;
    70. }
    71. .list-info {
    72. font-size: 9pt;
    73. color: #bbb;
    74. }
    75. .bottom-line{
    76. display: flex;
    77. height: 60rpx;
    78. justify-content: center;
    79. align-items: center;
    80. background-color: #f3f3f3;
    81. }
    82. .bottom-line text{
    83. font-size: 9pt;
    84. color: #666;
    85. }

    效果展示: 

  • 相关阅读:
    8.gec6818开发板通过并发多线程实现电子相册 智能家居 小游戏三合一完整项目
    Ae:内容识别填充面板
    搬砖日记:关于sync用不了的问题
    sora会是AGI的拐点么?
    Docker 实现 MySQL 一主一从配置
    Python学习之CSDN21天学习挑战赛计划之3
    查看Android App包名,查看keystore的信息,导出公钥
    Docker概述
    音频信号分析与实践
    JVM:区域划分和垃圾回收
  • 原文地址:https://blog.csdn.net/2301_76988707/article/details/133902605