• 通过小程序实现会议Oa的会议展示以及个人中心


          🏅我是默,一个在CSDN分享笔记的博主。📚📚

    🌟在这里,我要推荐给大家我的专栏《微信小程序 》。🎯🎯

    🚀无论你是编程小白,还是有一定基础的程序员,这个专栏都能满足你的需求。我会用最简单易懂的语言,带你走进代码的世界,让你从零开始,一步步成为编程大师。🚀🏆

    🌈让我们在代码的世界里畅游吧!🌈

    🎁如果感觉还不错的话请记得给我点赞哦!🎁🎁

    💖期待你的加入,一起学习,一起进步💖💖 

    一.自定义组件

    1.关于自定义组件的介绍

    小程序基础库版本 1.6.3 开始,小程序支持简洁的组件化编程。所有自定义组件相关特性都需要基础库版本 1.6.3 或更高。

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

    2.自定义组件的实例展示

    2.1实现思路

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

    1. {
    2. "component": true
    3. }

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

    代码示例:
    1. <view class="inner">
    2. {{innerText}}
    3. view>
    4. <slot>slot>
    1. /* 这里的样式只应用于这个自定义组件 */
    2. .inner {
    3. color: red;
    4. }

    注意:在组件wxss中不应使用ID选择器、属性选择器和标签名选择器。

    在自定义组件的 js 文件中,需要使用 Component() 来注册组件,并提供组件的属性定义、内部数据和自定义方法。

    组件的属性值和内部数据将被用于组件 wxml 的渲染,其中,属性值是可由组件外部传入的。更多细节参见 Component构造器 。

    代码示例:

    1. Component({
    2. properties: {
    3. // 这里定义了innerText属性,属性值可以在组件使用时指定
    4. innerText: {
    5. type: String,
    6. value: 'default value',
    7. }
    8. },
    9. data: {
    10. // 这里是一些组件内部数据
    11. someData: {}
    12. },
    13. methods: {
    14. // 这里是一个自定义方法
    15. customMethod: function(){}
    16. }
    17. })
    使用自定义组件

    使用已注册的自定义组件前,首先要在页面的 json 文件中进行引用声明。此时需要提供每个自定义组件的标签名和对应的自定义组件文件路径:

    1. {
    2. "usingComponents": {
    3. "component-tag-name": "path/to/the/custom/component"
    4. }
    5. }

    这样,在页面的 wxml 中就可以像使用基础组件一样使用自定义组件。节点名即自定义组件的标签名,节点属性即传递给组件的属性值。

    开发者工具 1.02.1810190 及以上版本支持在 app.json 中声明 usingComponents 字段,在此处声明的自定义组件视为全局自定义组件,在小程序内的页面或自定义组件中可以直接使用而无需再声明。

    代码示例:

    在开发者工具中预览效果

    1. <component-tag-name inner-text="Some text">component-tag-name>

    自定义组件的 wxml 节点结构在与数据结合之后,将被插入到引用位置内。

    注意事项

    一些需要注意的细节:

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

    注意,是否在页面文件中使用 usingComponents 会使得页面的 this 对象的原型稍有差异,包括:

    • 使用 usingComponents 页面的原型与不使用时不一致,即 Object.getPrototypeOf(this) 结果不同。
    • 使用 usingComponents 时会多一些方法,如 selectComponent 。
    • 出于性能考虑,使用 usingComponents 时, setData 内容不会被直接深复制,即 this.setData({ field: obj }) 后 this.data.field === obj 。(深复制会在这个值被组件间传递时发生。)

    如果页面比较复杂,新增或删除 usingComponents 定义段时建议重新测试一下。

    2.2自定义组件具体实现

    新建文件夹

     在创建成功后会出现一个错误提示,和解决办法

    定义组件
    1. 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>
    设置样式
    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. var App = getApp();
    2. Component({
    3. /**
    4. * 组件的属性列表
    5. */
    6. properties: {
    7. tabList:Object
    8. },
    9. /**
    10. * 组件的初始数据
    11. */
    12. data: {
    13. tabIndex:0
    14. },
    15. /**
    16. * 组件的方法列表
    17. */
    18. methods: {
    19. handleItemTap(e){
    20. // 获取索引
    21. const {index} = e.currentTarget.dataset;
    22. // 触发 父组件的事件
    23. this.triggerEvent("tabsItemChange",{index})
    24. this.setData({
    25. tabIndex:index
    26. })
    27. }
    28. }
    29. })
    导入自定义组件
    1. {
    2. "usingComponents": {
    3. "tabs": "/components/tabs/tabs"
    4. }
    5. }
    模拟数据
    1. data: {
    2. tabs:['会议中','已完成','已取消','全部会议'],
    3. },
    界面线束
    1. "{{tabs}}" bindtabsItemChange="tabsItemChange">
    效果展示

    二.会议界面和个人中心界面

    1.会议界面

    在list.js中定义数据

    1. lists: [
    2. {
    3. 'id': '1',
    4. 'image': '/static/persons/1.jpg',
    5. 'title': '对话产品总监 | 深圳·北京PM大会 【深度对话小米/京东/等产品总监】',
    6. 'num':'304',
    7. 'state':'进行中',
    8. 'time': '10月09日 17:59',
    9. 'address': '深圳市·南山区'
    10. },
    11. {
    12. 'id': '1',
    13. 'image': '/static/persons/2.jpg',
    14. 'title': 'AI WORLD 2016世界人工智能大会',
    15. 'num':'380',
    16. 'state':'已结束',
    17. 'time': '10月09日 17:39',
    18. 'address': '北京市·朝阳区'
    19. },
    20. {
    21. 'id': '1',
    22. 'image': '/static/persons/3.jpg',
    23. 'title': 'H100太空商业大会',
    24. 'num':'500',
    25. 'state':'进行中',
    26. 'time': '10月09日 17:31',
    27. 'address': '大连市'
    28. },
    29. {
    30. 'id': '1',
    31. 'image': '/static/persons/4.jpg',
    32. 'title': '报名年度盛事,大咖云集!2016凤凰国际论坛邀您“与世界对话”',
    33. 'num':'150',
    34. 'state':'已结束',
    35. 'time': '10月09日 17:21',
    36. 'address': '北京市·朝阳区'
    37. },
    38. {
    39. 'id': '1',
    40. 'image': '/static/persons/5.jpg',
    41. 'title': '新质生活 · 品质时代 2016消费升级创新大会',
    42. 'num':'217',
    43. 'state':'进行中',
    44. 'time': '10月09日 16:59',
    45. 'address': '北京市·朝阳区'
    46. }
    47. ],
    48. lists1: [
    49. {
    50. 'id': '1',
    51. 'image': '/static/persons/1.jpg',
    52. 'title': '对话产品总监 | 深圳·北京PM大会 【深度对话小米/京东/等产品总监】',
    53. 'num':'304',
    54. 'state':'进行中',
    55. 'time': '10月09日 17:59',
    56. 'address': '深圳市·南山区'
    57. },
    58. {
    59. 'id': '1',
    60. 'image': '/static/persons/2.jpg',
    61. 'title': 'AI WORLD 2016世界人工智能大会',
    62. 'num':'380',
    63. 'state':'已结束',
    64. 'time': '10月09日 17:39',
    65. 'address': '北京市·朝阳区'
    66. },
    67. {
    68. 'id': '1',
    69. 'image': '/static/persons/3.jpg',
    70. 'title': 'H100太空商业大会',
    71. 'num':'500',
    72. 'state':'进行中',
    73. 'time': '10月09日 17:31',
    74. 'address': '大连市'
    75. }
    76. ],
    77. lists2: [
    78. {
    79. 'id': '1',
    80. 'image': '/static/persons/1.jpg',
    81. 'title': '对话产品总监 | 深圳·北京PM大会 【深度对话小米/京东/等产品总监】',
    82. 'num':'304',
    83. 'state':'进行中',
    84. 'time': '10月09日 17:59',
    85. 'address': '深圳市·南山区'
    86. },
    87. {
    88. 'id': '1',
    89. 'image': '/static/persons/2.jpg',
    90. 'title': 'AI WORLD 2016世界人工智能大会',
    91. 'num':'380',
    92. 'state':'已结束',
    93. 'time': '10月09日 17:39',
    94. 'address': '北京市·朝阳区'
    95. }
    96. ],
    97. lists3: [
    98. {
    99. 'id': '1',
    100. 'image': '/static/persons/1.jpg',
    101. 'title': '对话产品总监 | 深圳·北京PM大会 【深度对话小米/京东/等产品总监】',
    102. 'num':'304',
    103. 'state':'进行中',
    104. 'time': '10月09日 17:59',
    105. 'address': '深圳市·南山区'
    106. },
    107. {
    108. 'id': '1',
    109. 'image': '/static/persons/2.jpg',
    110. 'title': 'AI WORLD 2016世界人工智能大会',
    111. 'num':'380',
    112. 'state':'已结束',
    113. 'time': '10月09日 17:39',
    114. 'address': '北京市·朝阳区'
    115. },
    116. {
    117. 'id': '1',
    118. 'image': '/static/persons/3.jpg',
    119. 'title': 'H100太空商业大会',
    120. 'num':'500',
    121. 'state':'进行中',
    122. 'time': '10月09日 17:31',
    123. 'address': '大连市'
    124. },
    125. {
    126. 'id': '1',
    127. 'image': '/static/persons/4.jpg',
    128. 'title': '报名年度盛事,大咖云集!2016凤凰国际论坛邀您“与世界对话”',
    129. 'num':'150',
    130. 'state':'已结束',
    131. 'time': '10月09日 17:21',
    132. 'address': '北京市·朝阳区'
    133. },
    134. {
    135. 'id': '1',
    136. 'image': '/static/persons/5.jpg',
    137. 'title': '新质生活 · 品质时代 2016消费升级创新大会',
    138. 'num':'217',
    139. 'state':'进行中',
    140. 'time': '10月09日 16:59',
    141. 'address': '北京市·朝阳区'
    142. }
    143. ]

    定义一个方法用于菜单的切换

    1. tabsItemChange(e){
    2. let tolists;
    3. if(e.detail.index==1){
    4. tolists = this.data.lists1;
    5. }else if(e.detail.index==2){
    6. tolists = this.data.lists2;
    7. }else{
    8. tolists = this.data.lists3;
    9. }
    10. this.setData({
    11. lists: tolists
    12. })
    13. },

    加载数据和样式

    1. wx:for-items="{{lists}}" wx:for-item="item" wx:key="item.id">
    2. <view class="list" data-id="{{item.id}}">
    3. <view class="list-img">
    4. <image class="video-img" mode="scaleToFill" src="{{item.image}}">image>
    5. view>
    6. <view class="list-detail">
    7. <view class="list-title"><text>{{item.title}}text>view>
    8. <view class="list-tag">
    9. <view class="state">{{item.state}}view>
    10. <view class="join"><text class="list-num">{{item.num}}text>人报名view>
    11. view>
    12. <view class="list-info"><text>{{item.address}}text>|<text>{{item.time}}text>view>
    13. view>
    14. view>
    1. /* pages/meeting/list/list.wxss */
    2. /**index.wxss**/
    3. .section{
    4. color: #aaa;
    5. display: flex;
    6. justify-content: center;
    7. }
    8. .list-info {
    9. color: #aaa;
    10. font-size: 10px;
    11. }
    12. .list-num {
    13. color: #e40909;
    14. font-weight: 700;
    15. }
    16. .join {
    17. padding: 0px 0px 0px 10px;
    18. color: #aaa;
    19. }
    20. .state {
    21. margin: 0px 6px 4px 0px;
    22. border: 1px solid #93b9ff;
    23. color: #93b9ff;
    24. }
    25. .list-tag {
    26. padding: 3px 0px 10px 0px;
    27. display: flex;
    28. align-items: center;
    29. }
    30. .list-title {
    31. display: flex;
    32. justify-content: space-between;
    33. font-size: 11pt;
    34. color: #333;
    35. font-weight: bold;
    36. }
    37. .list-detail {
    38. display: flex;
    39. flex-direction: column;
    40. margin: 0px 0px 0px 15px;
    41. }
    42. .video-img {
    43. width: 80px;
    44. height: 80px;
    45. display: flex;
    46. }
    47. .list {
    48. display: flex;
    49. flex-direction: row;
    50. border-bottom: 4px solid #6b6e74;
    51. padding: 10px;
    52. align-items: center;
    53. }
    54. .mobi-text {
    55. font-weight: 700;
    56. padding: 15px;
    57. }
    58. .mobi-icon {
    59. border-left: 5px solid #e40909;
    60. }
    61. .mobi-title {
    62. background-color: rgba(158, 158, 142, 0.678);
    63. margin: 10px 0px 10px 0px;
    64. }
    65. .swiper-item {
    66. height: 300rpx;
    67. width: 100%;
    68. border-radius: 10rpx;
    69. }
    70. .userinfo {
    71. display: flex;
    72. flex-direction: column;
    73. align-items: center;
    74. color: #aaa;
    75. }
    76. .userinfo-avatar {
    77. overflow: hidden;
    78. width: 128rpx;
    79. height: 128rpx;
    80. margin: 20rpx;
    81. border-radius: 50%;
    82. }
    83. .usermotto {
    84. margin-top: 200px;
    85. }

    效果展示

    2.个人中心界面

    wxml文件

    1. <view class="userInfo">
    2. <image class="userInfo-head" src="/static/persons/1.jpg">image>
    3. <view class="userInfo-login">刘兵瞎子view>
    4. <text class="userInfo-set">修改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. <view class="cell-items-num">3view>
    11. <text class="cell-items-detail">text>
    12. view>
    13. <hr />
    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. <view class="cell-items-num">4view>
    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/coding.png" class="cell-items-icon">image>
    24. <text class="cell-items-title">投票的会议text>
    25. <view class="cell-items-num">10view>
    26. <text class="cell-items-detail">text>
    27. view>
    28. <hr />
    29. <view class="cell-items">
    30. <image src="/static/tabBar/coding.png" class="cell-items-icon">image>
    31. <text class="cell-items-title">未投票的会议text>
    32. <view class="cell-items-num">6view>
    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/template.png" class="cell-items-icon">image>
    39. <text class="cell-items-title">我参与的会议text>
    40. <view class="cell-items-num">11view>
    41. <text class="cell-items-detail">text>
    42. view>
    43. <hr />
    44. <view class="cell-items">
    45. <image src="/static/tabBar/template.png" class="cell-items-icon">image>
    46. <text class="cell-items-title">我审核的会议text>
    47. <view class="cell-items-num">4view>
    48. <text class="cell-items-detail">text>
    49. view>
    50. view>
    51. <view class="cells">
    52. <view class="cell-items">
    53. <image src="/static/tabBar/coding.png" class="cell-items-icon">image>
    54. <text class="cell-items-title">消息text>
    55. view>
    56. <hr />
    57. <view class="cell-items">
    58. <image src="/static/tabBar/component.png" class="cell-items-icon">image>
    59. <text class="cell-items-title">设置text>
    60. view>
    61. view>

    wxss文件

    1. /* pages/ucenter/index/index.wxss */
    2. .userInfo{
    3. padding: 5px 0px 20px 10px;
    4. display: flex;
    5. align-items: center;
    6. }
    7. .userInfo-head{
    8. height: 80px;
    9. width: 80px;
    10. }
    11. .userInfo-login{
    12. width: 245px;
    13. padding-left: 10px;
    14. font-weight: 700;
    15. }
    16. .userInfo-set{
    17. color: rgb(146, 151, 155);
    18. }
    19. .cells{
    20. border-top: 8px solid rgb(238, 238, 238);
    21. }
    22. .cell-items{
    23. display: flex;
    24. align-items: center;
    25. border-top: 1px solid rgb(238, 238, 238);
    26. padding-top: 20px;
    27. padding-bottom: 20px;
    28. }
    29. .cell-items-icon{
    30. height: 25px;
    31. width: 25px;
    32. padding: 0px 10px 0px 5px;
    33. }
    34. .cell-items-title{
    35. width: 340px;
    36. }
    37. .cell-items-num{
    38. width: 30px;
    39. font-weight: 700;
    40. color: rgb(218, 31, 31);
    41. }
    42. .cell-items-detail{
    43. color: rgb(146, 151, 155);
    44. }

    效果展示

  • 相关阅读:
    大龄测试/开发程序员该怎样延长职业寿命?活在未来,终身学习......
    【unity3D】Rect Transform组件
    C和指针 第13章 高级指针话题 13.2 高级声明
    MySQL 练习<3>
    MySQL安全性策略:用户认证与数据加密
    【FreeRTOS】两个Delay函数
    完整、免费的把pdf转word文档
    httpx.HTTPStatusError: Client error ‘429 Too Many Requests‘ for url ‘
    元宇宙006 | 你不了解的“养成系”人工智能就此诞生
    十三届蓝桥杯Java国一与C++国一带你刷题(暑期刷题夏令营开启)
  • 原文地址:https://blog.csdn.net/lz17267861157/article/details/133902540