评论的组件封装

2024-09-06 05:52
文章标签 封装 组件 评论

本文主要是介绍评论的组件封装,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

在这里插入图片描述
在这里插入图片描述

主评论的人在数组第一层级,回复的评论都在children里面

【{
name:"张三"
idGenerator: 475403892531269
info_Conmment":"今天天气晴朗😀"
children:[
{
mainIdGenerator:475388950118469
name:"张三"
name1:"李四"
idGenerator:475403933356101
info_Conmment:"哈哈哈哈"
}
]
}】
<template><divstyle="margin: 20px; margin-top: 40px"v-if="route.query.isComment == 'true' || props.isComment"><p style="font-size: 18px; color: #1d2129"><el-dividerstyle="width: 3px; height: 18px; background: #2c68ff; margin-left: 0px"direction="vertical"/>{{$t('view.course.comment')}}:</p><el-form :model="commentForm"><!-- maxlength="1000"show-word-limit --><el-form-item><el-inputv-model="commentForm.commentText":rows="3"type="textarea"maxlength="150"@input="handleInput(commentForm.commentText)":placeholder="$t('view.course.add_comment')"></el-input><div class="commentOperate"><div class="numberLimit">还能输入<span class="remainingCount">{{ remainingCount }}</span>个字符</div><div class="comment-operate-item"><VueEmoji @chooseEmoji="chooseEmoji" /><el-button class="commentBtn" type="primary" @click="userCommont">评论</el-button></div></div></el-form-item></el-form><!-- 评论列表 --><div v-if="comments.length > 0"><divv-for="(comment, index) in comments":key="comment.idGenerator"style="margin-top: 12px;border-bottom: 1px #f4f3f3;display: flex;align-items: flex-start;"><el-avatar:size="40"style="margin-right: 12px; margin-left: 10px":src="comment.avatarUrl || profile"></el-avatar><div style="flex: 1"><span style="font-size: 16px">{{ comment.name }}</span><p>{{ comment.info_Conmment }}</p><p style="font-size: 12px; color: #86909c; margin-top: 5px">{{ comment.createdTime }}<el-buttonlinkstyle="font-size: 12px; color: #86909c"@click="toggleLikeComment(comment.idGenerator, comment.isThumbsUp)"><!-- <svg-icon:icon-class="getCommentIconClass(comment.idGenerator)":src="getCommentIconSrc(comment.idGenerator)"class="svg-icon"style="margin-left: 20px;margin-right: 3px;transform: translateY(-1px);":class="{ liked: isCommentLiked(comment.idGenerator) }"/> --><svg-icon:icon-class="getCommentzanIconClass(comment.isThumbsUp)":src="getCommentzanIconSrc(comment.isThumbsUp)"class="svg-icon"style="margin-left: 20px;margin-right: 3px;transform: translateY(-1px);"/><span v-if="comment.thumbsUpCount > 0">{{comment.thumbsUpCount}}</span>{{ $t('view.course.like') }}</el-button><el-buttonlinkstyle="font-size: 12px; color: #86909c"@click="toggleReply(comment.idGenerator)"><el-icon style="margin-right: 3px; font-size: 16px"><ChatLineSquare /></el-icon>{{ $t('view.course.reply') }}</el-button><el-dropdown trigger="click"><template #default><span><el-button link><el-iconstyle="margin-left: 12px;color: #4e5969;font-size: 12px;transform: translateY(4px);"><MoreFilled /></el-icon></el-button></span></template><template #dropdown><el-dropdown-menu><el-dropdown-item @click="deleteComment(comment.idGenerator)">删除评论</el-dropdown-item><el-dropdown-item><el-dropdown trigger="hover" placement="right-start"><span>禁言<el-iconstyle="transform: translateY(3px); margin-left: 20px"><ArrowRight /> </el-icon></span><template #dropdown><el-dropdown-menu><el-dropdown-item @click="banUserHour(comment.id)">一个小时</el-dropdown-item><el-dropdown-item @click="banUserDay(comment.id)">一天</el-dropdown-item><el-dropdown-item @click="banUserWeek(comment.id)">一周</el-dropdown-item><el-dropdown-item @click="banUserForever(comment.id)">永久</el-dropdown-item></el-dropdown-menu></template></el-dropdown></el-dropdown-item></el-dropdown-menu></template></el-dropdown></p><!-- <el-inputv-if="showReplyInput[comment.id]"v-model="replyTexts[comment.id]"type="textarea"placeholder="说点什么吧"rows="4"maxlength="150"show-word-limitstyle="margin-top: 10px"/> --><el-form v-if="showReplyInput[comment.idGenerator]"><el-form-item class="childrenForm"><el-inputv-model="replyTexts[comment.idGenerator]":rows="3"type="textarea"maxlength="150"@input="handleInput(replyTexts[comment.idGenerator],comment.idGenerator)":placeholder="$t('view.course.add_comment')"></el-input><div class="commentOperate"><div class="numberLimit">还能输入<span class="remainingCount">{{remainCount[comment.idGenerator]}}</span>个字符</div><div class="comment-operate-item"><VueEmoji@chooseEmoji="chooseEmoji":replyComment="replyTexts[comment.idGenerator]":keyId="comment.idGenerator"/><el-buttonclass="commentBtn"type="primary"@click="userChildrenCommont(comment)">评论</el-button></div></div></el-form-item></el-form><!-- 子评论列表 --><divv-for="(reply, replyIndex) in comment.children":key="reply.id"style="margin-top: 12px"><divstyle="margin-top: 12px;border-bottom: 1px #f4f3f3;display: flex;align-items: flex-start;"><el-avatar:size="30":src="reply.avatarUrl || profile"style="margin-right: 12px"></el-avatar><div style="flex: 1"><span>{{ reply.name || "0713" }}</span><span style="margin-left: 10px; color: #86909c">{{ $t('view.course.reply') }}</span><span style="margin-left: 10px; margin-right: 10px">{{ reply.name1 }}:{{ reply.info_Conmment }}</span><p style="font-size: 12px; color: #86909c; margin-top: 5px">{{ reply.createdTime }}<el-buttonlinkstyle="font-size: 12px; color: #86909c"@click="toggleLikeComment(reply.idGenerator, reply.isThumbsUp)"><!-- <svg-icon:icon-class="getReplyIconClass(comment.id, reply.id)":src="getReplyIconSrc(comment.id, reply.id)"class="svg-icon"style="margin-left: 20px;margin-right: 3px;transform: translateY(-1px);":class="{ liked: isReplyLiked(comment.id, reply.id) }"/> --><svg-icon:icon-class="getCommentzanIconClass(reply.isThumbsUp)":src="getCommentzanIconSrc(reply.isThumbsUp)"class="svg-icon"style="margin-left: 20px;margin-right: 3px;transform: translateY(-1px);"/><span v-if="reply.thumbsUpCount > 0">{{reply.thumbsUpCount}}</span>点赞                  </el-button><el-buttonlinkstyle="font-size: 12px; color: #86909c"@click="toggleReply(reply.idGenerator)"><el-icon style="margin-right: 3px; font-size: 16px"><ChatLineSquare /></el-icon>回复</el-button><el-dropdown trigger="click"><template #default><span><el-button link><el-iconstyle="margin-left: 12px;color: #4e5969;font-size: 12px;transform: translateY(4px);"><MoreFilled /></el-icon></el-button></span></template><template #dropdown><el-dropdown-menu><el-dropdown-item@click="deleteComment(reply.idGenerator)">删除评论</el-dropdown-item><el-dropdown-item><el-dropdown trigger="hover" placement="right-start"><span>禁言<el-iconstyle="transform: translateY(3px);margin-left: 20px;"><ArrowRight /> </el-icon></span><template #dropdown><el-dropdown-menu><el-dropdown-item@click="banUserHour(comment.id)">一个小时</el-dropdown-item><el-dropdown-item@click="banUserDay(comment.id)">一天</el-dropdown-item><el-dropdown-item@click="banUserWeek(comment.id)">一周</el-dropdown-item><el-dropdown-item@click="banUserForever(comment.id)">永久</el-dropdown-item></el-dropdown-menu></template></el-dropdown></el-dropdown-item></el-dropdown-menu></template></el-dropdown></p><!-- <el-inputv-if="showReplyInput[reply.id]"v-model="replyTexts[reply.id]"type="textarea":placeholder="$t('view.course.add_comment')"rows="3"maxlength="150"show-word-limitstyle="margin-top: 10px"/> --><el-form><el-form-itemclass="childrenForm"v-if="showReplyInput[reply.idGenerator]"><el-inputv-model="replyTexts[reply.idGenerator]":rows="3"type="textarea"maxlength="150"@input="handleInput(replyTexts[reply.idGenerator],reply.idGenerator)":placeholder="$t('view.course.add_comment')"></el-input><div class="commentOperate"><div class="numberLimit">还能输入<span class="remainingCount">{{remainCount[reply.idGenerator]}}</span>个字符</div><div class="comment-operate-item"><VueEmoji@chooseEmoji="chooseEmoji":replyComment="replyTexts[reply.idGenerator]":keyId="reply.idGenerator"/><el-buttonclass="commentBtn"type="primary"@click="userChildrenCommont(reply)">评论</el-button></div></div></el-form-item></el-form></div></div></div><el-dividerborder-style="double"style="height: 1px; border: 1px solid #f4f3f3"/></div></div></div></div>
</template>
<script setup>
import VueEmoji from "@/views/activity/activityDetail/VueEmoji.vue";
import { ElMessage, ElMessageBox } from "element-plus";
import {addComments,searchComments,commentThumbsUp,commentCancelThumbsUp,deleteCommentApi,
} from "@/api/common";
import {singleCourseCommentThumbsUp,singleCourseCommentCancelThumbsUp,
} from "@/api/course";
import { useRoute, useRouter } from "vue-router";
const likeIcon = new URL("@/assets/images/icons/svg/like.svg", import.meta.url).href;
const yellowLikeIcon = new URL("@/assets/images/icons/svg/yellowlike.svg",import.meta.url
).href;
import profile from "@/assets/images/profile.jpg";
import { onMounted } from "vue";
const route = useRoute();
const router = useRouter();
const isComment = ref(true);
const detailLoading = ref(false);
// 評論數據
const comments = ref([]);
//回覆評論
const replyTexts = ref({});
const showReplyInput = ref({});
const commentForm = reactive({commentText: "",
});
const props = defineProps({isComment: {type: Boolean,default: false,},
});onMounted(()=>{searchCommentsFn()
})const getCommentzanIconSrc = (isThumbsUp) => {return isThumbsUp ? yellowLikeIcon : likeIcon;
};const getCommentzanIconClass = (isThumbsUp) => {return isThumbsUp ? "yellowlike" : "like";
};
const toggleReply = (commentId) => {remainCount.value[commentId] = 150;if (!showReplyInput.value[commentId]) {showReplyInput.value[commentId] = false;}showReplyInput.value[commentId] = !showReplyInput.value[commentId];
};// 評論點讚狀態
const commentLikes = ref({});const toggleLikeComment = (commentId, isThumbsUp) => {// if (!commentLikes.value[commentId]) {//   commentLikes.value[commentId] = false;// }// commentLikes.value[commentId] = !commentLikes.value[commentId];// console.log(commentLikes.value[commentId], "commentLikes.value[commentId]");if (!isThumbsUp) {singleCourseCommentThumbsUp({mainId: route.query.id,commentId: commentId,}).then((res) => {if (res.code == 200) {ElMessage.success("点赞成功");searchCommentsFn();}});} else {singleCourseCommentCancelThumbsUp({mainId: route.query.id,commentId: commentId,}).then((res) => {if (res.code == 200) {ElMessage.success("取消点赞");searchCommentsFn();}});}
};
const searchCommentsFn = () => {comments.value = []detailLoading.value = true;let params = {mainId: route.query.id,funType: 1,pageNum: 1,pageSize: 10,};searchComments(params).then((res) => {if (res.code == 200) {comments.value = res.data.items;detailLoading.value = false;} else {ElMessage.error(res.message);detailLoading.value = false;}});
};
const remainingCount = ref(150);
const remainCount = ref({});
const handleInput = (value, id) => {if (id) {remainCount.value[id] = 150 - value.length;} else {remainingCount.value = 150 - value.length;}// if (remainingCount.value < 0) {//   this.message = this.message.slice(0, this.maxLength);//   event.target.scrollTop = event.target.scrollHeight;// }
};const chooseEmoji = (item, replyComment, keyId) => {if (keyId) {replyComment += item;replyTexts.value[keyId] = replyComment;remainCount.value[keyId]--;} else {commentForm.commentText += item;remainingCount.value--;}
};
const addCommont = (params) => {addComments(params).then((res) => {if (res.code == 200) {ElMessage.success("评论成功");showReplyInput.value[params.parentIdGenerator] = false;replyTexts.value[params.parentIdGenerator] = "";remainCount[params.parentIdGenerator] = 150;commentForm.commentText = "";remainingCount.value = 150;searchCommentsFn();detailLoading.value = false;} else {detailLoading.value = false;ElMessage.error(res.message);}});
};
const userChildrenCommont = (comment) => {detailLoading.value = true;let params = {info_Conmment: replyTexts.value[comment.idGenerator],mainIdGenerator: comment.mainIdGenerator,parentIdGenerator: comment.idGenerator,moduleTypeEnums: 1,};addCommont(params);
};
const userCommont = () => {detailLoading.value = true;let params = {info_Conmment: commentForm.commentText,mainIdGenerator: route.query.id,parentIdGenerator: 0,moduleTypeEnums: 1,};addCommont(params);
};
// 刪除評論(按鈕)
const deleteComment = (idValue) => {const data = {id: idValue,};ElMessageBox.confirm(`確定刪除评论?`, "提示", {confirmButtonText: "确定",cancelButtonText: "取消",type: "warning",}).then(() => {deleteCommentApi(data).then((res) => {if (res.code == 200) {ElMessage({type: "success",message: "刪除评论成功",});searchCommentsFn();} else {ElMessage({type: "error",message: res.message,});}});}).catch(() => {info;ElMessage.info("评论成功");});
};
watch(() => route.query,(newValue, oldValue) => {if (route.query.typeFlag == "courseindexEnter") {commentForm.commentText = "";showReplyInput.value = {};replyTexts.value = {};remainCount.value = {};remainingCount.value = 150;}},{ immediate: true }
);
defineExpose({ searchCommentsFn });
</script>
<style scoped lang="scss">
:deep(.el-form-item__content) {position: relative;//   margin-left: 20px;margin-top: 10px;padding-bottom: 10px;border: 1px solid #e7e7e7;border-radius: 6px;.el-textarea.el-input--default {.el-textarea__inner {box-shadow: 0 0 0 1px transparent !important;padding: 5px 16px !important;}}.commentOperate {height: 20px;border: 1px solid transparent;.numberLimit {position: absolute;// bottom: 5px;left: 16px;color: #999aaa;.remainingCount {color: #1d2129;padding: 0 2px;}}.comment-operate-img {width: 20px;height: 20px;}.comment-operate-item {position: absolute;// bottom: 0px;right: 21px;display: flex;align-items: center;.comment-operate-img {width: 20px;height: 20px;margin-right: 16px;cursor: pointer;}.commentBtn {padding-right: 10px;border-radius: 16px;width: 60px;height: 24px;font-size: 14px;}}}
}
</style>

