comment-item.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <script setup lang="ts">
  2. import { useUserStore } from '../../../store'
  3. import {
  4. cancelCircleReviewUpvote,
  5. createCircleReviewUpvote,
  6. deleteCircleReview,
  7. getReviewReplay,
  8. } from '../../../core/libs/requests'
  9. import { thumbsUp, thumbsUpActive } from '../../../core/libs/svgs'
  10. import { Comment } from '../../../core/models/moment'
  11. import { dayjs } from 'wot-design-uni'
  12. import { storeToRefs } from 'pinia'
  13. const props = defineProps({
  14. options: {
  15. type: Object as PropType<Comment>,
  16. default: () => ({}),
  17. },
  18. isChild: {
  19. type: Boolean,
  20. default: false,
  21. },
  22. })
  23. const emits = defineEmits<{ upvote: []; delete: [] }>()
  24. const userStore = useUserStore()
  25. const { userInfo } = storeToRefs(userStore)
  26. const handleUpvote = async () => {
  27. if (!props.options.upvote) {
  28. const { code, msg } = await createCircleReviewUpvote({
  29. circleId: props.options.circleId,
  30. userId: userInfo.value.userId,
  31. userName: userInfo.value.nickname,
  32. reviewId: props.options.id,
  33. })
  34. code === 0 && uni.showToast({ title: '点赞成功', icon: 'none' })
  35. } else {
  36. const { code, msg } = await cancelCircleReviewUpvote({
  37. circleId: props.options.circleId.toString(),
  38. userId: userInfo.value.userId.toString(),
  39. reviewId: props.options.id.toString(),
  40. })
  41. code === 0 && uni.showToast({ title: '取消点赞成功', icon: 'none' })
  42. }
  43. emits('upvote')
  44. }
  45. const handleDelect = async () => {
  46. uni.showModal({
  47. content: '确定删除评论?',
  48. showCancel: true,
  49. success: async (res) => {
  50. if (res.confirm) {
  51. // TODO: 删除评论
  52. const { code, msg } = await deleteCircleReview(props.options.id)
  53. if (code === 0) {
  54. uni.showToast({ title: '删除评论成功', icon: 'none' })
  55. } else {
  56. uni.showToast({ title: msg, icon: 'none' })
  57. }
  58. emits('delete')
  59. }
  60. },
  61. })
  62. }
  63. onMounted(async () => {
  64. const { data } = await getReviewReplay({ id: props.options.id.toString() })
  65. console.log(data)
  66. })
  67. </script>
  68. <template>
  69. <view class="grid grid-cols-[28px_1fr_28px] gap-2.5" :class="isChild ? 'ml-9' : ''">
  70. <wd-img
  71. custom-class="rounded-full overflow-hidden col-start-1 row-start-1"
  72. width="28"
  73. height="28"
  74. :src="options.userAvatar"
  75. />
  76. <view class="col-start-2 row-start-1">
  77. <div class="text-black/40 text-xs font-normal font-['PingFang SC'] leading-[10.18px]">
  78. {{ options.userName }}
  79. </div>
  80. <div class="my-3 text-black/90 text-sm font-normal font-['PingFang SC'] leading-[10.18px]">
  81. {{ options.reviewContent }}
  82. </div>
  83. <view class="flex items-center mt--2 gap-3">
  84. <div class="text-black/30 text-[10px] font-normal font-['PingFang SC'] leading-[10.18px]">
  85. {{ dayjs(options.reviewTime).format('YYYY/MM/DD') }}
  86. </div>
  87. <view class="">
  88. <wd-button custom-class="text-2.5!" type="text">回复</wd-button>
  89. </view>
  90. <div v-if="userInfo.userId === options.userId">
  91. <wd-button custom-class="text-2.5!" type="text" @click="handleDelect">删除</wd-button>
  92. </div>
  93. </view>
  94. </view>
  95. <view class="col-start-3 row-start-1 flex flex-col items-center" @click="handleUpvote">
  96. <div class="w-[18px] h-[18px] relative">
  97. <wd-img :src="options.upvote ? thumbsUpActive : thumbsUp" width="18" height="18"></wd-img>
  98. </div>
  99. <div
  100. class="mt-1.5 text-black/40 text-[10px] font-normal font-['PingFang SC'] leading-[10.18px]"
  101. >
  102. {{ options.upvoteCount || 0 }}
  103. </div>
  104. </view>
  105. </view>
  106. </template>