123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <script setup lang="ts">
- import { useUserStore } from '../../../store'
- import {
- cancelCircleReviewUpvote,
- createCircleReviewUpvote,
- deleteCircleReview,
- getReviewReplay,
- } from '../../../core/libs/requests'
- import { thumbsUp, thumbsUpActive } from '../../../core/libs/svgs'
- import { Comment } from '../../../core/models/moment'
- import { dayjs } from 'wot-design-uni'
- import { storeToRefs } from 'pinia'
- const props = defineProps({
- options: {
- type: Object as PropType<Comment>,
- default: () => ({}),
- },
- isChild: {
- type: Boolean,
- default: false,
- },
- })
- const emits = defineEmits<{ upvote: []; delete: [] }>()
- const userStore = useUserStore()
- const { userInfo } = storeToRefs(userStore)
- const handleUpvote = async () => {
- if (!props.options.upvote) {
- const { code, msg } = await createCircleReviewUpvote({
- circleId: props.options.circleId,
- userId: userInfo.value.userId,
- userName: userInfo.value.nickname,
- reviewId: props.options.id,
- })
- code === 0 && uni.showToast({ title: '点赞成功', icon: 'none' })
- } else {
- const { code, msg } = await cancelCircleReviewUpvote({
- circleId: props.options.circleId.toString(),
- userId: userInfo.value.userId.toString(),
- reviewId: props.options.id.toString(),
- })
- code === 0 && uni.showToast({ title: '取消点赞成功', icon: 'none' })
- }
- emits('upvote')
- }
- const handleDelect = async () => {
- uni.showModal({
- content: '确定删除评论?',
- showCancel: true,
- success: async (res) => {
- if (res.confirm) {
- // TODO: 删除评论
- const { code, msg } = await deleteCircleReview(props.options.id)
- if (code === 0) {
- uni.showToast({ title: '删除评论成功', icon: 'none' })
- } else {
- uni.showToast({ title: msg, icon: 'none' })
- }
- emits('delete')
- }
- },
- })
- }
- onMounted(async () => {
- const { data } = await getReviewReplay({ id: props.options.id.toString() })
- console.log(data)
- })
- </script>
- <template>
- <view class="grid grid-cols-[28px_1fr_28px] gap-2.5" :class="isChild ? 'ml-9' : ''">
- <wd-img
- custom-class="rounded-full overflow-hidden col-start-1 row-start-1"
- width="28"
- height="28"
- :src="options.userAvatar"
- />
- <view class="col-start-2 row-start-1">
- <div class="text-black/40 text-xs font-normal font-['PingFang SC'] leading-[10.18px]">
- {{ options.userName }}
- </div>
- <div class="my-3 text-black/90 text-sm font-normal font-['PingFang SC'] leading-[10.18px]">
- {{ options.reviewContent }}
- </div>
- <view class="flex items-center mt--2 gap-3">
- <div class="text-black/30 text-[10px] font-normal font-['PingFang SC'] leading-[10.18px]">
- {{ dayjs(options.reviewTime).format('YYYY/MM/DD') }}
- </div>
- <view class="">
- <wd-button custom-class="text-2.5!" type="text">回复</wd-button>
- </view>
- <div v-if="userInfo.userId === options.userId">
- <wd-button custom-class="text-2.5!" type="text" @click="handleDelect">删除</wd-button>
- </div>
- </view>
- </view>
- <view class="col-start-3 row-start-1 flex flex-col items-center" @click="handleUpvote">
- <div class="w-[18px] h-[18px] relative">
- <wd-img :src="options.upvote ? thumbsUpActive : thumbsUp" width="18" height="18"></wd-img>
- </div>
- <div
- class="mt-1.5 text-black/40 text-[10px] font-normal font-['PingFang SC'] leading-[10.18px]"
- >
- {{ options.upvoteCount || 0 }}
- </div>
- </view>
- </view>
- </template>
|