emoji.json

{"data": "😀,😁,😂,😃,😄,😅,😆,😉,😊,😋,😎,😍,😘,😗,😙,😚,😇,😐,😑,😶,😏,😣,😥,😮,😯,😪,😫,😴,😌,😛,😜,😝,😒,😓,😔,😕,😲,😷,😖,😞,😟,😤,😢,😭,😦,😧,😨,😬,😰,😱,😳,😵,😡,😠,💘,❤,💓,💔,💕,💖,💗,💙,💚,💛,💜,💝,💞,💟,❣,💪,👈,👉,☝,👆,👇,✌,✋,👌,👍,👎,✊,👊,👋,👏,👐,✍,🍇,🍈,🍉,🍊,🍋,🍌,🍍,🍎,🍏,🍐,🍑,🍒,🍓,🍅,🍆,🌽,🍄,🌰,🍞,🍖,🍗,🍔,🍟,🍕,🍳,🍲,🍱,🍘,🍙,🍚,🍛,🍜,🍝,🍠,🍢,🍣,🍤,🍥,🍡,🍦,🍧,🍨,🍩,🍪,🎂,🍰,🍫,🍬,🍭,🍮,🍯,🍼,☕,🍵,🍶,🍷,🍸,🍹,🍺,🍻,🍴,🌹,🍀,🍎,💰,📱,🌙,🍁,🍂,🍃,🌷,💎,🔪,🔫,🏀,⚽,⚡,👄,👍,🔥,🙈,🙉,🙊,🐵,🐒,🐶,🐕,🐩,🐺,🐱,😺,😸,😹,😻,😼,😽,🙀,😿,😾,🐈,🐯,🐅,🐆,🐴,🐎,🐮,🐂,🐃,🐄,🐷,🐖,🐗,🐽,🐏,🐑,🐐,🐪,🐫,🐘,🐭,🐁,🐀,🐹,🐰,🐇,🐻,🐨,🐼,🐾,🐔,🐓,🐣,🐤,🐥,🐦,🐧,🐸,🐊,🐢,🐍,🐲,🐉,🐳,🐋,🐬,🐟,🐠,🐡,🐙,🐚,🐌,🐛,🐜,🐝,🐞,🦋,😈,👿,👹,👺,💀,☠,👻,👽,👾,💣"
}

