微信小程序宠物论坛4

微信小程序宠物论坛4微信小程序宠物论坛4帖子详情模块界面图JS部分//初始化数据化constdb=wx.cloud.database();constcont=db.collection(‘comment’);const_=db.commandPage({data:{value:”请输入评论…”,id:””,post:[],//帖子信息postid:””,//帖子IDtime:””,//时间content:”

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

Jetbrains全系列IDE稳定放心使用

微信小程序宠物论坛4

帖子详情模块

界面图
在这里插入图片描述
JS部分

// 初始化数据化
const db = wx.cloud.database();
const cont = db.collection('comment');
const _ = db.command
Page({
  data: {
    value:"请输入评论...",
    id:"",
    post:[],  //帖子信息
    postid: "" , //帖子ID
    time:"", //时间
    content:"",//内容
    userid:"",//发帖人的id
    heads:"",//头像
    nickname:"" ,//昵称
    collect:'', //收藏表返回
    collectid:'',//收藏表ID
  },

  // //下拉刷新加载数据
  // onPullDownRefresh: function () {
  //   wx.showNavigationBarLoading()
  //   wx.hideNavigationBarLoading();
  //   const _ = db.command
  //   const openid=this.data.openid
  //   const id=this.data.id
  //   // 查询收藏表
  //   db.collection('connection').where({
  //     _openid: openid,
  //     postid: id
  //   })
  //     .get({
  //       success: res => {
  //         console.log(res.data)
  //         this.setData({
  //           collect: res.data.length,
  //           collectid: res.data[0]._id
  //         })
  //         console.log(this.data.collect)
  //       },
  //       fail:res=>{
  //         console.log(res.data)
  //       }
  //     })
  //   setTimeout(function () {
  //     wx.hideNavigationBarLoading() //完成停止加载
  //     wx.stopPullDownRefresh() //停止下拉刷新
  //   }, 1500);
  // },
   
  handlecontentInput(e) {
    const value = e.detail.value
    this.data.content = value
  },

  onLoad: function (options) {
    // 获取用户openid
    wx.cloud.callFunction({
      name: "getopenid",
      success: res => {
         this.setData({
           openid: res.result.openid
         })
        console.log(res.result.openid)
      },
      fail(res) {
        console.log("获取openid失败")
      }
    })
    const openid = this.data.openid   //当前用户ID
    console.log(openid)

  // 获取评论用户的昵称和头像
    db.collection('user').where({
      _openid: openid
    })
      .get({
        success: res => {
          console.log(res.data)
          this.setData({
            nickname: res.data[0].nickname,
            heads: res.data[0].heads
          })
        }
      })

   
    this.setData({
      postid:options.id,
      id: options.id,
    }) 
  
   console.log(this.data.id)
   var id=this.data.id //当前帖子ID

    // 查询收藏表
    db.collection('connection').where({
      _openid: openid,
      postid:id
    })
      .get({
        success: res => {
          console.log(res.data)
          this.setData({
            collect:res.data.length,
            collectid:res.data[0]._id
          })
          console.log(this.data.collectid)
        }
      })

    // 查询当前帖子信息
    db.collection('post').where({
      _id: id
    })
    .get({
      success: res=>{
        console.log(res.data)
        this.setData({
          post: res.data,
          userid:res.data[0]._openid
        })
      }
    })

    //查询评论表
    wx.cloud.callFunction({
      name: 'getpost',
      data: {
        mark: 'getcomment',
        postid: this.data.postid
      }
    }).then(res => {
      console.log(res)
      this.setData({
        comment: res.result.data
      })
    }).catch(err => { })


  },
  //   db.collection('comment').where({
  //     postid: id
  //   })
  //     .get({
  //       success: res => {
  //         console.log(res.data)
  //         this.setData({
  //           comment: res.data,
  //         })
  //       }
  //     })
    
  //   this.setData({
  //     postid:id1
  //   })
  // },


  // 发表评论
  submit(e){
    const nickname=this.data.nickname
    const heads=this.data.heads
  
    var util = require('../../utils/util.js');
    const time = util.formatTime(new Date());
    this.setData({
      time: time
    });

    const content=this.data.content
    const postid = this.data.postid
    console.log(postid)
    const userid=this.data.userid
    
    if(content=='')
    {
      wx.showModal({
        title: '提示',
        content: '请先输入评论再发布',
        success(res) {
          if (res.confirm) {
            console.log('用户点击确定')
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    }
    else
    {
      // 将评论写入数据库
      db.collection('comment').add({
        data: {
          postid: postid,
          content: content,
          time: time,
          userid: userid,
          nickname: nickname,
          heads: heads,
          review:'0'
        },
        success: function (res) {
          wx.showToast({
            title: '发布成功,请等待审核',
            icon: 'success',
            mask: true,
            duration: 1000,
          })
        },
      })
 
      //查询评论表
      wx.cloud.callFunction({
        name: 'getpost',
        data: {
          mark: 'getcomment',
          postid: this.data.postid
        }
      }).then(res => {
        console.log(res)
        this.setData({
          comment: res.result.data
        })
      }).catch(err => { })

      // 将评论框中的信息置空
      this.setData({
        value:"请输入评论..."
      })

    }
  },

  // 收藏按钮
  collect(e){

    const postid=this.data.id
    console.log(postid)
    db.collection('connection').add({
      data: {
        postid:postid
      },
      success: function (res) {
        wx.showToast({
          title: '已收藏',
          icon: 'success',
          mask: true,
          duration: 1000,
        })
      }
    })


    // // 查询收藏表
    // const openid=this.data.openid
    // const id=this.data.id
    // db.collection('connection').where({
    //   _openid: openid,
    //   postid: id
    // })
    //   .get({
    //     success: res => {
    //       console.log(res.data)
    //       this.setData({
    //         collect: res.data.length,
    //         collectid: res.data[0]._id
    //       })
    //       console.log(this.data.collectid)
    //     }
    //   })
    this.setData({
      collect:1
    })
    

  },

  // 取消收藏按钮
  notcollect(e){
    const collectid = this.data.collectid //收藏表ID
    console.log(collectid)

    db.collection('connection').doc(collectid)
      .remove({
      success: function (res) {
        wx.showToast({
          title: '已取消收藏',
          icon: 'success',
          mask: true,
          duration: 1000,
        })
      }
    })
   this.setData({
     collect:0
   })
  }
})

WXML部分

<!-- 帖子显示 -->
<view class="post" wx:for="{
  
  {post}}" wx:key="post">

<!-- 标题 -->
<view class="title">
<text class="title">{
  
  {item.title}}</text>
</view>

<view wx:if="{
  
  {collect==0}}" >
<button class="collect" size="mini" bindtap="collect" plain='true'>收藏此贴</button>
</view>

<view wx:else>
<button class="notcollect" size="mini" bindtap="notcollect" plain='true'>已收藏</button>
</view>

<!-- 头像,昵称,时间 -->
<view class="userinfo" style="flex-direction:row;">
<image class="userinfo-avatar" src="{
  
  {item.heads}}" background-size="cover"></image>
<text decode="true" class="userinfo-nickname">&nbsp;&nbsp;{
  
  {item.nickname}}</text>
<text decode="true" class="userinfo-time">&nbsp;&nbsp;&nbsp;{
  
  {item.time}}</text>

</view>
<!-- 内容 -->
<view class="content">{
  
  {item.content}}</view>
<!-- 图片 -->
<view class="images" wx:for="{
  
  {item.images}}" wx:key="*this">
