飞道的博客

微信小程序:会议OA项目-首页

489人阅读  评论(0)

目录

一、flex布局

Flex布局简介

什么是flex布局?

flex属性

flex的属性

二、轮播图组件及mockjs的使用

三、会议OA小程序首页布局

一、flex布局

Flex布局简介

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

什么是flex布局?

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

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

3) display: ‘flex’

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

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

flex属性

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

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

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

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

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

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

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

学习地址: Flex 布局语法教程 | 菜鸟教程

准备工作:打开我们的微信开发工具

新建一个小程序项目

目标

 搭建框架

 将static的文件夹放入小程序项目中

 以下是static中的内容

 

 构建我们的界面

 此时的app.json


  
  1. {
  2. "pages": [
  3. "pages/index/index",
  4. "pages/meeting/list/list",
  5. "pages/vote/list/list",
  6. "pages/ucenter/index/index"
  7. ],
  8. "window": {
  9. "backgroundTextStyle": "light",
  10. "navigationBarBackgroundColor": "#fff",
  11. "navigationBarTitleText": "Weixin",
  12. "navigationBarTextStyle": "black"
  13. },
  14. "tabBar": {
  15. "list": [
  16. {
  17. "pagePath": "pages/index/index",
  18. "text": "首页",
  19. "iconPath": "/static/tabBar/coding.png",
  20. "selectedIconPath": "/static/tabBar/coding-active.png"
  21. },
  22. {
  23. "pagePath": "pages/meeting/list/list",
  24. "iconPath": "/static/tabBar/sdk.png",
  25. "selectedIconPath": "/static/tabBar/sdk-active.png",
  26. "text": "会议"
  27. },
  28. {
  29. "pagePath": "pages/vote/list/list",
  30. "iconPath": "/static/tabBar/template.png",
  31. "selectedIconPath": "/static/tabBar/template-active.png",
  32. "text": "投票"
  33. },
  34. {
  35. "pagePath": "pages/ucenter/index/index",
  36. "iconPath": "/static/tabBar/component.png",
  37. "selectedIconPath": "/static/tabBar/component-active.png",
  38. "text": "设置"
  39. }
  40. ]
  41. },
  42. "style": "v2",
  43. "sitemapLocation": "sitemap.json"
  44. }

体会一下什么是flex布局

编辑list.wxml和list.wxss

 list.wxml


  
  1. <!--pages/meeting/list/list. wxml-->
  2. <!-- <text>pages/meeting/list/list.wxml</text> -->
  3. <view class="box">
  4. <view>1 </view>
  5. <view>2 </view>
  6. <view>3 </view>
  7. <view>4 </view>
  8. <view>5 </view>
  9. <view>6 </view>
  10. <view>7 </view>
  11. <view>8 </view>
  12. <view>9 </view>
  13. <view>10 </view>
  14. <view>11 </view>
  15. <view>12 </view>
  16. </view>

list.wxss(使用了flex的代码)


  
  1. /* pages/meeting/list/list.wxss */
  2. . box{
  3. height: 750rpx;
  4. width: 750rpx;
  5. background- color: aquamarine;
  6. display: flex;
  7. }
  8. view{
  9. height: 100rpx;
  10. width: 100rpx;
  11. border: 1px solid pink;
  12. }

未使用flex布局的效果图

 使用的效果图

 结论:使用flex布局(弹性布局)后,不会因为屏幕变小而导致效果失真

flex的属性

 

 

 

 想要了解更多,大家可以去看提供的学习地址

二、轮播图组件及mockjs的使用

体验以下轮播图组件的使用

通过开发文档找到该组件

 点击在开发者工具中预览效果

 

 效果图

 会自动播放

 找到我们所需要的功能代码复制到小程序项目中去,然后根据项目对代码进行修改

index.wxml


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

在没有后台的情况下会使用mockjs来造数据

mockjs的使用

新建一个config的文件夹,里面新建一个app.js的文件

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


  
  1. // pages/index/index.js
  2. const api = require( "../../config/app")
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgSrcs:[] //需要调用http://localhost:8080/demo/wx/swiperImgs接口地址拿数据
  9. },
  10. /**
  11. * 生命周期函数--监听页面加载
  12. */
  13. onLoad( options) {
  14. this. loadSwiperImgs();
  15. },
  16. /**
  17. * 生命周期函数--监听页面初次渲染完成
  18. */
  19. onReady( ) {
  20. },
  21. /**
  22. * 生命周期函数--监听页面显示
  23. */
  24. onShow( ) {
  25. },
  26. /**
  27. * 生命周期函数--监听页面隐藏
  28. */
  29. onHide( ) {
  30. },
  31. /**
  32. * 生命周期函数--监听页面卸载
  33. */
  34. onUnload( ) {
  35. },
  36. /**
  37. * 页面相关事件处理函数--监听用户下拉动作
  38. */
  39. onPullDownRefresh( ) {
  40. },
  41. /**
  42. * 页面上拉触底事件的处理函数
  43. */
  44. onReachBottom( ) {
  45. },
  46. /**
  47. * 用户点击右上角分享
  48. */
  49. onShareAppMessage( ) {
  50. },
  51. //加载图片
  52. loadSwiperImgs( ){
  53. let that= this;
  54. // http://localhost:8080/demo/wx/swiperImgs
  55. wx. request({
  56. url: api. SwiperImgs,
  57. dataType: 'json',
  58. success( res) {
  59. console. log(res)
  60. that. setData({
  61. imgSrcs:res. data. images
  62. })
  63. }
  64. })
  65. }
  66. })

 效果图:

