0.2.1 • Published 1 month ago

mz-tn-comment-list v0.2.1

Weekly downloads
-
License
Apache 2.0
Repository
github
Last release
1 month ago

图鸟 UI vue3 uniapp Plugins - 评论列表

TuniaoUI vue3 uniapp

Tuniao UI vue3官方仓库

该组件一般用于展示评论信息

组件安装

npm i tnuiv3p-tn-comment-list

组件位置

tnuiv3p-tn-comment-list/index.vue

平台差异说明

App(vue)H5微信小程序支付宝小程序...
适配中

基础使用

  • 通过data属性传入评论列表数据
<script setup lang="ts">
import { ref } from 'vue'
import type { TnCommentListData } from 'tnuiv3p-tn-comment-list'

const commentList = ref<TnCommentListData>([
  {
    id: 1,
    avatar: 'https://tnuiimage.tnkjapp.com/avatar/normal/1.png',
    nickname: '图鸟用户1',
    date: '07-22',
    position: '广东',
    content: '这是一条来自图鸟用户1的评论',
    likeActive: false,
    likeCount: 0,
    dislikeActive: false,
    disabledReply: false,
    allowDelete: false,
    commentCount: 3,
  },
  {
    id: 2,
    avatar: 'https://tnuiimage.tnkjapp.com/avatar/normal/2.png',
    nickname: '图鸟用户2',
    date: '07-22',
    position: '广东',
    content: '这是一条来自图鸟用户2的评论',
    likeActive: true,
    likeCount: 1,
    dislikeActive: false,
    disabledReply: false,
    allowDelete: false,
    commentCount: 2,
  },
])
</script>

<template>
  <TnCommentList :data="commentList" />
</template>

对评论列表的增删查操作

评论列表查看更多操作

  • 通过show-more事件可以监听到用户点击了评论列表的查看更多按钮,该事件返回的参数中包含了当前点击的评论的id,可以通过该id去请求该评论的回复列表;currentCommentCount可以获取当前已展示的评论数量

  • 通过调用TnCommentList内部addCommentData函数添加数据,该函数接收需要添加回复数据的评论id评论列表数据的参数

<script setup lang="ts">
import { ref } from 'vue'
import type {
  TnCommentListInstance,
  TnCommentListItem,
  TnShowMoreCommentParams,
} from 'tnuiv3p-tn-comment-list'
// ...列表数据定义...

const commentListRef = ref<TnCommentListInstance>()

const showMoreClickHandle = ({ id }: TnShowMoreCommentParams) => {
  // 通过id去请求该评论的回复列表
  // ...
  const commentData: TnCommentListItem = [
    {
      id: 3,
      avatar: 'https://tnuiimage.tnkjapp.com/avatar/normal/3.png',
      nickname: '图鸟用户3',
      date: '07-23',
      position: '广东',
      content: '这是一条来自图鸟用户3的评论',
      likeActive: false,
      likeCount: 0,
      dislikeActive: false,
      disabledReply: false,
      allowDelete: false,
      commentCount: 3,
      images:['https://mz-xiaoyuanqiang.oss-cn-shenzhen.aliyuncs.com/static/images/%E8%83%8C%E6%99%AF%E5%9B%BE.jpg','https://mz-xiaoyuanqiang.oss-cn-shenzhen.aliyuncs.com/static/images/%E8%83%8C%E6%99%AF%E5%9B%BE.jpg']
      comment: [
        {
          id: 5,
          avatar: 'https://tnuiimage.tnkjapp.com/avatar/normal/5.png',
          nickname: '图鸟用户5',
          date: '07-23',
          position: '广东',
          content: '这是一条来自图鸟用户5的评论',
          likeActive: false,
          likeCount: 0,
          dislikeActive: false,
          disabledReply: false,
          allowDelete: false,
          images:['https://mz-xiaoyuanqiang.oss-cn-shenzhen.aliyuncs.com/static/images/%E8%83%8C%E6%99%AF%E5%9B%BE.jpg','https://mz-xiaoyuanqiang.oss-cn-shenzhen.aliyuncs.com/static/images/%E8%83%8C%E6%99%AF%E5%9B%BE.jpg']
        },
      ],
    },
    {
      id: 4,
      avatar: 'https://tnuiimage.tnkjapp.com/avatar/normal/4.png',
      nickname: '图鸟用户4',
      date: '07-23',
      position: '广东',
      content: '这是一条来自图鸟用户4的评论',
      likeActive: false,
      likeCount: 0,
      dislikeActive: false,
      disabledReply: false,
      allowDelete: false,
    },
  ]
  commentListRef.value?.addCommentData(id, commentData)
}
</script>

<template>
  <TnCommentList :data="commentList" @show-more="showMoreClickHandle" />
</template>

添加单条评论操作

  • 通过reply事件可以监听点击了评论的回复操作,该事件返回的参数中包含了当前点击评论的id和待回复的用户名称nickname

  • 通过调用TnCommentListaddCommentReply函数添加单条评论数据,该函数接收需要添加到的评论的id评论数据的参数

<script setup lang="ts">
import { ref } from 'vue'
import type {
  TnCommentListInstance,
  TnReplyCommentParams,
} from 'tnuiv3p-tn-comment-list'
// ...列表数据定义...

const commentListRef = ref<TnCommentListInstance>()

