我的校园服务小程序_有创意校园的微信小程序

我的校园服务小程序_有创意校园的微信小程序微信小程序——校园服务小程序(四)校园论坛加预约理发服务上一篇介绍了如何用户如何将帖子的内容发送到数据库中。这次我们来介绍一下如何将库中数据渲染出来,通过get得到对应表的数据,在wxml上通过for循环渲染数据表中的值。这里以我们的主页面为例,首先思考一下,一个展示帖子的主页面要有什么功能,1.帖子在添加时会将新的帖子放在最后,再渲染时也会被渲染在后面,这样是不可以的,每一次进入界面都是第一个用户上传的帖子。这里我们需要对帖子进行一次排序,这里我使用了orderBy(‘timeone’,‘d

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

微信小程序——校园服务小程序(四)校园论坛加预约理发服务

上一篇介绍了如何用户如何将帖子的内容发送到数据库中。

这次我们来介绍一下如何将库中数据渲染出来,

通过get得到对应表的数据,在wxml上通过for循环渲染数据表中的值。

这里以我们的主页面为例,

首先思考一下,一个展示帖子的主页面要有什么功能,

1.帖子在添加时会将新的帖子放在最后,再渲染时也会被渲染在后面,这样是不可以的,每一次进入界面都是第一个用户上传的帖子。

这里我们需要对帖子进行一次排序,这里我使用了orderBy(‘timeone’,‘desc’),进行排序,第一个参数是排列规则的属性,第二个参数是代表倒序。

上拉刷新功能也是比不可少的,在这里叶别忘了排序,不然刷新后会将比较久远的帖子重新刷新在上方。

由于小程序一页只允许有20,所以触底刷新也是有必要的。

我们使用skip(常用于分页),变量page及concat,来实现触底刷新,skip:指定查询返回结果时从指定序列后的结果开始返回,page:储存着当前的页面数,concat:负责连接新数据和旧数据。

同时点击帖子应该进入详情界面,这里我们应该在这里统计一下点击量,非常简单,在跳转按钮对应的点击事件方法中,将库中的点击属性数加一。(inc)

下面是源码:

//js
// pages/home/home.js
const db = wx.cloud.database()
const lbtCollection = db.collection('lbt')
const nowdayCollection = db.collection('nowday')
//const marketCollection = db.collection('market')
//const lostcomeCollection = db.collection('lostcome')
const loveCollection = db.collection('love')
const peopleCollection = db.collection('people')
const _ = db.command
Page({ 
   
  data: { 
   
    page:0,
    open:false,
    loadingHidden:true,
    xindex: 0,

   },
   

   onChange(event) { 
   
    // event.detail 为当前输入的值
    console.log(event.detail);
  },

  onChange: function (e) { 
   
    this.setData({ 
   
      xindex: e.detail.current
    });
  },
  golbtindex(event){ 
   
    let loveid=event.currentTarget.dataset.id
    wx.navigateTo({ 
   
      url: '../lbtindex/lbtindex?loveid='+loveid,//添加页面参数以保证跳转到对应的页面
    })
  },
  onLoad: function() { 
   
    this.setData({ 
   
      loadingHidden: false
     });
    lbtCollection.get().then(res =>{ 
   
      this.setData({ 
   
        lbt: res.data
      })
    })//从数据库中获取数据
    nowdayCollection.orderBy('timeone','desc').get().then(res =>{ 
   
      this.setData({ 
   
        nowday: res.data
      })
      console.log(res);
    }).then(res=>{ 
   
      console.log("校园趣事");
      this.setData({ 
   
        loadingHidden: true
       });
    })
    loveCollection.orderBy('timeone','desc').get().then(res =>{ 
   
      this.setData({ 
   
        love: res.data
      })
      console.log(res);
    }).then(res=>{ 
   
      console.log("表白墙获取成功");
      this.setData({ 
   
        loadingHidden: true
       });
    })
    peopleCollection.get().then(res =>{ 
   
      this.setData({ 
   
        people: res.data
      })
      console.log(res);
    }).then(res=>{ 
   
      console.log("用户获取成功");
      this.setData({ 
   
        loadingHidden: true
       });
    })
  },
  //下拉刷新 注意:要在json中声明"enablePullDownRefresh":true,
  onPullDownRefresh:function(){ 
   
    nowdayCollection.orderBy('timeone','desc').get().then(res =>{ 
   
      this.setData({ 
   //获取数据
        nowday: res.data
      },res =>{ 
   
        console.log("数据更新完成");
        wx.stopPullDownRefresh()//获取数据完成后立即缩回
      })
    })
    loveCollection.orderBy('timeone','desc').get().then(res =>{ 
   
      this.setData({ 
   //获取数据
        love: res.data
      },res =>{ 
   
        console.log("数据更新完成");
        wx.stopPullDownRefresh()//获取数据完成后立即缩回
      })
    })
  },
  //页面上拉触底事件处理函数
  onReachBottom:function(){ 
   
    console.log("触底了");
    let page=this.data.page+20;
    console.log(page);
    nowdayCollection.skip(page).get().then(res =>{ 
   
      let new_data=res.data
      let old_data=this.data.nowday
      this.setData({ 
   //获取数据
        nowday: old_data.concat(new_data),
        paga:page
      },res =>{ 
   
        console.log(res,"触底刷新成功");
    })
  })
    loveCollection.skip(page).get().then(res =>{ 
   
      let new_data=res.data
      let old_data=this.data.love
      this.setData({ 
   //获取数据
        love: old_data.concat(new_data),
        page:page
      },res =>{ 
   
        console.log(res);
    })
  })
},
click:function(event){ 
   //点击量更新
  loveCollection.doc(event.currentTarget.dataset.id).update({ 
   
    data: { 
   
      view:_.inc(1)
    }
  })
},
  gosend(){ 
   
    wx.navigateTo({ 
   
      url: '../sendin/sendin',
    })
  },
  gochoose(){ 
   
    wx.navigateTo({ 
   
      url: '../allchoose/allchoose',
    })
  },
  goid(event){ 
   
    nowdayCollection.doc(event.currentTarget.dataset.id).get().then(res =>{ 
   
      //let age='' 
      this.setData({ 
   
        nowday: res.data
      })
      wx.setStorageSync('oldcomeid', res.data._id)//将数据导入缓存
      console.log(res);
      let textid=event.currentTarget.dataset.id
      console.log(event,"evnet内容");
      //console.log(event.currentTarget.dataset.id);
      console.log(textid);
      wx.cloud.callFunction({ 
   
        name:"viewnum1",
        data:{ 
   
          id:event.currentTarget.dataset.id,
          selectsql:"nowday"
        }
      }).then(res=>{ 
   
        console.log(res);
      })
      // nowdayCollection.doc(event.currentTarget.dataset.id).update({ 
   
      // data: { 
   
      // view:_.inc(1)
      // }
      // })
      wx.navigateTo({ 
   
        url: '../textindex/textindex?textid='+textid,//添加页面参数以保证跳转到对应的页面
      })
    })//从数据库中获取数据
  },
  goloveindex(event){ 
   
    loveCollection.doc(event.currentTarget.dataset.id).get().then(res =>{ 
   
      //let age='' 
      this.setData({ 
   
        love: res.data
      })
      // wx.setStorageSync('oldcomeid', res.data._id)//将数据导入缓存
      console.log(res);
      let loveid=event.currentTarget.dataset.id
      //console.log(event.currentTarget.dataset.id);
      console.log(loveid);
      wx.cloud.callFunction({ 
   
        name:"viewnum1",
        data:{ 
   
          id:event.currentTarget.dataset.id,
          selectsql:"love"
        }
      }).then(res=>{ 
   
        console.log(res);
      })
      // loveCollection.doc(event.currentTarget.dataset.id).update({ 
   
      // data: { 
   
      // view:_.inc(1)
      // }
      // })
      wx.navigateTo({ 
   
        url: '../loveindex/loveindex?loveid='+loveid,//添加页面参数以保证跳转到对应的页面
      })
    })//从数据库中获取数据
  },
  searchall(){ 
   
    wx.navigateTo({ 
   
      url: '../search/search', //添加页面参数以保证跳转到对应的页面
    })
  },
  onShow: function () { 
   
    if(typeof this.getTabBar==='function' && this.getTabBar()){ 
   
      this.getTabBar().setData({ 
   
        selected:0
      })
    }

    this.onLoad();
    },
})
//wxml
<!--pages/home/home.wxml-->
<!-- <block>
<view class="view_1">
  <van-button class="search_1" round type="default" block bind:click="navigateToSearch">搜索</van-button>
</view>
<view>
  <view class="index_swiper">
    <swiper class="swiper_1" autoplay indicator-dots circular>
      <swiper-item
      wx:for="{ 
   {lbt}}"
      wx:key="_id"
      ><!-- -->
        <!-- 图片标签
        mode属性
          widthFix 让图片等比例自适应
      --> 
        <!-- <navigator>
          <image mode="widthFix" src="{ 
   {item.image}}"></image>
        </navigator>
      </swiper-item> 
    </swiper>
  </view> -->


  <block class="page-top { 
   {open ? ['c-state','cover'] : ''}} ">
  <van-search
  value="{ 
   { value }}"
  shape="round"
  background="#576b95"
  placeholder="请输入搜索关键词"
  bindtap="searchall"