这篇关于评论的组件封装的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1141182

相关文章

JS常用组件收集

收集了一些平时遇到的前端比较优秀的组件,方便以后开发的时候查找!!! 函数工具: Lodash 页面固定: stickUp、jQuery.Pin 轮播: unslider、swiper 开关: switch 复选框: icheck 气泡: grumble 隐藏元素: Headroom

如何在页面调用utility bar并传递参数至lwc组件

1.在app的utility item中添加lwc组件: 2.调用utility bar api的方式有两种: 方法一,通过lwc调用: import {LightningElement,api ,wire } from 'lwc';import { publish, MessageContext } from 'lightning/messageService';import Ca

vue2 组件通信

props + emits props:用于接收父组件传递给子组件的数据。可以定义期望从父组件接收的数据结构和类型。‘子组件不可更改该数据’emits:用于定义组件可以向父组件发出的事件。这允许父组件监听子组件的事件并作出响应。(比如数据更新) props检查属性 属性名类型描述默认值typeFunction指定 prop 应该是什么类型,如 String, Number, Boolean,

JavaSE——封装、继承和多态

1. 封装 1.1 概念      面向对象程序三大特性:封装、继承、多态 。而类和对象阶段,主要研究的就是封装特性。何为封装呢?简单来说就是套壳屏蔽细节 。     比如:对于电脑这样一个复杂的设备,提供给用户的就只是:开关机、通过键盘输入,显示器, USB 插孔等,让用户来和计算机进行交互,完成日常事务。但实际上:电脑真正工作的却是CPU 、显卡、内存等一些硬件元件。

