• 小程序之实例会议OA的首页 (3)


                                           ⭐⭐ 小程序专栏:小程序开发专栏

                                            ⭐⭐ 个人主页个人主页


    目录

    ​编辑

    一.前言

    二.flex弹性布局

    flex属性

    2.1 display: flex 弹性布局属性

    2.2  flex-direction属性

    2.3 flex-wrap属性

    2.4 flex-flow属性

    2.5 justify-content属性

    三.首页轮播图

    3.2 mockJS模拟数据

    四.OA首页的布局


    一.前言

    今天终于进入正轨了,正式使用小程序制作一款App,本专栏以会议OA为示例进行讲解。本文章首先来实现OA的首页

    二.flex弹性布局

            学习地址:
    Flex 布局语法教程 | 菜鸟教程网页布局(layout)是CSS的一个重点应用。 布局的传统解决方案,基于盒状模型,依赖 display属性 + position属性 + float属性。它对于那些特殊布局非常不方便,比如,垂直居中就不容易实现。 2009年,W3C提出了一种新的方案—-Flex布局,可以简便、完整、响应式地实现各种页面布局。目前,它已经得到了所有浏览器的支持,这意味着,现在就能很安全地使用这项功能。 Flex布局将成为未来布..icon-default.png?t=N7T8http://www.runoob.com/w3cnote/flex-grammar.html         Flex是Flexible Box的缩写,意为”弹性布局”,用来为盒状模型提供最大的灵活性。

    flex属性

    • flex-direction 主轴的方向 默认为row

    • flex-wrap 如果一条轴线排不下,如何换行

    • flex-flow 是flex-direction属性和flex-wrap属性的简写形式

    • justify-content 定义了项目在主轴上的对齐方式

    • align-items 定义项目在交叉轴上如何对齐

    • align-content 属性定义了多根轴线的对齐方式

    注意,设为Flex布局以后,子元素的float、clear和vertical-align属性将失效。

    2.1 display: flex 弹性布局属性

    前端代码:

    1. <view class="box">
    2. <view>1</view>
    3. <view>2</view>
    4. <view>3</view>
    5. <view>4</view>
    6. <view>5</view>
    7. <view>6</view>
    8. <view>7</view>
    9. <view>8</view>
    10. <view>9</view>
    11. <view>10</view>
    12. <view>11</view>
    13. <view>12</view>
    14. </view>

    样式添加:

            给每一个view设置了宽高为100rpx,众所周知小程序的手机端的宽度是750rpx

    1. .box{
    2. height: 750rpx;
    3. width: 750rpx;
    4. background-color: pink;
    5. display: flex;
    6. }
    7. view{
    8. height: 100rpx;
    9. width: 100rpx;
    10. border: 1px solid greenyellow;
    11. }

    添加display: flex之前与之后的对比:

    2.2  flex-direction属性

    flex-direction属性决定主轴的方向(即项目的排列方向)。

     flex-direction: row | row-reverse | column | column-reverse;
    

    2.3 flex-wrap属性

    默认情况下,项目都排在一条线(又称”轴线”)上。flex-wrap属性定义,如果一条轴线排不下,如何换行。

     flex-wrap: nowrap (不换行) | wrap | wrap-reverse;

     

    2.4 flex-flow属性

    flex-flow属性是flex-direction属性和flex-wrap属性的简写形式,就是将两者结合起来了,默认值为row nowrap。

    2.5 justify-content属性

      justify-content: flex-start(居右对齐) | flex-end(居左对齐) | center(居中对齐) | space-between(两端对齐,项目之间的间隔都相等) | space-around(每个项目两侧的间隔相等。所以,项目之间的间隔比项目与边框的间隔大一倍。)
    

    三.首页轮播图

         3.1   我们先把一级菜单底座打好

    在app.json里面:

    1. "pages":[
    2. "pages/index/index",
    3. "pages/meeting/list/list",
    4. "pages/vote/list/list",
    5. "pages/ucenter/index/index",
    6. "pages/logs/logs"
    7. ],
    1. "tabBar": {
    2. "list": [{
    3. "pagePath": "pages/index/index",
    4. "text": "首页",
    5. "iconPath": "/static/tabBar/coding.png",
    6. "selectedIconPath": "/static/tabBar/coding-active.png"
    7. },
    8. {
    9. "pagePath": "pages/meeting/list/list",
    10. "iconPath": "/static/tabBar/sdk.png",
    11. "selectedIconPath": "/static/tabBar/sdk-active.png",
    12. "text": "会议"
    13. },
    14. {
    15. "pagePath": "pages/vote/list/list",
    16. "iconPath": "/static/tabBar/template.png",
    17. "selectedIconPath": "/static/tabBar/template-active.png",
    18. "text": "投票"
    19. },
    20. {
    21. "pagePath": "pages/ucenter/index/index",
    22. "iconPath": "/static/tabBar/component.png",
    23. "selectedIconPath": "/static/tabBar/component-active.png",
    24. "text": "设置"
    25. }]
    26. },

    3.2 mockJS模拟数据

    定义接口:

    右击新建立一个文件夹:

    在app.js里面定义接口 :

    1. // 以下是业务服务器API地址
    2. // 本机开发API地址
    3. var WxApiRoot = 'http://localhost:8080/demo/wx/';
    4. // 测试环境部署api地址
    5. // var WxApiRoot = 'http://192.168.0.101:8070/demo/wx/';
    6. // 线上平台api地址
    7. //var WxApiRoot = 'https://www.oa-mini.com/demo/wx/';
    8. module.exports = {
    9. IndexUrl: WxApiRoot + 'home/index', //首页数据接口
    10. SwiperImgs: WxApiRoot+'swiperImgs', //轮播图
    11. MettingInfos: WxApiRoot+'meeting/list', //会议信息
    12. };

    前端轮播图代码:index.wxml

    这段代码是从官网拿的,里面的属性官网中可以看到:视图容器 / swiper (qq.com)icon-default.png?t=N7T8https://developers.weixin.qq.com/miniprogram/dev/component/swiper.html

    1. <!--index.wxml-->
    2. <view>
    3. <swiper autoplay="true" indicator-dots="true" indicator-color="#fff" indicator-active-color="#00f">
    4. <block wx:for="{{imgSrcs}}" wx:key="text">
    5. <swiper-item>
    6. <view>
    7. <image src="{{item.img}}" class="swiper-item" />
    8. </view>
    9. </swiper-item>
    10. </block>
    11. </swiper>
    12. </view>

    样式:index.wxss

    1. .swiper-item {
    2. height: 300rpx;
    3. width: 100%;
    4. border-radius: 10rpx;
    5. }

    在index.js里面添加轮播图方法:

    1. // 轮播图数据
    2. loadSwiperImgs(){
    3. let that=this;
    4. wx.request({
    5. url: api.SwiperImgs,
    6. dataType: 'json',
    7. success(res) {
    8. console.log(res)
    9. that.setData({
    10. imgSrcs:res.data.images
    11. })
    12. }
    13. })
    14. },

    在index.js的onload方法中调用:

    1. onLoad() {
    2. if (wx.getUserProfile) {
    3. this.setData({
    4. canIUseGetUserProfile: true
    5. })
    6. }
    7. this.loadSwiperImgs();
    8. },

    在index.js里面 接口mockjs

    1. // 轮播图 mockjs
    2. const api = require("../config/app.js");

     注意:在这里我们用的是http的网址,不是https所以会报错,我们需要修改

    接着点开调式器的mock,在里面新增接口: 

    json数据:

    1. {
    2. "data": {
    3. "images":[
    4. {
    5. "img": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner1.png",
    6. "text": "1"
    7. },
    8. {
    9. "img": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner2.png",
    10. "text": "2"
    11. },
    12. {
    13. "img": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner3.png",
    14. "text": "3"
    15. },
    16. {
    17. "img": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner4.png",
    18. "text": "4"
    19. },
    20. {
    21. "img": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner5.png",
    22. "text": "5"
    23. },
    24. {
    25. "img": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner6.png",
    26. "text": "6"
    27. }
    28. ]
    29. },
    30. "statusCode": "200",
    31. "header": {
    32. "content-type":"applicaiton/json;charset=utf-8"
    33. }
    34. }

    这样就可以啦,看看效果

    四.OA首页的布局

    mock数据:

    1. lists: [
    2. {
    3. "id": "1",
    4. "image": "/static/persons/1.jpg",
    5. "title": "对话产品总监 | 深圳·北京PM大会 【深度对话小米/京东/等产品总监】",
    6. "num":"304",
    7. "state":"进行中",
    8. "starttime": "2022-03-13 00:00:00",
    9. "location": "深圳市·南山区"
    10. },
    11. {
    12. "id": "1",
    13. "image": "/static/persons/2.jpg",
    14. "title": "AI WORLD 2016世界人工智能大会",
    15. "num":"380",
    16. "state":"已结束",
    17. "starttime": "2022-03-15 00:00:00",
    18. "location": "北京市·朝阳区"
    19. },
    20. {
    21. "id": "1",
    22. "image": "/static/persons/3.jpg",
    23. "title": "H100太空商业大会",
    24. "num":"500",
    25. "state":"进行中",
    26. "starttime": "2022-03-13 00:00:00",
    27. "location": "大连市"
    28. },
    29. {
    30. "id": "1",
    31. "image": "/static/persons/4.jpg",
    32. "title": "报名年度盛事,大咖云集!2016凤凰国际论坛邀您“与世界对话”",
    33. "num":"150",
    34. "state":"已结束",
    35. "starttime": "2022-03-13 00:00:00",
    36. "location": "北京市·朝阳区"
    37. },
    38. {
    39. "id": "1",
    40. "image": "/static/persons/5.jpg",
    41. "title": "新质生活 · 品质时代 2016消费升级创新大会",
    42. "num":"217",
    43. "state":"进行中",
    44. "starttime": "2022-03-13 00:00:00",
    45. "location": "北京市·朝阳区"
    46. }
    47. ]
    48. },

    前端index.wxml:

    1. <view class="mobi-title">
    2. <text class="mobi-icon"></text>
    3. <text>会议信息</text>
    4. </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">
    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">{{item.state}}</view>
    14. <view class="join"><text class="list-num">{{item.num}}</text>人报名</view>
    15. </view>
    16. <view class="list-info"><text>{{item.location}}</text>|<text>{{item.starttime}}</text></view>
    17. </view>
    18. </view>
    19. </block>
    20. <view class="section bottom-line">
    21. <text>到底啦</text>
    22. </view>

    样式:index.wxss

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

    效果:

    好啦今天的分享就到这啦!!

  • 相关阅读:
    点云处理开发测试题目
    历届图灵奖得主盘点
    django ModelSerializer自定义显示字段
    JavaScript - 将 Allegro 坐标文件转为嘉立创坐标文件(CSV 格式)的工具
    体系结构29_多处理机的互联网络
    GO微服务实战第三十一节 案例:如何在微服务中集成 Zipkin 组件?
    【Fastadmin/ThinkPHP5】使用Queue队列方法详细步骤
    深眸科技迭代深度学习算法,以AI机器视觉技术扩围工业应用场景
    Java.lang.Class类 toString()方法有什么功能呢?
    画布入门—由浅至深
  • 原文地址:https://blog.csdn.net/YZZdear/article/details/133882254