bayi пре 2 година
родитељ
комит
5a4f33fd61

+ 4 - 0
api/video.js

@@ -15,6 +15,8 @@ module.exports = {
   getComment: data => request('/posts/reply', 'get', data),
   // 发布评论
   postReply: data => request('/posts', 'post', data),
+  // 删除评论
+  delPost: data => request('/posts', 'delete', data),
   // 回复评论
   ReplyComment: data => request('/reply', 'post', data),
   // 评论点赞
@@ -25,4 +27,6 @@ module.exports = {
   getLikeNotes: data => request('/likeLog', 'get', data),
   // 获取单条点赞记录
   getLikeNote: data => request(`/likeLog/one/${data}`, 'get'),
+  // 获取单条评论记录
+  getCommentNote: data => request(`/posts/one/${data}`, 'get'),
 }

+ 67 - 28
components/comment/index.js

@@ -3,8 +3,10 @@ import {
   postReply,
   ReplyComment,
   likeReply,
+  delPost,
   getLikeNotes,
-  getLikeNote
+  getLikeNote,
+  getCommentNote
 } from '~/api/video'
 import {
   setFans
@@ -24,9 +26,9 @@ Component({
     quickShow: true,
     type: 'comment',
     commentId: '',
-    totalSize: 0,
     firstData: {},
     list: [],
+    count: {},
     detailDesc: '',
     postId: '',
     postIndex: '',
@@ -35,7 +37,7 @@ Component({
     animation: {}
   },
   methods: {
-    open(columnId, type = 'comment', onceId) {
+    async open(columnId, type = 'comment', onceId) {
       console.log(columnId, type, onceId);
       // 背景遮罩层
       var animation = wx.createAnimation({
@@ -61,16 +63,30 @@ Component({
       } else {
         this.resetData()
       }
+      let r1 = await getComment({
+        columnId: this.data.columnId,
+        pageSize: 1
+      })
+      let r2 = await getLikeNotes({
+        userReadId: this.data.columnId,
+        pageSize: 1
+      })
+      this.setData({
+        count: {
+          commentNum: r1.totalSize,
+          likeNum: r2.totalSize
+        }
+      })
     },
     changeType({
       currentTarget
     }) {
       let type = currentTarget.dataset.type
       this.setData({
-        type
+        type,
+        firstData: {}
       })
       this.resetData()
-      console.log(currentTarget.dataset);
     },
     close() {
       this.setData({
@@ -90,26 +106,33 @@ Component({
       })
     },
     loadMore() {
-      if (this.data.type == 'like') {
-        this.getData((data) => {
-          return new Promise(async (reslove) => {
-            let res = await getLikeNotes(data)
-            if (this.data.firstData) {
-              res.list = res.list.filter(item => {
-                return item.id != this.data.firstData.id
-              })
-              res.list.unshift(this.data.firstData)
-            }
-            reslove(res)
-          })
-        }, {
-          userReadId: this.data.columnId,
-        })
-      } else {
-        this.getData(getComment, {
-          columnId: this.data.columnId,
+      this.getData((data) => {
+        return new Promise(async (reslove) => {
+          let res
+          if (this.data.type == 'comment') {
+            res = await getComment(data)
+            this.setData({
+              'count.commentNum': res.totalSize
+            })
+          } else if (this.data.type == 'like') {
+            res = await getLikeNotes(data)
+            this.setData({
+              'count.likeNum': res.totalSize
+            })
+          }
+          if (this.data.firstData.id) {
+            res.list = res.list.filter(item => {
+              return item.id != this.data.firstData.id
+            })
+            res.list.unshift(this.data.firstData)
+          }
+          reslove(res)
         })
-      }
+      }, this.data.type == 'comment' ? {
+        columnId: this.data.columnId
+      } : {
+        userReadId: this.data.columnId,
+      })
     },
     bindKeyInput(e) {
       this.setData({
@@ -117,7 +140,13 @@ Component({
       })
     },
     async topping(id) {
-      let res = await getLikeNote(id)
+      console.log(this.data.type);
+      let res
+      if (this.data.type == 'like') {
+        res = await getLikeNote(id)
+      } else {
+        res = await getCommentNote(id)
+      }
       console.log(res);
       this.setData({
         firstData: res
@@ -203,11 +232,21 @@ Component({
         url: `/pages/personal/index?uid=${currentTarget.dataset.uid}&type=user`,
       })
     },
-    onLongPress(e) {
+    onLongPress({
+      currentTarget
+    }) {
+      let {
+        id,
+        type
+      } = currentTarget.dataset
       wx.showActionSheet({
         itemList: ['删除评论'],
-        success(res) {
-          console.log(res.tapIndex)
+        success: async () => {
+          let res2 = await delPost({
+            id,
+            type
+          })
+          console.log(res2);
         },
       })
     },

+ 7 - 6
components/comment/index.wxml

@@ -4,9 +4,10 @@
   <view class="commentBg" catchtap="close" catchtouchmove="true"></view>
   <view class="comment {{tabBarPadding?'seat2':''}}" animation="{{animationData}}">
     <view class="header">
-      <view class="hl {{type=='comment'?'currentH':''}}" bindtap="changeType" data-type="comment">评论 {{totalSize}}
+      <view class="hl {{type=='comment'?'currentH':''}}" bindtap="changeType" data-type="comment">评论
+        {{count.commentNum}}
       </view>
-      <view class="hl {{type=='like'?'currentH':''}}" bindtap="changeType" data-type="like">赞 {{totalSize}}</view>
+      <view class="hl {{type=='like'?'currentH':''}}" bindtap="changeType" data-type="like">赞 {{count.likeNum}}</view>
       <view class=" hr" catchtap="close">×</view>
     </view>
     <scroll-view scroll-y="true" class="body" bindscrolltolower='loadMore' bindtap="cancelId">
@@ -17,13 +18,14 @@
             <view class="nickName">
               {{item.user.nickName||item.user.eid}}
             </view>
-            <view class="detailDesc" data-item='{{item}}' bind:longpress="onLongPress">
+            <view class="detailDesc" data-id='{{item.id}}' data-type='1' bind:longpress="onLongPress">
               {{item.detailDesc}}
             </view>
             <view class="replyList" wx:if="{{item.replyVOList.length>0}}">
               <view class="reply" wx:for="{{item.replyVOList}}" wx:for-item="reply" wx:key='id'>
                 <text class="replyTitle">{{reply.user.nickName||reply.user.eid}}</text>
-                <text class="replyContent">:{{reply.content}}</text>
+                <text class="replyContent" data-id='{{reply.id}}' data-type='2'
+                  bind:longpress="onLongPress">:{{reply.content}}</text>
               </view>
             </view>
             <view class="record">
@@ -49,8 +51,7 @@
               <view class="time">{{item.gmtCreated}}</view>
             </view>
             <view class="follow {{item.isFans?'isFans':''}}" bindtap="setFans">
-              <image src="{{item.isFans?'/static/follow_2.png':'/static/follow_3.png'}}" class="character"
-                mode="" />
+              <image src="{{item.isFans?'/static/follow_2.png':'/static/follow_3.png'}}" class="character" mode="" />
               <text class="text">{{item.isFans?'已关注':'关注'}}</text>
             </view>
           </view>

+ 7 - 0
mixins/video.js

@@ -88,6 +88,13 @@ module.exports = Behavior({
       target
     }) {
       console.log(target);
+      this.selectComponent('#comment').open(target.dataset.id)
+    },
+    // 打开设置类型的评论组件
+    openTypeComment({
+      target
+    }) {
+      console.log(target);
       this.selectComponent('#comment').open(target.dataset.id, target.dataset.type, target.dataset.onceId)
     },
     // 分享

+ 12 - 13
pages/comment/index.js

@@ -4,21 +4,16 @@ import {
 import {
   ReplyComment
 } from '~/api/video'
+import reachBottom from '~/mixins/reachBottom'
 Page({
-  data: {
-    list: []
-  },
-
-  /**
-   * 生命周期函数--监听页面加载
-   */
+  behaviors: [reachBottom],
+  data: {},
   onLoad(options) {
-    this.getNewComment()
+    this.resetData()
   },
-  async getNewComment() {
-    let list = await getNewComment()
-    this.setData({
-      list
+  loadMore() {
+    this.getData(getNewComment, {
+      pageSize: 20
     })
   },
   setReply({
@@ -55,8 +50,12 @@ Page({
   jumpWork({
     currentTarget
   }) {
+    let {
+      id,
+      commentlog
+    } = currentTarget.dataset
     wx.navigateTo({
-      url: `/pages/userWorks/index?id=${currentTarget.dataset.id}`,
+      url: `/pages/userWorks/index?id=${id}&onceId=${commentlog}&type=comment`,
     })
   },
 })

+ 4 - 3
pages/comment/index.wxml

@@ -1,7 +1,8 @@
 <view class="commentPage">
-  <view class="notes" wx:for="{{list}}" wx:key="index" data-id='{{item.userRead.id}}' bindtap="jumpWork">
-    <view class="redDrop"></view>
-    <image src="{{item.user.avatar}}" class="avatar" data-uid='{{item.user.uid}}' catchtap="jumpUserInfo" />
+  <view class="notes" wx:for="{{list}}" wx:key="index" data-id='{{item.userRead.id}}'
+    data-commentlog="{{item.posts.id}}" bindtap="jumpWork">
+    <view class="redDrop" wx:if="{{!item.posts.readStatus}}"></view>
+    <image src=" {{item.user.avatar}}" class="avatar" data-uid='{{item.user.uid}}' catchtap="jumpUserInfo" />
     <view class="body">
       <view class="nickName">{{item.user.nickName||item.user.eid}}</view>
       <view class="date">

+ 1 - 5
pages/like/index.js

@@ -4,10 +4,7 @@ import {
 import reachBottom from '~/mixins/reachBottom'
 Page({
   behaviors: [reachBottom],
-  data: {
-    list: [],
-    url:"https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MzIzNDY1NTgyNAMzIzNDY1NTgyNA==#wechat_redirect"
-  },
+  data: {},
   onShow(options) {
     this.resetData()
   },
@@ -26,7 +23,6 @@ Page({
   jumpWork({
     currentTarget
   }) {
-    console.log(currentTarget.dataset);
     let {
       id,
       likelog

+ 2 - 2
pages/userWorks/index.js

@@ -16,10 +16,10 @@ Page({
     if (options.id) {
       this.getreadInfo(options.id)
       wx.nextTick(() => {
-        this.selectComponent('#worksList').openComment({
+        this.selectComponent('#worksList').openTypeComment({
           target: {
             dataset: {
-              type: 'like',
+              type: options.type,
               onceId: options.onceId,
               id: options.id
             }