• 会议OA小程序项目 与后台数据的交互【首页】


    目录

    一. 与后台数据进行交互

    pom.xml

    配置数据源

    MinoaApplication

    WxHomeController

    后台数据展示 

    二. request的封装

    三. 会议展示


    一. 与后台数据进行交互

    pom.xml

    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    4. <modelVersion>4.0.0</modelVersion>
    5. <parent>
    6. <groupId>org.springframework.boot</groupId>
    7. <artifactId>spring-boot-starter-parent</artifactId>
    8. <version>2.6.2</version>
    9. <relativePath/> <!-- lookup parent from repository -->
    10. </parent>
    11. <groupId>com.zking</groupId>
    12. <artifactId>minoa</artifactId>
    13. <version>0.0.1-SNAPSHOT</version>
    14. <name>minoa</name>
    15. <description>Demo project for Spring Boot</description>
    16. <properties>
    17. <java.version>1.8</java.version>
    18. <fastjson.version>1.2.70</fastjson.version>
    19. <jackson.version>2.9.8</jackson.version>
    20. </properties>
    21. <dependencies>
    22. <dependency>
    23. <groupId>org.springframework.boot</groupId>
    24. <artifactId>spring-boot-starter-jdbc</artifactId>
    25. </dependency>
    26. <dependency>
    27. <groupId>org.springframework.boot</groupId>
    28. <artifactId>spring-boot-starter-web</artifactId>
    29. </dependency>
    30. <dependency>
    31. <groupId>org.mybatis.spring.boot</groupId>
    32. <artifactId>mybatis-spring-boot-starter</artifactId>
    33. <version>2.2.1</version>
    34. </dependency>
    35. <dependency>
    36. <groupId>mysql</groupId>
    37. <artifactId>mysql-connector-java</artifactId>
    38. <version>5.1.44</version>
    39. <scope>runtime</scope>
    40. </dependency>
    41. <dependency>
    42. <groupId>org.projectlombok</groupId>
    43. <artifactId>lombok</artifactId>
    44. <optional>true</optional>
    45. </dependency>
    46. <dependency>
    47. <groupId>com.alibaba</groupId>
    48. <artifactId>fastjson</artifactId>
    49. <version>${fastjson.version}</version>
    50. </dependency>
    51. </dependencies>
    52. <build>
    53. <plugins>
    54. <plugin>
    55. <groupId>org.springframework.boot</groupId>
    56. <artifactId>spring-boot-maven-plugin</artifactId>
    57. <configuration>
    58. <excludes>
    59. <exclude>
    60. <groupId>org.projectlombok</groupId>
    61. <artifactId>lombok</artifactId>
    62. </exclude>
    63. </excludes>
    64. </configuration>
    65. </plugin>
    66. <plugin>
    67. <groupId>org.mybatis.generator</groupId>
    68. <artifactId>mybatis-generator-maven-plugin</artifactId>
    69. <version>1.3.2</version>
    70. <dependencies>
    71. <!--使用Mybatis-generator插件不能使用太高版本的mysql驱动 -->
    72. <dependency>
    73. <groupId>mysql</groupId>
    74. <artifactId>mysql-connector-java</artifactId>
    75. <version>${mysql.version}</version>
    76. </dependency>
    77. </dependencies>
    78. <configuration>
    79. <overwrite>true</overwrite>
    80. </configuration>
    81. </plugin>
    82. </plugins>
    83. </build>
    84. </project>

    配置数据源

    application.yml

    1. spring:
    2. datasource:
    3. #type连接池类型 DBCP,C3P0,Hikari,Druid,默认为Hikari
    4. type: com.zaxxer.hikari.HikariDataSource
    5. driver-class-name: com.mysql.jdbc.Driver
    6. url: jdbc:mysql://localhost:3306/mybatis_oapro?useUnicode=true&characterEncoding=UTF-8&useSSL=false
    7. username: root
    8. password: 123456
    9. mybatis:
    10. mapper-locations: classpath*:mapper/*.xml #指定mapper文件位置
    11. type-aliases-package: com.zking.minoa.model #指定自动生成别名所在包
    12. logging:
    13. level:
    14. root: info
    15. com.zking.minoa.mapper: debug

    MinoaApplication

    1. package com.zking.minoa;
    2. import org.mybatis.spring.annotation.MapperScan;
    3. import org.springframework.boot.SpringApplication;
    4. import org.springframework.boot.autoconfigure.SpringBootApplication;
    5. @MapperScan("com.zking.minoa.mapper") //指mapper接口所在包
    6. @SpringBootApplication
    7. public class MinoaApplication {
    8. public static void main(String[] args) {
    9. SpringApplication.run(MinoaApplication.class, args);
    10. }
    11. }

    WxHomeController

    1. package com.zking.minoa.wxcontroller;
    2. import com.zking.minoa.mapper.InfoMapper;
    3. import com.zking.minoa.model.Info;
    4. import com.zking.minoa.util.ResponseUtil;
    5. import org.springframework.beans.factory.annotation.Autowired;
    6. import org.springframework.web.bind.annotation.RequestMapping;
    7. import org.springframework.web.bind.annotation.RestController;
    8. import java.util.HashMap;
    9. import java.util.List;
    10. import java.util.Map;
    11. /**
    12. * @Autho donkee
    13. * @Since 2022/6/29
    14. */
    15. @RestController
    16. @RequestMapping("/wx/home")
    17. public class WxHomeController {
    18. @Autowired
    19. private InfoMapper infoMapper;
    20. @RequestMapping("/index")
    21. public Object index(Info info) {
    22. List infoList = infoMapper.list(info);
    23. Map data = new HashMap();
    24. data.put("infoList",infoList);
    25. return ResponseUtil.ok(data);
    26. }
    27. }

    后台数据展示 

    二. request的封装

    在utils/util.js中

    1. /**
    2. * 封装微信的request请求
    3. */
    4. function request(url, data = {}, method = "GET") {
    5. return new Promise(function (resolve, reject) {
    6. wx.request({
    7. url: url,
    8. data: data,
    9. method: method,
    10. header: {
    11. 'Content-Type': 'application/json',
    12. },
    13. success: function (res) {
    14. if (res.statusCode == 200) {
    15. resolve(res.data);//会把进行中改变成已成功
    16. } else {
    17. reject(res.errMsg);//会把进行中改变成已失败
    18. }
    19. },
    20. fail: function (err) {
    21. reject(err)
    22. }
    23. })
    24. });
    25. }
    26. module.exports = {
    27. request
    28. }

    三. 会议展示

    api.js

    1. // 以下是业务服务器API地址
    2. // 本机开发API地址
    3. var WxApiRoot = 'http://localhost:8080/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/index.js

    1. // index.js
    2. // 获取应用实例
    3. const app = getApp()
    4. const api = require("../../config/api.js")
    5. const util = require("../../utils/util.js")
    6. Page({
    7. data: {
    8. imgSrcs: [{
    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. },
    36. // 事件处理函数
    37. bindViewTap() {
    38. wx.navigateTo({
    39. url: '../logs/logs'
    40. })
    41. },
    42. loadMeetInfos() {
    43. util.request(api.IndexUrl).then(res => {
    44. console.log(res);
    45. this.setData({
    46. lists: res.data.infoList
    47. })
    48. })
    49. },
    50. onLoad() {
    51. if (wx.getUserProfile) {
    52. this.setData({
    53. canIUseGetUserProfile: true
    54. })
    55. }
    56. this.loadMeetInfos();
    57. },
    58. getUserProfile(e) {
    59. // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
    60. wx.getUserProfile({
    61. desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
    62. success: (res) => {
    63. console.log(res)
    64. this.setData({
    65. userInfo: res.userInfo,
    66. hasUserInfo: true
    67. })
    68. }
    69. })
    70. },
    71. getUserInfo(e) {
    72. // 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息
    73. console.log(e)
    74. this.setData({
    75. userInfo: e.detail.userInfo,
    76. hasUserInfo: true
    77. })
    78. }
    79. })

    utils/comm.wxs

    1. // /pages/comm.wxs
    2. function getStateName(state){
    3. if(state == 1){
    4. return "待审核"
    5. }else if(state == 2){
    6. return "审核通过"
    7. }else if(state == 3){
    8. return "审核不通过"
    9. }else if(state == 4){
    10. return "待开会议"
    11. }
    12. return "其他";
    13. }
    14. function getNum(canyuze,liexize,zhuchiren){
    15. var person = canyuze + "," + liexize + "," + zhuchiren
    16. return person.split(",").length;
    17. }
    18. function formatDate(ts, option) {
    19. var date = getDate(ts)
    20. var year = date.getFullYear()
    21. var month = date.getMonth() + 1
    22. var day = date.getDate()
    23. var week = date.getDay()
    24. var hour = date.getHours()
    25. var minute = date.getMinutes()
    26. var second = date.getSeconds()
    27. //获取 年月日
    28. if (option == 'YY-MM-DD') return [year, month, day].map(formatNumber).join('-')
    29. //获取 年月
    30. if (option == 'YY-MM') return [year, month].map(formatNumber).join('-')
    31. //获取 年
    32. if (option == 'YY') return [year].map(formatNumber).toString()
    33. //获取 月
    34. if (option == 'MM') return [mont].map(formatNumber).toString()
    35. //获取 日
    36. if (option == 'DD') return [day].map(formatNumber).toString()
    37. //获取 年月日 周一 至 周日
    38. if (option == 'YY-MM-DD Week') return [year, month, day].map(formatNumber).join('-') + ' ' + getWeek(week)
    39. //获取 月日 周一 至 周日
    40. if (option == 'MM-DD Week') return [month, day].map(formatNumber).join('-') + ' ' + getWeek(week)
    41. //获取 周一 至 周日
    42. if (option == 'Week') return getWeek(week)
    43. //获取 时分秒
    44. if (option == 'hh-mm-ss') return [hour, minute, second].map(formatNumber).join(':')
    45. //获取 时分
    46. if (option == 'hh-mm') return [hour, minute].map(formatNumber).join(':')
    47. //获取 分秒
    48. if (option == 'mm-dd') return [minute, second].map(formatNumber).join(':')
    49. //获取 时
    50. if (option == 'hh') return [hour].map(formatNumber).toString()
    51. //获取 分
    52. if (option == 'mm') return [minute].map(formatNumber).toString()
    53. //获取 秒
    54. if (option == 'ss') return [second].map(formatNumber).toString()
    55. //默认 时分秒 年月日
    56. return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
    57. }
    58. function formatNumber(n) {
    59. n = n.toString()
    60. return n[1] ? n : '0' + n
    61. }
    62. function getWeek(n) {
    63. switch(n) {
    64. case 1:
    65. return '星期一'
    66. case 2:
    67. return '星期二'
    68. case 3:
    69. return '星期三'
    70. case 4:
    71. return '星期四'
    72. case 5:
    73. return '星期五'
    74. case 6:
    75. return '星期六'
    76. case 7:
    77. return '星期日'
    78. }
    79. }
    80. module.exports = {
    81. getStateName: getStateName,
    82. getNum:getNum,
    83. formatDate:formatDate
    84. };

    index/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. <wxs src="/utils/comm.wxs" module="tools" />
    13. <view class="mobi-title">
    14. <text class="mobi-icon"></text>
    15. <text>会议信息</text>
    16. </view>
    17. <block wx:for-items="{{lists}}" wx:for-item="item" wx:key="item.id">
    18. <view class="list" data-id="{{item.id}}">
    19. <view class="list-img">
    20. <image class="video-img" mode="scaleToFill" src="{{item.image !=null ? item.image:'/static/persons/1.jpg'}}"></image>
    21. </view>
    22. <view class="list-detail">
    23. <view class="list-title"><text>{{item.title}}</text></view>
    24. <view class="list-tag">
    25. <view class="state">{{tools.getStateName(item.state)}}</view>
    26. <view class="join"><text class="list-num">{{tools.getNum(item.canyuze,item.liexize,item.zhuchiren)}}</text>人参与</view>
    27. </view>
    28. <view class="list-info"><text>{{item.location}}</text>|<text>{{tools.formatDate(item.starttime)}}</text></view>
    29. </view>
    30. </view>
    31. </block>
    32. <view class="section bottom-line">
    33. <text>到底啦</text>
    34. </view>

     效果展示

  • 相关阅读:
    根据文章段落内容自动插入图片php版
    【ESP 保姆级教程】疯狂Node.js服务器篇 ——案例:ESP8266 + 环境监测 +NodeJs本地服务+文件存储数据 + 钉钉/微信/飞书报警
    Android基础二:常见的几种组件
    在外包公司干了一年半软件测试的一些反思与总结
    [ZOOKEEPER]zookeeper基础知识笔记
    C语言-写一个简单的Web服务器(二)
    Docker部署ELK
    DFS之剪枝与优化
    BaGet搭建Nuget私仓(window10&docker)
    为什么Facebook运营需使用IP代理?有哪些美国IP代理好用?
  • 原文地址:https://blog.csdn.net/lijie1025/article/details/133958604