• 微信小程序开发的OA会议之会议,个人中心的页面搭建及模板以及自定义组件


    目录

    自定义组件

    是什么

    创建

    定义

    编写

    使用

    会议

    数据

     显示

    样式

     效果展示

    个人中心

     页面

    样式

    效果展示


    自定义组件

    是什么

    自定义组件允许开发者将页面中的一部分代码封装成一个可重用的组件,方便在不同的页面中复用。自定义组件可以使用自己的WXML模板、WXSS样式和JS逻辑,实现更加清晰的代码分离和组件化开发。

    创建

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

    定义

    自定义组件的目录结构类似于页面的结构,但组件和页面是有区别的,组件没有自己的生命周期和Page实例,它是由页面进行引用和使用的。 

     在 tabs.json 中编写

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

    编写

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

    使用

    在项目的 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>

    会议

    数据

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

    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/16.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/15.gif',
    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/14.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/13.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/8.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/7.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/15.gif',
    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/14.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/16.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/15.gif',
    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/8.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/7.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/13.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/14.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/15.gif',
    144. 'title': '新质生活 · 品质时代 2016消费升级创新大会',
    145. 'num':'217',
    146. 'state':'进行中',
    147. 'time': '10月09日 16:59',
    148. 'address': '北京市·朝阳区'
    149. }
    150. ]
    151. },
    152. tabsItemChange(e){
    153. let tolists;
    154. if(e.detail.index==1){
    155. tolists = this.data.lists1;
    156. }else if(e.detail.index==2){
    157. tolists = this.data.lists2;
    158. }else{
    159. tolists = this.data.lists3;
    160. }
    161. this.setData({
    162. lists: tolists
    163. })
    164. },
    165. /**
    166. * 生命周期函数--监听页面加载
    167. */
    168. onLoad(options) {
    169. },
    170. /**
    171. * 生命周期函数--监听页面初次渲染完成
    172. */
    173. onReady() {
    174. },
    175. /**
    176. * 生命周期函数--监听页面显示
    177. */
    178. onShow() {
    179. },
    180. /**
    181. * 生命周期函数--监听页面隐藏
    182. */
    183. onHide() {
    184. },
    185. /**
    186. * 生命周期函数--监听页面卸载
    187. */
    188. onUnload() {
    189. },
    190. /**
    191. * 页面相关事件处理函数--监听用户下拉动作
    192. */
    193. onPullDownRefresh() {
    194. },
    195. /**
    196. * 页面上拉触底事件的处理函数
    197. */
    198. onReachBottom() {
    199. },
    200. /**
    201. * 用户点击右上角分享
    202. */
    203. onShareAppMessage() {
    204. }
    205. })

     显示

     在会议的 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>

    样式

    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. }

     效果展示

    个人中心

     页面

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

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

    样式

    在个人中心的 .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. }

    效果展示

    okok,今天就到这里了,下班下班!!!!!!!!!!!!!!! 

  • 相关阅读:
    高性能MySQL实战开篇寄语:建立完整的MySQL知识体系
    内衣洗衣机什么牌子好又便宜?实力非凡机型深度测评
    链表经典面试题(四)
    MVCC版本并发控制、bufferpool缓存机制
    12.cuBLAS开发指南中文版--cuBLAS中的Level-1函数asum()和axpy()
    WPF中使用WinForm Chart控件(1)----实时曲线
    Jaya算法在电力系统最优潮流计算中的应用(创新点)【Matlab代码实现】
    「实用场景教程」如何用日程控件DHTMLX Scheduler制作酒店预订日历?(一)
    【Netty】TCP拆包黏包问题讲解_基础概念介绍
    管理者的三抓三放
  • 原文地址:https://blog.csdn.net/m0_74934282/article/details/133936149