微信小程序 —— 会议OA项目首页布局与Mock数据交互

news2025/3/15 0:19:01

14天阅读挑战赛
如果世界上有奇迹,那一定是努力的另一个名字。

目录

一、小程序布局

1.1 Flex布局

1.2 Flex属性

 

二、OA会议首页搭建

2.1 首页底部菜单

2.2 创建后端结口

2.3 Mock模拟数据

2.4 首页轮播图搭建

2.5 首页内容搭建 


一、小程序布局

1.1 Flex布局

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

  • Flex是Flexible Box的缩写,意为”弹性布局”,用来为盒状模型提供最大的灵活性。
  • 任何一个容器都可以指定为Flex布局。
  • display: ‘flex’

  

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

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

1.2 Flex属性

  • flex-direction 主轴的方向 默认为row
  • flex-wrap 如果一条轴线排不下,如何换行
  • flex-flow 是flex-direction属性和flex-wrap属性的简写形式
  • justify-content 定义了项目在主轴上的对齐方式
  • align-items 定义项目在交叉轴上如何对齐
  • align-content 属性定义了多根轴线的对齐方式

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


更多详情:Flex 布局语法教程 | 菜鸟教程

二、OA会议首页搭建

2.1 首页底部菜单

在该项目资源管理器创建以下路径,用来存放图标:

/static/tabBar/coding-active.png

创建新的小程序项目之后,在app.json里面pages新建页面和绑定tabBer

{
    "pages": [
        "pages/index/index",
        "pages/meeting/list/list",
        "pages/vote/list/list",
        "pages/ucenter/index/index",
        "pages/logs/logs"
    ],
    "window": {
        "backgroundTextStyle": "light",
        "navigationBarBackgroundColor": "#fff",
        "navigationBarTitleText": "Weixin",
        "navigationBarTextStyle": "black"
    },
    "tabBar": {
        "list": [
            {
                "pagePath": "pages/index/index",
                "text": "首页",
                "iconPath": "/static/tabBar/coding.png",
                "selectedIconPath": "/static/tabBar/coding-active.png"
            },
            {
                "pagePath": "pages/meeting/list/list",
                "iconPath": "/static/tabBar/sdk.png",
                "selectedIconPath": "/static/tabBar/sdk-active.png",
                "text": "会议"
            },
            {
                "pagePath": "pages/vote/list/list",
                "iconPath": "/static/tabBar/template.png",
                "selectedIconPath": "/static/tabBar/template-active.png",
                "text": "投票"
            },
            {
                "pagePath": "pages/ucenter/index/index",
                "iconPath": "/static/tabBar/component.png",
                "selectedIconPath": "/static/tabBar/component-active.png",
                "text": "设置"
            }
        ]
    },
    "style": "v2",
    "sitemapLocation": "sitemap.json"
}

2.2 创建后端结口

在该项目资源管理器创建config/api.js文件

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

2.3 Mock模拟数据

本次没有连接后端,利用小程序Mock模拟假数据。

打开调试器,按照一下示例进行操作

{
  "data": {
    "images":[
  {
    "img": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner1.png",
    "text": "1"
  },
  {
    "img": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner2.png",
    "text": "2"
  },
  {
    "img": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner3.png",
    "text": "3"
  },
  {
    "img": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner4.png",
    "text": "4"
  },
  {
    "img": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner5.png",
    "text": "5"
  },
  {
    "img": "https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner6.png",
    "text": "6"
  }
]
  },
  "statusCode": "200",
  "header": {
    "content-type":"applicaiton/json;charset=utf-8"
  }
}

2.4 首页轮播图搭建

首先打开不校验合法域名设置:

编写轮播图页面:

//index.wxml
<view>
    <swiper autoplay="true" indicator-dots="true" indicator-color="#fff" indicator-active-color="#00f">
        <block wx:for="{{imgSrcs}}" wx:key="text">
            <swiper-item>
                <view>
                    <image src="{{item.img}}" class="swiper-item" />
                </view>
            </swiper-item>
        </block>
    </swiper>
</view>

编写js

