• 会议OA小程序【首页布局】


    目录

    一. Flex布局介绍

    1.1 什么是Flex布局

    1.2 基本概念

    1.3 Flex属性

     二. 会议OA首页轮播图的实现

    配置

    Mock工具

    swiper

    效果展示

    三. 会议OA首页会议信息布局

    index.js

    index.wxml

    index.wxss 

    首页整体效果展示


    一. Flex布局介绍

    布局的传统解决方案,基于盒状模型,依赖 display属性 + position属性 + float属性。

    2009年,W3C提出了一种新的方案—-Flex布局,可以简便、完整、响应式地实现各种页面布局。目前,它已经得到了所有浏览器的支持,这意味着,现在就能很安全地使用这项功能。

    1.1 什么是Flex布局

    Flex是Flexible Box的缩写,意为”弹性布局”,用来为盒状模型提供最大的灵活性。

    任何一个容器都可以指定为Flex布局。

    1. .box{
    2. display: flex;
    3. }

    行内元素也可以使用Flex布局。

    1. .box{
    2. display: inline-flex;
    3. }

    Webkit内核的浏览器,必须加上-webkit前缀。

    1. .box{
    2. display: -webkit-flex; /* Safari */
    3. display: flex;
    4. }

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

    1.2 基本概念

    采用Flex布局的元素,称为Flex容器(flex container),简称”容器”。它的所有子元素自动成为容器成员,称为Flex项目(flex item),简称”项目”。

    容器默认存在两根轴:水平的主轴(main axis)和垂直的交叉轴(cross axis)。主轴的开始位置(与边框的交叉点)叫做main start,结束位置叫做main end;交叉轴的开始位置叫做cross start,结束位置叫做cross end。

    项目默认沿主轴排列。单个项目占据的主轴空间叫做main size,占据的交叉轴空间叫做cross size。

    1.3 Flex属性

    • flex-direction 主轴的方向(即项目的排列方向) 默认为row

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

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

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

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

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

    详细内容请查看 Flex布局语法教程

     二. 会议OA首页轮播图的实现

    配置

    • config/api.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. };

    Mock工具

    由于这里我还没有将小程序与后台数据进行交互,所以使用mock模拟数据

    • imgSrcs

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

    swiper

    • index.wxml
    1. <!--index.wxml-->
    2. <view>
    3. <swiper indicator-dots="true"
    4. autoplay="true">
    5. <block wx:for="{{imgSrcs}}" wx:key="*text">
    6. <swiper-item>
    7. <image src="{{item.img}}"/>
    8. </swiper-item>
    9. </block>
    10. </swiper>
    11. </view>
    • index.js
    1. // index.js
    2. // 获取应用实例
    3. const app = getApp()
    4. const api = require("../../config/api.js")
    5. Page({
    6. data: {
    7. imgSrcs:[]
    8. },
    9. // 事件处理函数
    10. bindViewTap() {
    11. wx.navigateTo({
    12. url: '../logs/logs'
    13. })
    14. },
    15. loadSwiperImgs(){
    16. let that=this;
    17. wx.request({
    18. url: api.SwiperImgs,
    19. dataType: 'json',
    20. success(res) {
    21. console.log(res)
    22. that.setData({
    23. imgSrcs:res.data.images
    24. })
    25. }
    26. })
    27. },
    28. onLoad() {
    29. if (wx.getUserProfile) {
    30. this.setData({
    31. canIUseGetUserProfile: true
    32. })
    33. }
    34. this.loadSwiperImgs();
    35. },
    36. getUserProfile(e) {
    37. // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
    38. wx.getUserProfile({
    39. desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
    40. success: (res) => {
    41. console.log(res)
    42. this.setData({
    43. userInfo: res.userInfo,
    44. hasUserInfo: true
    45. })
    46. }
    47. })
    48. },
    49. getUserInfo(e) {
    50. // 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息
    51. console.log(e)
    52. this.setData({
    53. userInfo: e.detail.userInfo,
    54. hasUserInfo: true
    55. })
    56. }
    57. })

    效果展示

    三. 会议OA首页会议信息布局

    • index.js

    1. // index.js
    2. // 获取应用实例
    3. const app = getApp()
    4. const api = require("../../config/api.js")
    5. Page({
    6. data: {
    7. imgSrcs:[
    8. {
    9. "img": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner1.png",
    10. "text": "1"
    11. },
    12. {
    13. "img": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner2.png",
    14. "text": "2"
    15. },
    16. {
    17. "img": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner3.png",
    18. "text": "3"
    19. },
    20. {
    21. "img": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner4.png",
    22. "text": "4"
    23. },
    24. {
    25. "img": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner5.png",
    26. "text": "5"
    27. },
    28. {
    29. "img": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner6.png",
    30. "text": "6"
    31. }
    32. ],
    33. lists:[
    34. {
    35. "id": "1",
    36. "image": "/static/persons/1.jpg",
    37. "title": "对话产品总监 | 深圳·北京PM大会 【深度对话小米/京东/等产品总监】",
    38. "num":"304",
    39. "state":"进行中",
    40. "starttime": "2022-03-13 00:00:00",
    41. "location": "深圳市·南山区"
    42. },
    43. {
    44. "id": "1",
    45. "image": "/static/persons/2.jpg",
    46. "title": "AI WORLD 2016世界人工智能大会",
    47. "num":"380",
    48. "state":"已结束",
    49. "starttime": "2022-03-15 00:00:00",
    50. "location": "北京市·朝阳区"
    51. },
    52. {
    53. "id": "1",
    54. "image": "/static/persons/3.jpg",
    55. "title": "H100太空商业大会",
    56. "num":"500",
    57. "state":"进行中",
    58. "starttime": "2022-03-13 00:00:00",
    59. "location": "大连市"
    60. },
    61. {
    62. "id": "1",
    63. "image": "/static/persons/4.jpg",
    64. "title": "报名年度盛事,大咖云集!2016凤凰国际论坛邀您“与世界对话”",
    65. "num":"150",
    66. "state":"已结束",
    67. "starttime": "2022-03-13 00:00:00",
    68. "location": "北京市·朝阳区"
    69. },
    70. {
    71. "id": "1",
    72. "image": "/static/persons/5.jpg",
    73. "title": "新质生活 · 品质时代 2016消费升级创新大会",
    74. "num":"217",
    75. "state":"进行中",
    76. "starttime": "2022-03-13 00:00:00",
    77. "location": "北京市·朝阳区"
    78. }
    79. ]
    80. },
    81. // 事件处理函数
    82. bindViewTap() {
    83. wx.navigateTo({
    84. url: '../logs/logs'
    85. })
    86. },
    87. loadSwiperImgs(){
    88. let that=this;
    89. wx.request({
    90. url: api.SwiperImgs,
    91. dataType: 'json',
    92. success(res) {
    93. console.log(res)
    94. that.setData({
    95. imgSrcs:res.data.images
    96. })
    97. }
    98. })
    99. },
    100. onLoad() {
    101. if (wx.getUserProfile) {
    102. this.setData({
    103. canIUseGetUserProfile: true
    104. })
    105. }
    106. this.loadSwiperImgs();
    107. },
    108. getUserProfile(e) {
    109. // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
    110. wx.getUserProfile({
    111. desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
    112. success: (res) => {
    113. console.log(res)
    114. this.setData({
    115. userInfo: res.userInfo,
    116. hasUserInfo: true
    117. })
    118. }
    119. })
    120. },
    121. getUserInfo(e) {
    122. // 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息
    123. console.log(e)
    124. this.setData({
    125. userInfo: e.detail.userInfo,
    126. hasUserInfo: true
    127. })
    128. }
    129. })
    • index.wxml

    1. <!--index.wxml-->
    2. <view>
    3. <swiper indicator-dots="true"
    4. autoplay="true">
    5. <block wx:for="{{imgSrcs}}" wx:key="*text">
    6. <swiper-item>
    7. <image src="{{item.img}}"/>
    8. </swiper-item>
    9. </block>
    10. </swiper>
    11. </view>
    12. <view class="mobi-title">
    13. <text class="mobi-icon"></text>
    14. <text>会议信息</text>
    15. </view>
    16. <block wx:for-items="{{lists}}" wx:for-item="item" wx:key="item.id">
    17. <view class="list" data-id="{{item.id}}">
    18. <view class="list-img">
    19. <image class="video-img" mode="scaleToFill" src="{{item.image}}"></image>
    20. </view>
    21. <view class="list-detail">
    22. <view class="list-title"><text>{{item.title}}</text></view>
    23. <view class="list-tag">
    24. <view class="state">{{item.state}}</view>
    25. <view class="join"><text class="list-num">{{item.num}}</text>人报名</view>
    26. </view>
    27. <view class="list-info"><text>{{item.location}}</text>|<text>{{item.starttime}}</text></view>
    28. </view>
    29. </view>
    30. </block>
    31. <view class="section bottom-line">
    32. <text>到底啦</text>
    33. </view>
    • index.wxss 

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

    首页整体效果展示

  • 相关阅读:
    【vue】如何打开别人编译后的vue项目
    面试系列 - Redis持久化机制详解
    Elasticsearch 搜索入门技术之一
    K8s使用RDMA进行高速通信
    JVM 虚拟机系列:架构(二)一图看懂虚拟机架构:JNI
    Qt技巧--添加C++11支持
    Spark java.io.NotSerializableException
    数据湖:分布式开源处理引擎Spark
    ES6 类的扩展
    dubbo 接口的测试方法汇总
  • 原文地址:https://blog.csdn.net/lijie1025/article/details/133882831