diff --git a/jiuyi2/api/video.js b/jiuyi2/api/video.js index 4d0e3609..7c449055 100644 --- a/jiuyi2/api/video.js +++ b/jiuyi2/api/video.js @@ -268,6 +268,19 @@ const video = { }) }, + /** + * 点赞/取消点赞评论 + * @param {Object} param + */ + likecomment(param) { + return util.request({ + url: `/video/comment/likecomment`, + data: param.data, + method: 'POST', + load: true, + }) + }, + /** * 热点视频 * @param {Object} param diff --git a/jiuyi2/components/index/commentArea.vue b/jiuyi2/components/index/commentArea.vue index abe3f041..da71a8a2 100644 --- a/jiuyi2/components/index/commentArea.vue +++ b/jiuyi2/components/index/commentArea.vue @@ -38,7 +38,7 @@ // 输入框为空时占位符 const placeholder = computed(() => { let result = '评论一下吧~' - if (reply.id) result = `回复 @${reply.userNickname}` + if (reply.id) result = `回复 @${reply.nickName}` return result }) // 填充高度 @@ -120,14 +120,17 @@ // api.video.savecomment({ data: { - // 视频父id - parentId: reply.id ? reply.id : 0, + // 评论的一级id + parentId: reply.childrenParentId || 0, // 视频id videoId: detail.id, // 评论内容 content: content.value, // 用户id userId: userinfo.value.id, + // 评论的父id + childrenParentId: reply.id || 0, + } }).then(rs => { console.log('saveComment', rs) @@ -173,9 +176,11 @@ /** * 回复对象 * @param {Object} item 回复的评论对象 + * @param {Object} childrenParentId 评论的一级id */ - function handleReply(item) { + function handleReply(item, childrenParentId) { Object.assign(reply, item) + reply.childrenParentId = childrenParentId proxy.$refs.comment.open() } @@ -215,17 +220,20 @@ */ function getLevelCommentList(item, index) { // - api.video.levelCommentList({ - query: { - commentId: item.id, + api.video.getcomment({ + data: { + // 视频id + videoId: item.videoId, + // 父节点id + parentId: item.id, pageSize: item.pageSize, pageNum: item.pageNum, } }).then(rs => { + console.log('getcomment', rs) if (rs.code == 200) { // 追加子列表 listProperty.data[index].child.push(...rs.rows.map(node => { - node.formatUserPortrait = util.format_url(node.userPortrait, 'img') return node })) // 展示列表 @@ -242,22 +250,40 @@ /** * 评论点赞 * @param {Object} item 视频对象 + * @param {Object} index 一级下标 + * @param {Object} secIndex 二级下标 */ - function handleLike(item) { + function handleLike(item, index, secIndex) { util.isLogin().then(rs => { // - api.video.thumbsUp({ - query: { + api.video.likecomment({ + data: { // 0取消 1点赞 - type: item.isLike ? 0 : 1, + likeType: { + '0': '1', + '1': '0', + } [item.likeType], // 评论id - commentId: item.id, + id: item.id, + // 视频id + videoId: detail.id, } }).then(rs => { if (rs.code == 200) { - if (item.isLike) item.likes-- - else item.likes++ - item.isLike = !item.isLike + // 点赞 + let obj = { + ...item, + ...rs.data, + } + + // 如果是一级 + if (secIndex == undefined) { + listProperty.data.splice(index, 1, obj) + } + // 如果是二级 + else { + listProperty.data[index].child.splice(secIndex, 1, obj) + } // listProperty.data = JSON.parse(JSON.stringify(listProperty.data)) return @@ -319,53 +345,61 @@ {{item.content}} - - - {{item.likes}} + {{item.createTime}} - + 回复 -