// index.js
// 获取应用实例
const app = getApp()
const api = require("../../config/api")
Page({
    data: {
        imgSrcs: [],
        lists: []
    },
    // 事件处理函数
    bindViewTap() {
        wx.navigateTo({
            url: '../logs/logs'
        })
    },
    //   轮播图的方法
    loadSwiperImgs() {
        let that = this;
        wx.request({
            url: api.SwiperImgs,
            dataType: 'json',
            success(res) {
                console.log(res)
                that.setData({
                    imgSrcs: res.data.images
                })
            }
        })
    },
    onLoad() {
        if (wx.getUserProfile) {
            this.setData({
                canIUseGetUserProfile: true
            })
        }
        // 一进来就调用轮播图的方法
        this.loadSwiperImgs();
        this.loadMeetingInfos();
    },
    getUserProfile(e) {
        // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
        wx.getUserProfile({
            desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
            success: (res) => {
                console.log(res)
                this.setData({
                    userInfo: res.userInfo,
                    hasUserInfo: true
                })
            }
        })
    },
    getUserInfo(e) {
        // 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息
        console.log(e)
        this.setData({
            userInfo: e.detail.userInfo,
            hasUserInfo: true
        })
    }
})

效果图:

2.5 首页内容搭建 

 1. 利用Mack模拟数据

JSON数据包:

{
  "data": {
    "lists": [
        {
          "id": "1",
          "image": "/static/persons/1.jpg",
          "title": "对话产品总监 | 深圳·北京PM大会 【深度对话小米/京东/等产品总监】",
          "num":"304",
          "state":"进行中",
          "starttime": "2022-03-13 00:00:00",
          "location": "深圳市·南山区"
        },
        {
          "id": "1",
          "image": "/static/persons/2.jpg",
          "title": "AI WORLD 2016世界人工智能大会",
          "num":"380",
          "state":"已结束",
          "starttime": "2022-03-15 00:00:00",
          "location": "北京市·朝阳区"
        },
        {
          "id": "1",
          "image": "/static/persons/3.jpg",
          "title": "H100太空商业大会",
          "num":"500",
          "state":"进行中",
          "starttime": "2022-03-13 00:00:00",
          "location": "大连市"
        },
        {
          "id": "1",
          "image": "/static/persons/4.jpg",
          "title": "报名年度盛事,大咖云集!2016凤凰国际论坛邀您“与世界对话”",
          "num":"150",
          "state":"已结束",
          "starttime": "2022-03-13 00:00:00",
          "location": "北京市·朝阳区"
        },
        {
          "id": "1",
          "image": "/static/persons/5.jpg",
          "title": "新质生活 · 品质时代 2016消费升级创新大会",
          "num":"217",
          "state":"进行中",
          "starttime": "2022-03-13 00:00:00",
          "location": "北京市·朝阳区"
        }
      ]
  },
  "statusCode": "200",
  "header": {
    "content-type":"applicaiton/json;charset=utf-8"
  }
}

2. 添加js方法

index.js
    //首页会议信息的ajax
    loadMeetingInfos() {
        let that = this;
        wx.request({
            url: api.MettingInfos,
            dataType: 'json',
            success(res) {
              console.log(res),
                that.setData({
                    lists: res.data.lists
                })
            }
        })
    },

3. 首页界面:

<view class="indexbg">
    <swiper autoplay="true" indicator-dots="true" indicator-color="#fff" indicator-active-color="#00f">
        <block wx:for="{{imgSrcs}}" wx:key="text">
            <swiper-item>
                <view>
                    <image src="{{item.img}}" class="swiper-item" />
                </view>
            </swiper-item>
        </block>
    </swiper>
    <view class="mobi-title">
        <text class="mobi-text">会议信息</text>
    </view>
    <block wx:for-items="{{lists}}" wx:for-item="item" wx:key="item.id" class="bg">
        <view class="list" data-id="{{item.id}}">
            <view class="list-img">
                <image class="video-img" mode="scaleToFill" src="{{item.image}}"></image>
            </view>
            <view class="list-detail">
                <view class="list-title"><text>{{item.title}}</text></view>
                <view class="list-tag">
                    <view class="state">{{item.state}}</view>
                    <view class="join"><text class="list-num">{{item.num}}</text>人报名</view>
                </view>
                <view class="list-info"><text>{{item.location}}</text>|<text>{{item.starttime}}</text></view>
            </view>
        </view>
    </block>
    <view class="section">
        <text>到底啦</text>
    </view>
</view>

4. 界面样式:

/**index.wxss**/
.userinfo {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: #aaa;
}

.userinfo-avatar {
  overflow: hidden;
  width: 128rpx;
  height: 128rpx;
  margin: 20rpx;
  border-radius: 50%;
}

.usermotto {
  margin-top: 200px;
}

/**index.wxss**/
.section {
  color: #aaa;
  display: flex;
  justify-content: center;
}

.list-info {
  color: #aaa;
}

.list-num {
  color: red;
  /* font-weight: 700; */
}

.join {
  padding: 0px 0px 0px 10px;
  color: #aaa;
}

.state {
  margin: 0px 6px 0px 6px;
  border: 1px solid #4083ff;
  color: #4083ff;
  padding: 3px 5px 3px 5px;
}