<image mode="heightFix" class="images-image" src="{
  
  {item}}"/>
</view>

</view>

<view class="hr"></view>



<!-- 显示评论 -->
<view class="showcomment" wx:for="{
  
  {comment}}" wx:key="comment" >
<image class="comment-avatar" src="{
  
  {item.heads}}" background-size="cover"></image>
<text class="comment-nickname" decode="true">&nbsp;&nbsp;&nbsp;{
  
  {item.nickname}}</text>
<text class="comment-time" decode="true">&nbsp;&nbsp;&nbsp;{
  
  {item.time}}</text>
<view class="comment-content">{
  
  {item.content}}</view>
<view class="line"></view>
</view>


<!-- 评论部分 --> 
<view class="comment">
<textarea class="textarea" value="{
  
  {value}}" placeholder-style="color:#b3b3b3;font-size:14px;" style="height: 12rem" maxlength="100" bindinput="handlecontentInput" bindblur="bindTextAreaBlur" auto-height />
<view class="line"></view>
<button class="besure" size="mini"  bindtap="submit" plain='true'>发布</button>
</view>

WXSS部分

.title{
  height: 100rpx
}
.title.title{
  text-align:center;
  font-size: 120%;
  font-weight:bold;
}

.userinfo{
  height:120rpx;
  padding-left:4.5%;
  padding-right:4.5%
}

.userinfo-avatar {
  width: 58rpx;
  height: 58rpx;
  border-radius: 50%;
}

.userinfo-nickname {
  font-weight:bold;
  font-size:75%;
  color: black;
  margin-bottom:30px;
}
.userinfo-time{
 font-size:65%;
 padding-bottom:40px
}

.content{
  padding-left:4.5%;
  padding-right:4.5%;
  height: 180rpx;
}
.images{                   
 justify-content: center; 
}
.line {
  border: 2px solid #ccc;
  opacity: 0.2;
}