三、会议OA小程序首页布局

调整一下样式

index.wxss


  
  1. /* pages/index/index.wxss */
  2. page{
  3. height: 100%;
  4. background- color: #efeff4;
  5. }
  6. . swiper-item {
  7. height: 300rpx;
  8. width: 100%;
  9. border- radius: 10rpx;
  10. }

在没有后台的情况下我们之前是使用mock工具 提供的图片,现在我们将数据固定

index.js


  
  1. // pages/index/index.js
  2. const api = require( "../../config/app")
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgSrcs:[], //需要调用http://localhost:8080/demo/wx/swiperImgs接口地址拿数据
  9. lists:[
  10. {
  11. "id": "1",
  12. "image": "/static/persons/1.jpg",
  13. "title": "对话产品总监 | 深圳·北京PM大会 【深度对话小米/京东/等产品总监】",
  14. "num": "304",
  15. "state": "进行中",
  16. "starttime": "2022-03-13 00:00:00",
  17. "location": "深圳市·南山区"
  18. },
  19. {
  20. "id": "1",
  21. "image": "/static/persons/2.jpg",
  22. "title": "AI WORLD 2016世界人工智能大会",
  23. "num": "380",
  24. "state": "已结束",
  25. "starttime": "2022-03-15 00:00:00",
  26. "location": "北京市·朝阳区"
  27. },
  28. {
  29. "id": "1",
  30. "image": "/static/persons/3.jpg",
  31. "title": "H100太空商业大会",
  32. "num": "500",
  33. "state": "进行中",
  34. "starttime": "2022-03-13 00:00:00",
  35. "location": "大连市"
  36. },
  37. {
  38. "id": "1",
  39. "image": "/static/persons/4.jpg",
  40. "title": "报名年度盛事,大咖云集!2016凤凰国际论坛邀您“与世界对话”",
  41. "num": "150",
  42. "state": "已结束",
  43. "starttime": "2022-03-13 00:00:00",
  44. "location": "北京市·朝阳区"
  45. },
  46. {
  47. "id": "1",
  48. "image": "/static/persons/5.jpg",
  49. "title": "新质生活 · 品质时代 2016消费升级创新大会",
  50. "num": "217",
  51. "state": "进行中",
  52. "starttime": "2022-03-13 00:00:00",
  53. "location": "北京市·朝阳区"
  54. }
  55. ]
  56. },
  57. /**
  58. * 生命周期函数--监听页面加载
  59. */
  60. onLoad( options) {
  61. this. loadSwiperImgs();
  62. },
  63. /**
  64. * 生命周期函数--监听页面初次渲染完成
  65. */
  66. onReady( ) {
  67. },
  68. /**
  69. * 生命周期函数--监听页面显示
  70. */
  71. onShow( ) {
  72. },
  73. /**
  74. * 生命周期函数--监听页面隐藏
  75. */
  76. onHide( ) {
  77. },
  78. /**
  79. * 生命周期函数--监听页面卸载
  80. */
  81. onUnload( ) {
  82. },
  83. /**
  84. * 页面相关事件处理函数--监听用户下拉动作
  85. */
  86. onPullDownRefresh( ) {
  87. },
  88. /**
  89. * 页面上拉触底事件的处理函数
  90. */
  91. onReachBottom( ) {
  92. },
  93. /**
  94. * 用户点击右上角分享
  95. */
  96. onShareAppMessage( ) {
  97. },
  98. //加载图片
  99. loadSwiperImgs( ){
  100. let that= this;
  101. // http://localhost:8080/demo/wx/swiperImgs
  102. wx. request({
  103. url: api. SwiperImgs,
  104. dataType: 'json',
  105. success( res) {
  106. console. log(res)
  107. that. setData({
  108. imgSrcs:res. data. images
  109. })
  110. }
  111. })
  112. }
  113. })

index.wxml


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

此时的效果图:

 我们对其进行调整

index.wxss


  
  1. /* pages/index/index.wxss */
  2. page{
  3. height: 100%;
  4. background- color: #efeff4;
  5. }
  6. . swiper-item {
  7. height: 300rpx;
  8. width: 100%;
  9. border- radius: 10rpx;
  10. }
  11. . mobi-title{
  12. line- height: 120%;
  13. margin: 10rpx;
  14. /* margin-top: -50px; */
  15. }
  16. . mobi-icon{
  17. padding: 0 3rpx;
  18. background- color: #ff7777;
  19. }
  20. . list{
  21. display: flex;
  22. margin: 20rpx 0;
  23. background- color:#ffffff;
  24. }
  25. . list-img,. video-img{
  26. height: 120rpx;
  27. width: 120rpx;
  28. }
  29. . video-img{
  30. margin:20px 10rpx;
  31. }
  32. . list-detail{
  33. /* border: 2px solid red; */
  34. height: 220rpx;
  35. width: 600rpx;
  36. margin: 5rpx 20rpx;
  37. }
  38. . list-title{
  39. font- weight: 700;
  40. }
  41. . list-tag{
  42. display: flex;
  43. margin: 10rpx 0;
  44. }
  45. . state,. join{
  46. border: 1px solid rgb( 160, 216, 235);
  47. padding: 10rpx;
  48. }
  49. . list-num{
  50. color: red;
  51. }
  52. . bottom-line{
  53. text- align: center;
  54. margin- bottom: 10px;
  55. }

index.wxml


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

效果:


转载:https://blog.csdn.net/weixin_62735525/article/details/128540485
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场