.list-tag {
  padding: 3px 0px 10px 0px;
  display: flex;
  align-items: center;
}

.list-title {
  display: flex;
  justify-content: space-between;
  font-size: 11pt;
  color: #333;
  font-weight: bold;


}

.list-detail {
  display: flex;
  flex-direction: column;
  margin: 0px 0px 0px 15px;
}

.video-img {
  margin-top: 5px;
  width: 80px;
  height: 80px;
}

.list {
  display: flex;
  flex-direction: row;
  background-color: seashell;
  border-bottom: 1px solid #cecece;
  padding: 10px;
}

.mobi-text {
  font-weight: 700;
  padding: 15px;
}

/* .mobi-icon {
  border-left: 5px solid #57f564;
} */
.indexbg{
    background-color: rgba(219, 219, 219, 0.678);
}

.mobi-title {
  /* background-color: rgba(219, 219, 219, 0.678); */
  margin: 10px 0px 10px 0px;
}

.swiper-item {
  height: 300rpx;
  width: 100%;
  border-radius: 10rpx;
}

.userinfo {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: #aaa;
}

.userinfo-avatar {
  overflow: hidden;
  width: 128rpx;
  height: 128rpx;
  margin: 20rpx;
  border-radius: 50%;
}

.usermotto {
  margin-top: 200px;
}

5. 效果展示

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1103826.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

SpringBoot+Mybatis实现多数据源+分页

1 主要依赖版本 &#xff08;1&#xff09;SpringBoot 2.7.8 &#xff08;2&#xff09;Mybatis 2.2.2 &#xff08;3&#xff09;Pagehelper 1.3.0 &#xff08;4&#xff09;MySQL 8.0.26 &#xff08;5&#xff09;Oracle 11.2.0.3 2 概述 &#xff08;1&#xff09;…

Linux内核8. 进程地址空间

进程地址空间也就是每个进程所使用的内存&#xff0c;内核对进程地址空间的管理&#xff0c;也就是对用户态程序的内存管理。 主要内容&#xff1a; 地址空间(mm_struct)虚拟内存区域(VMA)地址空间和页表 1. 地址空间(mm_struct) 地址空间就是每个进程所能访问的内存地址范围…

React高级特性之RenderProps