kubelet组件的启动流程源码分析

概述 摘要: 本文将总结kubelet的作用以及原理,在有一定基础认识的前提下,通过阅读kubelet源码,对kubelet组件的启动流程进行分析。 正文 kubelet的作用 这里对kubelet的作用做一个简单总结。 节点管理 节点的注册 节点状态更新 容器管理(pod生命周期管理) 监听apiserver的容器事件 容器的创建、删除(CRI) 容器的网络的创建与删除

火语言RPA流程组件介绍--浏览网页

🚩【组件功能】:浏览器打开指定网址或本地html文件 配置预览 配置说明 网址URL 支持T或# 默认FLOW输入项 输入需要打开的网址URL 超时时间 支持T或# 打开网页超时时间 执行后后等待时间(ms) 支持T或# 当前组件执行完成后继续等待的时间 UserAgent 支持T或# User Agent中文名为用户代理,简称 UA,它是一个特殊字符串头,使得服务器

哈希表的封装和位图

文章目录 2 封装2.1 基础框架2.2 迭代器(1)2.3 迭代器(2) 3. 位图3.1 问题引入3.2 左移和右移?3.3 位图的实现3.4 位图的题目3.5 位图的应用 2 封装 2.1 基础框架 文章 有了前面map和set封装的经验,容易写出下面的代码 // UnorderedSet.h#pragma once#include "HashTable.h"

