• 微信小程序会议OA系统其他页面


    前言:

    及上一文章:https://blog.csdn.net/djssubddbj/article/details/133895170?spm=1001.2014.3001.5501我们所写的会议OA的首页,在这个上面我们继续完成我们的会议OA系统,这是我们的本期所要完成的页面

    自定义组件

    微信小程序自定义组件是指开发者可以将一些功能和样式封装成独立的组件,然后在不同的页面中使用这些组件,从而提高开发效率和代码复用性。自定义组件可以包含模板、样式和行为逻辑,可以由开发者自主定义组件的属性和事件,使得组件更加灵活、可定制化。

    自定义组件的使用方式类似于小程序原生组件,可以通过标签名引用,也可以通过自定义属性传递参数和设置组件状态。自定义组件还支持向外暴露属性、方法和事件,方便开发者在使用组件时进行交互和控制。

    易于维护和扩展:自定义组件具备良好的封装性,内部的实现细节对外部是隐藏的,这样可以避免代码耦合和冲突。当需要修改或扩展某个功能时,只需要修改自定义组件的代码,而不会影响其他部分。

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

    {
      "component": true
    }

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

    自定义组件开发需要使用小程序提供的Component构造器,通过编写wxml、wxss和js文件来定义组件的结构、样式和行为逻辑。在编写组件时,需要考虑组件的可复用性和可定制化,同时也需要注意组件的兼容性和性能问题。

    我们的微信小程序需要创建自定义组件的原因有以下几个:

    1. 提高开发效率和代码复用性:自定义组件可以将一些常用的功能和样式封装成独立的组件,方便在不同的页面中进行调用,从而减少代码的重复编写,提高开发效率和代码复用性。

    2. 实现组件化开发:自定义组件可以将一个页面拆分成多个独立的组件,每个组件都有自己的结构、样式和行为逻辑,从而实现组件化开发,方便团队协作,提高代码的可维护性和可拓展性。

    3. 实现定制化需求:自定义组件可以根据不同的需求进行定制化开发,自由定义组件的属性、方法和事件,使得组件更加灵活、可定制化。

    4. 提高用户体验:自定义组件可以使得小程序的界面更加丰富和生动,提高用户的体验和满意度。

     在新的版本里面我们会出现报错,但是在win7的一些旧版本里面是不会出现这些问题的,我们需要在project.config.json文件里面添加以下代码:

    "ignoreDevUnusedFiles": false,
    "ignoreUploadUnusedFiles": false,

    综上,创建自定义组件是微信小程序开发中的常见需求和实践,对于提高开发效率和代码质量、提高用户体验等方面都具有重要的意义。

    代码案例

    会议代码:
    list.wxml
    1. <!--pages/meeting/list/list.wxml-->
    2. <!-- <text>pages/meeting/list/list.wxml</text> -->
    3. <tabs tabList="{{tabs}}" bindtabsItemChange="tabsItemChange">
    4. </tabs>
    5. <view style="height: 100rpx;"></view>
    6. <block wx:for-items="{{lists}}" wx:for-item="item" wx:key="item.id">
    7. <view class="list" data-id="{{item.id}}">
    8. <view class="list-img al-center">
    9. <image class="video-img" mode="scaleToFill" src="{{item.image}}"></image>
    10. </view>
    11. <view class="list-detail">
    12. <view class="list-title"><text>{{item.title}}</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>
    list.wxss 
    1. /* pages/meeting/list/list.wxss */
    2. page{
    3. height: 100%;
    4. background-color:#efeff4;
    5. }
    6. .swiper-item {
    7. height: 350rpx;
    8. width: 100%;
    9. border-radius: 10rpx;
    10. }
    11. .mobi-title{
    12. font-size: 18px;
    13. margin: 10rpx;
    14. }
    15. .mobi-icon{
    16. margin:0 0 200px 0 ;
    17. background-color: red;
    18. padding: 3rpx;
    19. }
    20. .mobi-title text{
    21. margin-left: 10rpx;
    22. }
    23. .list{
    24. background-color: #fff;
    25. display: flex;
    26. margin:10rpx;
    27. padding:10rpx;
    28. }
    29. .list-img,.video-img{
    30. height: 150rpx;
    31. width: 150rpx;
    32. }
    33. .list-img{
    34. margin:30rpx 0 0 0 ;
    35. }
    36. .list-detail{
    37. margin:0 0 0 10rpx;
    38. }
    39. .list-title{
    40. font-weight: 700;
    41. }
    42. .list-tag{
    43. display: flex;
    44. margin: 10px 0 ;
    45. }
    46. .state{
    47. border: 3px solid lightblue;
    48. padding: 2px;
    49. color: lightblue;
    50. }
    51. .join{
    52. border: 3px solid #fff;
    53. padding: 2px;
    54. margin: 0 0 0 20rpx;
    55. color:gray;
    56. }
    57. .list-num{
    58. color: red;
    59. }
    60. .list-info{
    61. color:gray;
    62. }
    63. .bottom-line{
    64. text-align: center;
    65. margin-bottom: 10px;
    66. }
    list.json 
    1. {
    2. "usingComponents": {
    3. "tabs": "/components/tabs/tabs"
    4. }
    5. }
     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/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. onReady() {
    161. },
    162. /**
    163. * 生命周期函数--监听页面显示
    164. */
    165. onShow() {
    166. },
    167. /**
    168. * 生命周期函数--监听页面隐藏
    169. */
    170. onHide() {
    171. },
    172. /**
    173. * 生命周期函数--监听页面卸载
    174. */
    175. onUnload() {
    176. },
    177. /**
    178. * 页面相关事件处理函数--监听用户下拉动作
    179. */
    180. onPullDownRefresh() {
    181. },
    182. /**
    183. * 页面上拉触底事件的处理函数
    184. */
    185. onReachBottom() {
    186. },
    187. /**
    188. * 用户点击右上角分享
    189. */
    190. onShareAppMessage() {
    191. },
    192. tabsItemChange(e){
    193. // debugger
    194. let tolists;
    195. if(e.detail.index==1){
    196. tolists = this.data.lists1;
    197. }else if(e.detail.index==2){
    198. tolists = this.data.lists2;
    199. }else{
    200. tolists = this.data.lists3;
    201. }
    202. this.setData({
    203. lists: tolists
    204. })
    205. }
    206. })

     

     设置代码

    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. <view class="userInfo">
    6. <image class="user-head" src="/static/images/avatar.png"></image>
    7. <text class="user-name">立即登录</text>
    8. <text class="user-edit">修改</text>
    9. </view>
    10. <view class="list">
    11. <view class="list-item">
    12. <image class="item-icon" src="/static/tabBar/sdk.png"></image>
    13. <text class="item-title">我主持的会议</text>
    14. <text space="nbsp" class="item-num">1 </text>
    15. <text class="item-detail"></text>
    16. </view>
    17. <view class="hr"></view>
    18. <view class="list-item">
    19. <image class="item-icon" src="/static/tabBar/sdk.png"></image>
    20. <text class="item-title">我参与的会议</text>
    21. <text class="item-num">10</text>
    22. <text class="item-detail"></text>
    23. </view>
    24. </view>
    25. <view class="list">
    26. <view class="list-item">
    27. <image class="item-icon" src="/static/tabBar/sdk.png"></image>
    28. <text class="item-title">我发布的投票</text>
    29. <text space="nbsp" class="item-num">1 </text>
    30. <text class="item-detail"></text>
    31. </view>
    32. <view class="hr"></view>
    33. <view class="list-item">
    34. <image class="item-icon" src="/static/tabBar/sdk.png"></image>
    35. <text class="item-title">我参与的投票</text>
    36. <text class="item-num">10</text>
    37. <text class="item-detail"></text>
    38. </view>
    39. </view>
    40. <view class="list">
    41. <view class="list-item">
    42. <image class="item-icon" src="/static/tabBar/sdk.png"></image>
    43. <text class="item-title">消息</text>
    44. <text class="item-num"></text>
    45. <text space="nbsp" class="item-detail"></text>
    46. </view>
    47. <view class="hr"></view>
    48. <view class="list-item">
    49. <image class="item-icon" src="/static/tabBar/sdk.png"></image>
    50. <text class="item-title">设置</text>
    51. <text space="emsp" class="item-num"></text>
    52. <text space="nbsp" class="item-detail"></text>
    53. </view>
    54. </view>
    index.wxss 
    1. /* pages/ucenter/index/index.wxss */
    2. /* pages/ucenter/index/index.wxss */
    3. Page{
    4. background-color: #fff;
    5. }
    6. .userInfo{
    7. display: flex;
    8. background-color: antiquewhite;
    9. border: 1px solid red;
    10. padding: 20rpx;
    11. }
    12. .user-head{
    13. width: 150rpx;
    14. height: 150rpx;
    15. }
    16. .user-name,.user-edit{
    17. display: flex;
    18. align-items: center;
    19. margin: 0 0 0 20rpx;
    20. }
    21. .user-name{
    22. /* display: inline-block; */
    23. width: 450rpx;
    24. font-weight: 700;
    25. }
    26. .user-edit{
    27. color: gray;
    28. }
    29. .list{
    30. height: 280rpx;
    31. width: 750rpx;
    32. display: flex;
    33. flex-direction: column;
    34. }
    35. .list-item{
    36. height: 130rpx;
    37. }
    38. .item-icon{
    39. height: 60rpx;
    40. width: 60rpx;
    41. margin-top: 20px;
    42. /* border: 1px solid red; */
    43. }
    44. .item-title,.item-num,.item-detail{
    45. /* border: 1px solid red; */
    46. position: relative;
    47. top:-10px;
    48. display: inline-block;
    49. }
    50. .item-title{
    51. font-size: 18px;
    52. width: 520rpx;
    53. height: 25px;
    54. margin-left: 10px;
    55. }
    56. .item-num{
    57. margin-right: 10px;
    58. }
    59. .item-detail{
    60. color: gray;
    61. }
    62. .list .hr{
    63. background-color: lightgray;
    64. height: 1px;
    65. width: 400px;
    66. display: inline-block;
    67. }

  • 相关阅读:
    巧妙实现防止按钮重复点击
    LM-INFINITE: SIMPLE ON-THE-FLY LENGTH GENERALIZATION FOR LARGE LANGUAGE MODELS
    作业帮 x TiDB丨多元化海量数据业务的支撑
    Flutter中的“迷你计算器”带有源代码
    简单的聊一聊Vue中如何使用 Ref 和 Reactive 声明响应式数据
    CSS3与HTML5
    OSPF高级配置
    Lodash常用方法介绍
    【干活分享-年薪百万以上】Java高端人才应具备的能力
    非支配排序遗传算法NSGA
  • 原文地址:https://blog.csdn.net/djssubddbj/article/details/133937558