| | |
| | | <uni-popup ref="commentPopup" type="bottom" :is-mask-click="true" @maskClick="closeCommentPopup"> |
| | | <view class="comment-popup"> |
| | | <view class="popup-header"> |
| | | <text class="popup-title">评论({{comments.length}})</text> |
| | | <text class="popup-title">评论({{commentsTotal}})</text> |
| | | <text class="iconfont close-icon" @click="closeCommentPopup"></text> |
| | | </view> |
| | | |
| | |
| | | export default { |
| | | data() { |
| | | return { |
| | | commentNoMore: false, // 是否还有更多评论 |
| | | commentQuery: { |
| | | pageNumber: 1, |
| | | pageSize: 5, |
| | |
| | | replyId: null |
| | | }, |
| | | comments: [], // 评论列表 |
| | | commentsTotal: 0, // 评论总条数 |
| | | commentLoading: false, // 评论加载状态 |
| | | startHidenTime: 0, // 记录切换至其它页面的时间,用于计算视频观看时间减去的部分 |
| | | totalHidenTime: 0, // 总共隐藏页面的时间 |
| | |
| | | replyId: null |
| | | } |
| | | this.comments.unshift(res.data.data); |
| | | console.log("新增后",this.comments); |
| | | uni.showToast({ |
| | | title: '评论成功' |
| | | }); |
| | | // 当前视频评论数加一 |
| | | this.commentsTotal += 1; |
| | | this.videoList[this.currentIndex].commentNum += 1; |
| | | } else { |
| | | uni.showToast({ |
| | |
| | | }, |
| | | // 关闭评论弹窗 |
| | | closeCommentPopup() { |
| | | console.log("触发了"); |
| | | this.$refs.commentPopup.close() |
| | | this.showCommentPopup = false; |
| | | this.comments = []; |
| | |
| | | commentContent: '', |
| | | replyId: null |
| | | } |
| | | this.commentQuery.pageNumber = 1; |
| | | this.commentNoMore = false; |
| | | }, |
| | | // 下滑评论区加载评论 |
| | | async getCommentPage() { |
| | | this.commentQuery.pageNumber += 1; |
| | | if(this.commentNoMore) { |
| | | return; |
| | | } |
| | | getVideoComments(this.commentQuery).then(res => { |
| | | this.comments.push(res.data.data) |
| | | if(this.commentQuery.pageNumber === 1) { |
| | | this.comments = res.data.data |
| | | } else { |
| | | this.comments = [ |
| | | ...this.comments, |
| | | ...res.data.data.filter( |
| | | (newItem) => !this.comments.some((oldItem) => oldItem.id === newItem.id) |
| | | ), |
| | | ]; |
| | | } |
| | | if (res.data.data.length < this.commentQuery.pageSize) { |
| | | this.commentNoMore = true; |
| | | return; |
| | | } |
| | | this.commentQuery.pageNumber++; |
| | | }) |
| | | }, |
| | | // 显示评论弹窗 |
| | |
| | | this.commentLoading = true; |
| | | this.commentQuery.videoId = item.id |
| | | // 首次加载评论分页大小增加一倍,以产生滚动条,后续可触发 |
| | | this.commentQuery.pageSize *= 2; |
| | | getVideoComments(this.commentQuery).then(res => { |
| | | this.comments = res.data.data |
| | | this.commentsTotal = res.data.total; |
| | | this.comments = res.data.data; |
| | | this.commentQuery.pageNumber += 2; |
| | | this.commentQuery.pageSize /= 2; |
| | | }).catch(() => { |
| | | uni.showToast({ |
| | | title: '获取评论失败', |