.hr {
  width: 100%;
  height: 30px;
  background-color: #f4f5f6;
}

.showcomment{
  padding-left:4.5%;
  padding-right:4.5%;
}

.comment{
  padding-left:4.5%;
  padding-right:4.5%;
}
.besure{
  position:relative;
  left:550rpx;
}

.comment-avatar {
  width: 45rpx;
  height: 45rpx;
  border-radius: 50%;
}

.comment-nickname {
  font-weight:bold;
  font-size:75%;
  color: black;
}
.comment-time{
 font-size:65%;
}
.textarea{
margin-right: 200rpx;  
}

/* .collect{
  width: 42rpx;
  height: 42rpx;
  margin-top: 20rpx;
  background-color: white;
  color: #999999;
  border-radius: 0rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 30rpx;
}

.collect1 {
  width: 42rpx;
  height: 42rpx;
  position: relative;
  right:200rpx;
  top:20rpx
}

.collect::after {
  border: 0; 
} */

.collect{
  position: relative;
  left:60%;
  top:20%
}

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

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

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


相关推荐

  • 【SpringBoot】35、SpringBoot整合Redis监听Key过期事件「建议收藏」

    【SpringBoot】35、SpringBoot整合Redis监听Key过期事件「建议收藏」在实际的开发项目中,监听key的过期事件,应用非常广泛,例如:订单超时未支付,优惠券过期等等一、修改Redis配置文件1、在Redis的安装目录2、找到redis.windows.conf文件,搜索“notify-keyspace-events”修改为“notify-keyspace-eventsEx”,这样我们的Redis就支持key过期事件的监听了二、注入redisMessageListenerContainer注意:本偏文章衔接与上篇文章:【Sprin

    2022年9月23日
    0
  • android 混淆不起作用,Android代码混淆的写法总结

    android 混淆不起作用,Android代码混淆的写法总结Apk文件被反编译出来能被获取到里面的代码。对于这种情况,我们可以对项目代码进行混淆,随机生成难理解的类名,方法名,让代码难以阅读,加大功能被盗取的难度。混淆可以起到压缩Apk,混淆文件,预检,优化的作用。1.使用方式,在gradle文件中设置minifyEnabled为true即可开启混淆buildTypes{release{minifyEnabledture//是否开启代码混淆pro…

    2022年5月24日
    31
  • 圆柱表面积公式计算器_根据体重体表面积计算公式

    圆柱表面积公式计算器_根据体重体表面积计算公式【www.shanpow.com–在线新华字典】体积计算器在线计算篇(一):常用体积计算公式多面体的体积和表面积:有立方体计算公式、长方体∧棱柱∨计算公式、三棱柱计算公式、棱锥计算公式、棱台计算公式、圆柱和空心圆柱∧管∨计算公式、斜线直圆柱计算公式、直圆锥计算公式、圆台计算公式、球计算公式、球扇形∧球楔∨计算公式、球缺计算公式、圆环体∧胎∨计算公式、球带体计算公式、桶形计算公式、椭球体计算公式、…

    2022年9月15日
    1
  • 因果图分析法[通俗易懂]

    因果图分析法[通俗易懂]目录一、因果图法1.理解二、因果图需要掌握的基本知识1.关系2.约束3.输出条件的约束4.输出条件的约束5.原因和结果表示6.中间节点三、因果图设计测试用例的步骤四、优缺点1.优点2.缺点五、实例1.案例2.分析案例六、为什么要有中间节点1.无中间节点因果图2.有中间节点因果图一、因果图法1.理解因果图是一种简化了的逻辑图,能直观的表明程序输入条件(原因)和输出动作(结果)之间的相互关系; 因果图法是借助图形来设计测试

    2022年8月14日
    1
  • MacOS VSCode快捷键[通俗易懂]

    MacOS VSCode快捷键[通俗易懂]Macos下VSCode快捷键文章转载出处:http://www.cnblogs.com/informatics/全局Command+Shift+P/F1显示命令面板Command+P快速打开Command+Shift+N打开新窗口Command+W关闭窗口基本Command+X剪切(未选中文本的情况下,剪切光标所在行)Command+C复制(未选中文本的情况下,复制光标所在行)Option+Up向上移动行Option+D

    2022年6月4日
    148
  • DLL注入与安全

    DLL注入与安全伊始  安全与危险是共存的。如果我们了解危险的来源以及产生的过程,对于安全防护拥有很现实的意义。  本文主要介绍dll注入的方式,意在描述危险的来源,以及危险的执行的过程,以便于我们解决危险。主体这篇文章介绍2大类:序号方式1调用API2直接修改源码1.调用API  如果要实现注入,那么需要一个目标,一个DLL,一个注入程序。原理:  代码的执行…

    2022年5月16日
    49

发表回复

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

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