一、概念 renderProps是另外一个能实现类似于HOC这种多个组件抽离公共组件逻辑的方式。 二、例子 import React from react import PropTypes from prop-typesclass Mouse extends React.Component {constructor(props) {super(props)this.state { x: 0, y: 0 }}handleMouse…

日志技术快速入门

1、创建Maven项目 这里不再说如何创建Maven项目 2、导入相关依赖 <dependency><groupId>ch.qos.logback</groupId><artifactId>logback-classic</artifactId><version>1.2.12</version></dependency>3、创建配置文件 在re…

Spring源码解析——事务增强器

正文 上一篇文章我们讲解了事务的Advisor是如何注册进Spring容器的&#xff0c;也讲解了Spring是如何将有配置事务的类配置上事务的&#xff0c;实际上也就是用了AOP那一套&#xff0c;也讲解了Advisor&#xff0c;pointcut验证流程&#xff0c;至此&#xff0c;事务的初始化工…

强化学习------Policy Gradient算法

目录 简介PG算法原理效果&#xff1a;参考 简介 之前的QLearning DQN Sarsa都是通过计算动作得分来决策的&#xff0c;我们是在确定了价值函数的基础上采用某种策略&#xff0c;即Value-Based&#xff0c;通过先算出价值函数&#xff0c;再去做决策。而Policy Gradient算法是一…

云计算:shell脚本

shell脚本&#xff0c;会极大减少重复性工作&#xff0c;缩短很大时间。 脚本每个人都可以不一样&#xff0c;只要实现就可以。 注意&#xff1a;要多思考&#xff0c;把思路锻炼好。以后就可以写各种程序。 shell语言 学完shell之后&#xff0c;对Linux理解更深刻&#xff…

在调试器下看微信[如何耗电]

在今天这样干什么都离不开手机的时代里&#xff0c;手机的待机时间太重要了。特别是对于我这个不喜欢带充电宝出门的人来说&#xff0c;一旦看到手机电量低于20%&#xff0c;立刻就精神紧张了&#xff0c;因为一切信息都在手机里&#xff0c;如果手机没电&#xff0c;那么就失联…

[SQL | MyBatis] MyBatis 简介

目录 一、MyBatis 简介 1、MyBatis 简介 2、工作流程 二、入门案例 1、准备工作 2、示例 三、Mapper 代理开发 1、问题简介 2、工作流程 3、注意事项 4、测试 四、核心配置文件 mybatis-config.xml 1、environment 2、typeAilases 五、基于 xml 的查询操作 1、…

通过stream对list集合中对象的多个字段进行去重

记录下通过stream流对list集合中对象的多个字段进行去重&#xff01; 举个栗子&#xff0c;对象book&#xff0c;我们要通过姓名和价格这两个字段的值进行去重&#xff0c;该这么做呢&#xff1f; distinct&#xff08;&#xff09;返回由该流的不同元素组成的流。distinct&am…

第五届芜湖机器人展,正运动助力智能装备“更快更准”更智能!

■展会名称&#xff1a; 第十一届中国(芜湖)科普产品博览交易会-第五届机器人展 ■展会日期 2023年10月21日-23日 ■展馆地点 中国ㆍ芜湖宜居国际博览中心B馆 ■展位号 B029 正运动技术&#xff0c;作为国内领先的运动控制企业&#xff0c;将于2023年10月21日参加芜湖机…

查看双翌视觉软件版本号

查看双翌视觉软件版本号 MasterAlign视觉对位软件 MasterAlign视觉对位软件的版本号在软件界面的右下角&#xff0c;如下图所示&#xff1a; 进入界面查看右下角编号尾号为O的代表旧协议版本 而编号尾号为N的则为新协议版本。 WiseAlign视觉对位软件 打开WiseAlign视觉对位软…

靶机 Chill_Hack

Chill_Hack 信息搜集 存活检测 arp-scan -l 详细扫描 扫描结果 显示允许 ftp 匿名链接 FTP 匿名登录 匿名登陆 ftp 下载文件并查看 anonymous10.4.7.139下载命令 get note.txt查看文件 译 Anurodh告诉我&#xff0c;在命令 Apaar 中有一些字符串过滤后台扫描 扫描结果…

【算法挨揍日记】day16——525. 连续数组、1314. 矩阵区域和

525. 连续数组 525. 连续数组 题目描述&#xff1a; 给定一个二进制数组 nums , 找到含有相同数量的 0 和 1 的最长连续子数组&#xff0c;并返回该子数组的长度。 解题思路&#xff1a; 本题的元素只有0和1&#xff0c;根据题目意思&#xff0c;我们可以把题目看成找一段最…

Educational Codeforces Round 156 (Rated for Div. 2)

C. Decreasing String 分析&#xff1a;暴力做法是很容易想到的&#xff0c;但时间复杂度为O(n2) 这是我打cf以来看到的最好的题解。 #include<cstdio> #include<set> #include<list> #include<queue> #include<math.h> #include<stdlib.h&g…

5.DApp-前端网页怎么连接MetaMask

题记 在前端网页连接metamask&#xff0c;以下是全部操作流程和代码。 编写index.html文件 index.html文件如下&#xff1a; <!DOCTYPE html> <html> <head> <title>My DApp</title> <!--导入用于检测Metamask提供者的JavaScript库--> &l…

嵌入式开发学习之STM32F407定时器中断配置(四)

嵌入式开发学习之STM32F407定时器中断配置&#xff08;四&#xff09; 此次实现目的开发涉及工具一、TIM参数配置和中断配置二、TIM的中断服务函数 此次实现目的 1.配置一个TIM进行计时&#xff0c;让一颗LED以点亮500ms&#xff0c;熄灭500ms的方式闪烁&#xff1b; 有工程实…

【JVM】对象内存布局

对象内存布局 文章目录 对象内存布局1. 对象的内存布局2. 对象标记(Mark Word)3. 类元信息(类型指针)4. 实例数据和对象填充 1. 对象的内存布局 在Hotspot虚拟机里&#xff0c;对象在堆内存中的存储布局可以划分为三个部分&#xff1a;对象头(Header)、实例数据(Instance Data…

华为云云耀云服务器L实例评测|使用Benchmark工具对云耀云服务器Elasticsearch的性能测试

目录 引言 1 在centos上安装Elasticsearch 1.1在服务器上安装 Docker 1.2 查找Elasticsearch镜像 1.3 安装并运行 Elasticsearch 容器 2 性能测试 Elasticsearch 2.1 安装 Apache Benchmark 工具 2.2 使用Benchmark进行性能测试 3 性能分析 3.1 性能测试结果 3.2 性能…

堆/二叉堆详解[C/C++]

前言 堆是计算机科学中-类特殊的数据结构的统称。实现有很多,例如:大顶堆,小顶堆&#xff0c;斐波那契堆&#xff0c;左偏堆&#xff0c;斜堆等等。从子结点个数上可以分为二汊堆&#xff0c;N叉堆等等。本文将介绍的是二叉堆。 二叉堆的概念 1、引例 我们小时候&#xff0c;基…