| | |
| | | </view> |
| | | |
| | | <!-- 示例评论项,comment-item 可替换为实际组件 --> |
| | | <comment-item v-for="(item, index) in commentList" :avatar="item.picture" |
| | | :nickname="item.commentUserName" :isAuthor="item.createBy === filmInfo.createBy" |
| | | :content="item.content" :images="getImageList(item)" :date="item.createTime" address="湖北" |
| | | :likes="item.likeCount" :child="item.child" :filmInfo="filmInfo" @reply="showCommentLayer" /> |
| | | <!-- <comment-item v-for="(item, index) in commentList" :avatar="item.picture"--> |
| | | <!-- :nickname="item.commentUserName" :isAuthor="item.createBy === filmInfo.createBy"--> |
| | | <!-- :content="item.content" :images="getImageList(item)" :date="item.createTime" address="湖北"--> |
| | | <!-- :likes="item.likeCount" :child="item.child" :filmInfo="filmInfo" @reply="showCommentLayer" />--> |
| | | <comment-item |
| | | v-for="(item, index) in commentList" |
| | | :avatar="item.picture" |
| | | :nickname="item.commentUserName" |
| | | :isAuthor="item.createBy === filmInfo.createBy" |
| | | :content="item.content" |
| | | :images="getImageList(item)" |
| | | :date="item.createTime" |
| | | address="湖北" |
| | | :likes="item.likeCount" |
| | | :isLiked="item.isLike" |
| | | :id="item.id" |
| | | :child="item.child" |
| | | :filmInfo="filmInfo" |
| | | @reply="(id) => showCommentLayer(id)" |
| | | @like="handleCommentLike" |
| | | /> |
| | | </view> |
| | | </scroll-view> |
| | | |
| | |
| | | }) |
| | | } |
| | | |
| | | const showCommentLayer = () => { |
| | | // film-detail.vue |
| | | const showCommentLayer = (parentId?: number) => { |
| | | console.log('点击了评论按钮',parentId) |
| | | commentShow.value = true |
| | | // 如果有parentId,说明是回复评论,需要设置parentId |
| | | // 如果没有parentId,说明是直接评论,不需要设置parentId |
| | | commentParendId.value = parentId ? String(parentId) : '' |
| | | } |
| | | |
| | | const handleCommentSuccess = (data) => { |
| | | // 例如重新请求评论列表 |
| | | // fetchCommentList(); |
| | | // 重新获取评论列表 |
| | | getCommentList(filmId.value) |
| | | commentShow.value = false |
| | | commentParendId.value = '' // 清除父评论ID |
| | | }; |
| | | |
| | | onShow(() => { |
| | | |
| | | }); |
| | | |
| | | // 处理评论点赞 |
| | | const handleCommentLike = async (commentId: number) => { |
| | | console.log('点击了评论点赞', commentId) |
| | | try { |
| | | const res = await $http.request('post', '/v2/comment-likes/commentLikes/edit', { |
| | | data: { commentId } |
| | | }) |
| | | |
| | | if (res.code === 0) { |
| | | // 更新评论列表中的点赞状态和数量 |
| | | const updateCommentLike = (comments: CommentDTO[]) => { |
| | | comments.forEach(comment => { |
| | | if (comment.id === commentId) { |
| | | comment.isLike = !comment.isLike |
| | | comment.likeCount += comment.isLike ? 1 : -1 |
| | | } |
| | | if (comment.child && comment.child.length > 0) { |
| | | updateCommentLike(comment.child) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | updateCommentLike(commentList.value) |
| | | // 根据当前点赞状态显示对应提示 |
| | | const comment = findCommentById(commentList.value, commentId) |
| | | $message.showToast(comment?.isLike ? '点赞成功' : '取消点赞') |
| | | } |
| | | } catch (error) { |
| | | console.error('评论点赞失败:', error) |
| | | $message.showToast('操作失败') |
| | | } |
| | | } |
| | | |
| | | // 添加一个辅助函数来查找评论 |
| | | const findCommentById = (comments: CommentDTO[], id: number): CommentDTO | undefined => { |
| | | for (const comment of comments) { |
| | | if (comment.id === id) { |
| | | return comment |
| | | } |
| | | if (comment.child && comment.child.length > 0) { |
| | | const found = findCommentById(comment.child, id) |
| | | if (found) return found |
| | | } |
| | | } |
| | | return undefined |
| | | } |
| | | |
| | | const filmInfo = ref<FilmInfo>() |
| | | |
| | | const filmPictureList = ref<string[]>([]) |