/>
<view>
  <view class="container">
    <swiper class='bannerSwiper' previous-margin="54rpx" next-margin='54rpx' indicator-dots="true" indicator-color='#B5B5B5' indicator-active-color='#fff' interval='3000' duration='500' bindchange='onChange' circular='true' autoplay="{ 
   {true}}">
      
        <swiper-item wx:for="{ 
   {lbt}}"
      wx:key="_id">
          <image bindtap="golbtindex" data-id="{ 
   {item._id}}" class="{ 
   {index==xindex?'imageBanner':'imageBanner_small'}}" data-index="{ 
   {index}}" data-item="item" src="{ 
   {item.image}}">   
          </image>
        </swiper-item>
     
    </swiper>
    </view>
   </view>
  <!-- <button bindtap="gochoose">更多分类</button> -->
  <view class="tab_homefenlei">
    <!-- <view class="tab_fenlei"> -->
<image src="../../icons/felei.png" class="tab_fenleiimage" bindtap="gochoose"></image>
<!-- <view class="textqushi">更多分类</view> -->
<!-- </view> -->
<view>分类</view>
  </view>
  <view class="tab_homezhongjian">
    <view class="tab_homequshi">
      <view class="tab_xiaoyuan" >
      <image src="../../icons/xiaoyuanquanzi.png" class="tab_xiaoyuanimage" ></image>
      <view class="textqushi">校 园 趣 事</view>
    </view>
    </view>
    <view class="tab_homekaobai">
      <view class="tab_kaobai">
      <image src="../../icons/xiaogaobai.png" class="tab_kaobaiimage"></image>
      <view class="textqushi">告 白 墙</view>
    </view>
    </view>
  </view>