const replyClickHandle = ({ id }: TnReplyCommentParams) => {
  // 通过id添加评论到数据库中
  // ...
  commentListRef.value?.addCommentReply(id, {
    id: 10,
    avatar: 'https://tnuiimage.tnkjapp.com/avatar/normal/6.png',
    nickname: '图鸟用户6',
    date: '07-24',
    position: '广东',
    content: '这是一条来自图鸟用户6的评论',
    allowDelete: true,
  })
}
</script>

<template>
  <TnCommentList :data="commentList" @reply="replyClickHandle" />
</template>

删除评论操作

  • 通过delete事件可以监听到用户点击了评论的删除按钮,该事件返回的参数中包含了当前点击的评论的id,可以通过该id去请求删除该评论

  • 如果需要显示删除按钮,需要在数据参数中设置allowDeletetrue

  • 通过调用TnCommentListdeleteCommentReply函数删除评论,该函数接受评论的id

<script setup lang="ts">
import { ref } from 'vue'
import type { TnCommentListInstance } from 'tnuiv3p-tn-comment-list'
// ...列表数据定义...

const commentListRef = ref<TnCommentListInstance>()

const deleteClickHandle = (id: string | number) => {
  // 通过id从数据库中删除评论
  // ...
  commentListRef.value?.deleteCommentReply(id)
}
</script>

<template>
  <TnCommentList :data="commentList" @delete="deleteClickHandle" />
</template>

API

Props

属性名说明类型默认值可选值
data评论列表TnCommentListData[]-
show-like显示点赞图标Booleantruefalse
show-dislike显示点踩图标Booleantruefalse
like-icon点赞图标Stringlike图标有效值
active-like-icon激活后的点赞图标Stringlike-fill图标有效值
like-icon-color点赞图标默认颜色Stringtn-gray-dark颜色有效值
active-like-icon-color点赞图标激活颜色Stringtn-red颜色有效值
dislike-icon点踩图标Stringlike-break图标有效值
active-dislike-icon激活后的点踩图标Stringlike-fill图标有效值
dislike-icon-color点踩图标默认颜色Stringtn-gray-dark颜色有效值
active-dislike-icon-color点踩图标激活颜色Stringtn-gray-dark颜色有效值

Emits

事件名说明类型
like点赞事件(id: string \| number) => void
dislike点踩事件(id: string \|number) => void
reply回复事件(params: TnReplyCommentParams) => void
delete删除事件(id: string \|number) => void
show-more查看更多事件(params: TnShowMoreCommentParams) => void

Expose

函数名说明类型
addCommentData添加评论(id: string \| number, data: TnCommentListData) => void
addCommentReply添加评论回复(id: string \| number, data: TnReplyCommentData) => void
deleteCommentReply删除评论回复(id: string \| number) => void

TnCommentListItem

参数类型说明必填
idstring | number评论id
avatarstring用户头像
nicknamestring用户名
datestring评论日期
positionstring评论所在所属地
contentstring评论内容
likeActiveboolean激活点赞操作
likeCountnumber点赞数量
dislikeActiveboolean激活点踩操作
disabledReplyboolean禁止评论
allowDeleteboolean允许删除
commentCountnumber总评论数据条数
commentTnCommentListItem[]子评论数据

TnCommentListData = TnCommentListItem[]

TnReplyCommentParams

参数类型说明
idstring | number评论id
nicknamestring正在回复评论所属用户的名称

TnShowMoreCommentParams

参数类型说明
idstring | number评论id
currentCommentCountnumber当前已显示的评论数量

TnReplyCommentData

参数类型说明必填
idstring | number评论id
avatarstring用户头像
nicknamestring用户名
datestring评论日期
positionstring评论所在所属地
contentstring评论内容
allowDeleteboolean允许删除
disabledReplyboolean禁止回复
0.2.1

1 month ago

0.2.0

2 months ago

2.3.15

2 months ago

0.1.63

3 months ago

0.1.62

3 months ago

0.1.59

3 months ago

0.1.61

3 months ago

0.1.58

4 months ago

0.1.56

4 months ago

0.1.57

4 months ago

0.1.52

4 months ago

0.1.53

4 months ago

0.1.54

4 months ago

0.1.55

4 months ago

0.1.51

4 months ago

0.1.41

4 months ago

0.1.42

4 months ago

0.1.43

4 months ago

0.1.45

4 months ago

0.1.40

4 months ago

0.1.39

4 months ago

0.1.35

4 months ago

0.1.36

4 months ago

0.1.31

4 months ago

0.1.30

4 months ago

0.1.28

4 months ago

0.1.29

4 months ago

0.1.27

5 months ago

0.1.26

5 months ago

0.1.25

5 months ago

0.1.24

5 months ago

0.1.23

5 months ago

0.1.22

5 months ago

0.1.21

5 months ago

0.1.20

5 months ago

0.1.19

5 months ago

0.1.18

5 months ago

0.1.17

5 months ago

0.1.16

5 months ago

0.1.15

5 months ago

0.1.14

5 months ago

0.1.13

5 months ago

0.1.12

5 months ago

0.1.11

5 months ago

0.0.45

5 months ago

0.0.41

5 months ago

0.0.40

5 months ago

0.0.32

5 months ago

0.0.31

5 months ago

0.0.3

5 months ago