index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <div>
  3. <a-comment
  4. v-for="(item, idx) in commentList"
  5. :key="idx"
  6. :style="{ 'border-bottom': item.parentId == -1 ? '1px solid #ccc' : '' }"
  7. >
  8. <template #actions>
  9. <span key="comment-basic-like">
  10. <a-tooltip title="点赞">
  11. <template v-if="item.isLike == 1">
  12. <HeartOutlined :style="{ color: '#fa6c8d' }" @click="like(item)" />
  13. </template>
  14. <template v-else>
  15. <HeartOutlined @click="like(item)" />
  16. </template>
  17. </a-tooltip>
  18. <span style="padding-left: 8px; cursor: auto">
  19. {{ item.likeCount }}
  20. </span>
  21. </span>
  22. <a-tooltip title="编辑">
  23. <EditOutlined
  24. v-if="item.isSelf == 1"
  25. @click="replyFormRef.onOpen(item, props.params.targetId, item.replyId, true)"
  26. />
  27. </a-tooltip>
  28. <a-tooltip title="删除">
  29. <DeleteOutlined v-if="item.isSelf == 1" @click="showDeleteConfirm(item)" />
  30. </a-tooltip>
  31. <span
  32. key="comment-basic-reply-to"
  33. @click="replyFormRef.onOpen(item, props.params.targetId, item.replyId, false)"
  34. v-if="item.parentId == -1"
  35. >
  36. 回复
  37. </span>
  38. </template>
  39. <template #author>
  40. <a>{{ item.userNickname }}</a>
  41. </template>
  42. <template #avatar>
  43. <a-avatar :src="item.userAvatar" :alt="item.userNickname" />
  44. </template>
  45. <template #content>
  46. <div v-html="item.replyContent"></div>
  47. </template>
  48. <template #datetime>
  49. <span>{{ formatDateTime(item.createTime) }}</span>
  50. </template>
  51. <div v-if="item.children">
  52. <a-divider />
  53. </div>
  54. <Comment
  55. v-if="item.children && item.children.length > 0"
  56. :commentList="item.children"
  57. :params="params"
  58. @successful="emit('successful')"
  59. ></Comment>
  60. </a-comment>
  61. <replyForm ref="replyFormRef" @successful="emit('successful')" />
  62. </div>
  63. </template>
  64. <script setup name="commentList">
  65. import forumApi from '@/api/forum/forumApi'
  66. import Comment from '@/components/Comment/index.vue'
  67. import { ExclamationCircleOutlined } from '@ant-design/icons-vue'
  68. import { createVNode } from 'vue'
  69. import { Modal } from 'ant-design-vue'
  70. import { parseTime } from '@/utils/exam'
  71. import replyForm from '@/views/forum/replyForm.vue'
  72. const emit = defineEmits({ successful: null })
  73. const replyFormRef = ref()
  74. const props = defineProps({
  75. commentList: {
  76. type: Array,
  77. default: () => []
  78. },
  79. params: {
  80. type: Object,
  81. default: () => {}
  82. },
  83. count: {
  84. type: [String , Number],
  85. default: 0
  86. }
  87. })
  88. function formatDateTime(val) {
  89. if (!val) return ''
  90. return parseTime(val, '{y}-{m}-{d} {h}:{i}:{s}')
  91. }
  92. const like = (item) => {
  93. forumApi
  94. .postlikeSubmit(
  95. {
  96. ...props.params,
  97. targetId: item.replyId
  98. },
  99. item.isLike
  100. )
  101. .then((data) => {
  102. item.isLike = !item.isLike
  103. })
  104. }
  105. const showDeleteConfirm = (item) => {
  106. Modal.confirm({
  107. title: '确定要删除回复?',
  108. icon: createVNode(ExclamationCircleOutlined),
  109. onOk() {
  110. forumApi.postreplyDel([{ replyId: item.replyId }]).then((data) => {
  111. emit('successful')
  112. })
  113. },
  114. onCancel() {
  115. console.log('Cancel')
  116. }
  117. })
  118. }
  119. </script>