<view class="vw_home1">
  <view style="flex:1;height:4000px" class="vw_h2">
    <view wx:for="{ 
   {nowday}}"  class="vw_imag1" bindtap="goid" data-id="{ 
   {item._id}}">
      <image src="{ 
   {item.pages}}" mode="widthFix" class="image1"></image>
      <view class="vw_tx1">
          <text wx:if="{ 
   {item.title!=''}}">{ 
   { 
   item.title}}</text>
          <text wx:else>标题都么得有</text>
      </view>
      <view class="home_vwimage">
        <image class="home_image1" src="{ 
   {item.wxpages}}"></image>
        <text class="home_text1">{ 
   { 
   item.wxtitle}}</text>
        <!-- <view>{ 
   { 
   item.shenfen}}</view> -->
        <view wx:if="{ 
   {item.shenfen=='教师'}}" >
      <view class="shenfeijiaos">{ 
   { 
   item.shenfen}}</view>
        </view>
      <block wx:else>
        <view class=xueshen">{ 
   { 
   item.shenfen}}</view></block>
      </view>
      <view class="lldzpl">
        <view><image class="lielanimage" src="../../icons/looking.png"></image><text class="tx_lielan"> { 
   { 
   item.view}}</text></view>
        <view><image class="dainzhanimage" src="../../icons/like.png"></image><text class="tx_xihua">{ 
   { 
   item.good}}</text></view>
        <view><image class="pinlunimage" src="../../icons/comment.png"></image><text class="tx_pinlun">{ 
   { 
   item.sendyou}}</text></view>
      </view>
    </view>
  </view>
  <view style="flex:1;height:4000px" class="vw_h3">
    <view wx:for="{ 
   {love}}" class="vw_imag2" bindtap="goloveindex" data-id="{ 
   {item._id}}">
      <image src="{ 
   {item.pages}}" mode="widthFix" class="image2"></image>
      <view class="vw_tx2">
        <text wx:if="{ 
   {item.title!=''}}">{ 
   { 
   item.title}}</text>
          <text wx:else>标题都么得有</text>
      </view>
      <view class="home_vwimage">
        <image class="home_image1" src="{ 
   {item.wxpages}}"></image>
        <text class="home_text1">{ 
   { 
   item.wxtitle}}</text>
        <view wx:if="{ 
   {item.shenfen=='教师'}}" >
      <view class="shenfeijiaos">{ 
   { 
   item.shenfen}}</view>
        </view>
      <block wx:else>
        <view class=xueshen">{ 
   { 
   item.shenfen}}</view></block>
      </view>
      <view class="lldzpl">
        <view><image class="lielanimage" src="../../icons/looking.png"></image><text class="tx_lielan"> { 
   { 
   item.view}}</text></view>
        <view><image class="dainzhanimage" src="../../icons/like.png"></image><text class="tx_xihua">{ 
   { 
   item.good}}</text></view>
        <view><image class="pinlunimage" src="../../icons/comment.png"></image><text class="tx_pinlun">{ 
   { 
   item.sendyou}}</text></view>
      </view>
    </view>
  </view>

  </view>