封装MySQL操作时Where条件语句的组织

在对数据库进行封装的过程中,条件语句应该是相对难以处理的,毕竟条件语句太过于多样性。 条件语句大致分为以下几种: 1、单一条件,比如:where id = 1; 2、多个条件,相互间关系统一。比如:where id > 10 and age > 20 and score < 60; 3、多个条件,相互间关系不统一。比如:where (id > 10 OR age > 20) AND sco

vue 父组件调用子组件的方法报错,“TypeError: Cannot read property ‘subDialogRef‘ of undefined“

vue 父组件调用子组件的方法报错,“TypeError: Cannot read property ‘subDialogRef’ of undefined” 最近用vue做的一个界面,引入了一个子组件,在父组件中调用子组件的方法时,报错提示: [Vue warn]: Error in v-on handler: “TypeError: Cannot read property ‘methods

JavaEE应用的组件

1、表现层组件:主要负责收集用户输入数据,或者向客户显示系统状态。最常用的表现层技术是JSP,但JSP并不是唯一的表现层技术。 2、控制器组件:对于JavaEE的MVC框架而言,框架提供一个前端核心控制器,而核心控制器负责拦截用户请求,并将用户请求转发给用户实现的控制器组件。而这些用户实现的控制器则负责处理调用业务逻辑方法,处理用户请求。 3、业务逻辑组件:是系统的核心组件,实现系统的业务逻辑