</block>
<loading hidden="{ 
   {loadingHidden}}">
 加载中...
</loading>




版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/191273.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 一个基于SpringBoot+vue的学生信息管理系统详细设计

    一个基于SpringBoot+vue的学生信息管理系统详细设计主要功能:用户登录、用户管理、角色、菜单、灵活控制、sql监控、日志、老师、学生、班级、课程、选课、打分、成绩、新闻、通知公告、附件查看下载等功能

    2022年10月17日
    1
  • 非阻塞connect errno为EINPROGRESS,如何判断已经连接上了?[通俗易懂]

    非阻塞connect errno为EINPROGRESS,如何判断已经连接上了?[通俗易懂]via:http://stackoverflow.com/questions/8145624/getpeername-can-not-recognize-connection-established

    2022年7月16日
    11
  • 3D点云综述[通俗易懂]

    3D点云综述[通俗易懂]24页3D点云综述,共计214篇参考文献,涵盖3D形状分类,3D目标检测和跟踪,3D点云分割方向和大数据集。

    2022年6月5日
    159
  • MATLAB 循环语句_for循环matlab

    MATLAB 循环语句_for循环matlabMatlab的循环语法1、用循环方式实现从1到999的累加2、(1)、for循环方式实现: %% %初始化sum的值为0 sum=0; %从1开始遍历到999 fori=1:999 %对遍历的每一个元素进行累加 sum=sum+i; end %在控制台显示结果 disp(sum); (…

    2022年9月26日
    0
  • 书包网小说多线程爬虫[通俗易懂]

    书包网小说多线程爬虫[通俗易懂]书包网是个很好的小说网站,提供了小说txt下载,并且网站后端高并发,不用担心随便抓一下把网站抓崩了既然如此,何不拿来练手爬虫项目呢。直接上代码把,此多线程爬虫支持爬取各种这样类似的网站,关键需要网站支持高并发,否则分分钟崩了。毕竟5分钟一本18mb的小说,属于超级快的那种了fromlxmlimportetreeimportrequestsfromthreadi…

    2022年6月15日
    30
  • 二叉树的一些性质图解

    二叉树的一些性质图解树的介绍1.树的定义树是一种数据结构,它是由n(n&gt;=1)个有限节点组成一个具有层次关系的集合。把它叫做“树”是因为它看起来像一棵倒挂的树,也就是说它是根朝上,而叶朝下的。它具有以下的特点:(01)每个节点有零个或多个子节点;(02)没有父节点的节点称为根节点;(03)每一个非根节点有且只有一个父节点;(04)除了根节点外,每个子节点可以分为多个不相交的子树。 2.树的基本术语若…

    2022年5月20日
    34

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号