fix: rating
This commit is contained in:
173
components/CommentItem/CommentItem.vue
Normal file
173
components/CommentItem/CommentItem.vue
Normal file
@@ -0,0 +1,173 @@
|
||||
<template>
|
||||
<view class="comment-item">
|
||||
<image class="c-avatar" :src="comment.avatar" mode="aspectFill" />
|
||||
<view class="c-content-wrap">
|
||||
<view class="c-header">
|
||||
<view class="c-user-info">
|
||||
<text class="c-name">{{ comment.name }}</text>
|
||||
<!-- 用户态度徽章 -->
|
||||
<ActionBadge v-if="comment.userAction" :action="comment.userAction" />
|
||||
<view class="c-badge" v-if="comment.badge">
|
||||
<text class="b-icon">{{ comment.badgeIcon }}</text>
|
||||
<text class="b-text">{{ comment.badge }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="c-like" @tap="handleLike">
|
||||
<text class="like-icon" :class="{ 'is-liked': isLiked }"></text>
|
||||
<text class="like-count" :class="{ 'liked-text': isLiked }">{{ currentLikes }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<text class="c-time">{{ comment.time }}</text>
|
||||
<text class="c-text">{{ comment.content }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, watch } from 'vue';
|
||||
import ActionBadge from "@/components/ActionBadge/ActionBadge.vue";
|
||||
|
||||
const props = defineProps({
|
||||
comment: {
|
||||
type: Object,
|
||||
required: true,
|
||||
default: () => ({})
|
||||
}
|
||||
});
|
||||
|
||||
const isLiked = ref(false);
|
||||
const currentLikes = ref(props.comment.likes || 0);
|
||||
|
||||
watch(() => props.comment.likes, (newVal) => {
|
||||
currentLikes.value = newVal;
|
||||
});
|
||||
|
||||
const handleLike = () => {
|
||||
isLiked.value = !isLiked.value;
|
||||
if (isLiked.value) {
|
||||
currentLikes.value += 1;
|
||||
// 震动反馈增加交互感
|
||||
uni.vibrateShort({ type: 'light' });
|
||||
} else {
|
||||
currentLikes.value -= 1;
|
||||
}
|
||||
// TODO: 如果需要,可以抛出事件给父组件去调用点赞接口
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.comment-item {
|
||||
display: flex;
|
||||
padding: 32rpx 0;
|
||||
position: relative;
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
|
||||
.comment-item:active {
|
||||
background-color: #fafbfe;
|
||||
}
|
||||
|
||||
.comment-item::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 104rpx; /* 头像宽度(80) + 间距(24) */
|
||||
right: 0;
|
||||
height: 2rpx;
|
||||
background-color: #f0f2f7;
|
||||
}
|
||||
|
||||
.c-avatar {
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
border-radius: 50%;
|
||||
margin-right: 24rpx;
|
||||
background-color: #f5f6fa;
|
||||
flex-shrink: 0;
|
||||
border: 2rpx solid #f0f2f7;
|
||||
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.03);
|
||||
}
|
||||
|
||||
.c-content-wrap {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.c-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 8rpx;
|
||||
}
|
||||
|
||||
.c-user-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.c-name {
|
||||
font-size: 30rpx;
|
||||
font-weight: 700; /* 减轻字重,显得更精致 */
|
||||
color: #1a1a1a;
|
||||
margin-right: 12rpx;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Helvetica, Segoe UI, Arial, Roboto, sans-serif;
|
||||
}
|
||||
|
||||
.c-badge {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: linear-gradient(90deg, #f5f6fa, #f0f2f7);
|
||||
padding: 4rpx 16rpx;
|
||||
border-radius: 100rpx;
|
||||
margin-left: 12rpx;
|
||||
}
|
||||
|
||||
.b-icon { font-size: 20rpx; margin-right: 6rpx; }
|
||||
.b-text { font-size: 20rpx; color: #666; font-weight: bold; }
|
||||
|
||||
.c-like {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
color: #999;
|
||||
font-size: 24rpx;
|
||||
font-weight: 600;
|
||||
padding: 8rpx;
|
||||
margin: -8rpx; /* 增加点击区域 */
|
||||
}
|
||||
|
||||
.like-icon {
|
||||
width: 32rpx;
|
||||
height: 32rpx;
|
||||
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3'%3E%3C/path%3E%3C/svg%3E");
|
||||
background-size: cover;
|
||||
margin-right: 8rpx;
|
||||
transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
|
||||
}
|
||||
|
||||
.like-icon.is-liked {
|
||||
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23ff4d4f' stroke='%23ff4d4f' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3'%3E%3C/path%3E%3C/svg%3E");
|
||||
transform: scale(1.15);
|
||||
}
|
||||
|
||||
.liked-text {
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.c-like:active .like-icon {
|
||||
transform: scale(0.9);
|
||||
}
|
||||
|
||||
.c-time {
|
||||
font-size: 22rpx;
|
||||
color: #a1a1a1;
|
||||
display: block;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.c-text {
|
||||
font-size: 30rpx;
|
||||
color: #2c2c2c;
|
||||
line-height: 1.65;
|
||||
word-break: break-all;
|
||||
}
|
||||
</style>
|
||||
@@ -87,28 +87,11 @@
|
||||
</view>
|
||||
|
||||
<view class="comment-list">
|
||||
<view class="comment-item" v-for="comment in comments" :key="comment.id">
|
||||
<image class="c-avatar" :src="comment.avatar" mode="aspectFill" />
|
||||
<view class="c-content-wrap">
|
||||
<view class="c-header">
|
||||
<view class="c-user-info">
|
||||
<text class="c-name">{{ comment.name }}</text>
|
||||
<!-- 用户态度徽章 -->
|
||||
<ActionBadge v-if="comment.userAction" :action="comment.userAction" />
|
||||
<view class="c-badge" v-if="comment.badge">
|
||||
<text class="b-icon">{{ comment.badgeIcon }}</text>
|
||||
<text class="b-text">{{ comment.badge }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="c-like">
|
||||
<text class="like-icon"></text>
|
||||
<text class="like-count">{{ comment.likes }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<text class="c-time">{{ comment.time }}</text>
|
||||
<text class="c-text">{{ comment.content }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<CommentItem
|
||||
v-for="(comment, index) in comments"
|
||||
:key="comment.id"
|
||||
:comment="comment"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<!-- 加载更多 -->
|
||||
@@ -130,6 +113,7 @@ import { onLoad, onPullDownRefresh, onReachBottom } from "@dcloudio/uni-app";
|
||||
import AttitudePanel from "@/components/AttitudePanel/AttitudePanel.vue";
|
||||
import SuccessPopup from "@/components/SuccessPopup/SuccessPopup.vue";
|
||||
import ActionBadge from "@/components/ActionBadge/ActionBadge.vue";
|
||||
import CommentItem from "@/components/CommentItem/CommentItem.vue";
|
||||
import { FILE_BASE_URL } from "@/utils/constants";
|
||||
import { fetchTopicRatingItems, topicItemScore, topicItemComment, topicItemCommentList } from "@/api/topicItem";
|
||||
import { formatDate } from "@/utils/date";
|
||||
@@ -227,7 +211,7 @@ const getCommentsData = async () => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const res = await topicItemCommentList(detailData.value.topicId, itemId.value, currentPage.value);
|
||||
const list = res?.list || [];
|
||||
const list = res?.list || [];
|
||||
|
||||
const formattedList = list.map(item => ({
|
||||
id: item.id,
|
||||
@@ -248,7 +232,7 @@ const getCommentsData = async () => {
|
||||
}
|
||||
|
||||
// 假设每页10条,如果返回的少于10条则没有更多了
|
||||
hasMore.value = list.length >= 10;
|
||||
hasMore.value = list.length >= 6;
|
||||
} catch (error) {
|
||||
console.error('获取评论列表失败:', error);
|
||||
} finally {
|
||||
@@ -270,7 +254,7 @@ const getDetailData = async () => {
|
||||
avatar: data.avatarUrl ? `${FILE_BASE_URL}${data.avatarUrl}` : '',
|
||||
aiSummary: data.description || '暂无总结',
|
||||
hotScore: data.hotScore || '0.00',
|
||||
topicId: data.topicId || '',
|
||||
topicId: data.topicId || detailData.value.topicId || '',
|
||||
ratingCount: data.scoreCount || 0,
|
||||
userAction: data.userAction || ""
|
||||
};
|
||||
@@ -303,6 +287,9 @@ const getDetailData = async () => {
|
||||
};
|
||||
|
||||
onLoad((options) => {
|
||||
if (options.topicId) {
|
||||
detailData.value.topicId = options.topicId;
|
||||
}
|
||||
if (options.itemId) {
|
||||
itemId.value = options.itemId;
|
||||
getDetailData();
|
||||
@@ -648,105 +635,6 @@ onReachBottom(() => {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.comment-item {
|
||||
display: flex;
|
||||
padding: 32rpx 0;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.comment-item::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 104rpx; /* 头像宽度(80) + 间距(24) */
|
||||
right: 0;
|
||||
height: 2rpx;
|
||||
background-color: #f0f2f7;
|
||||
}
|
||||
|
||||
.comment-item:last-child::after {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.c-avatar {
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
border-radius: 50%;
|
||||
margin-right: 24rpx;
|
||||
background-color: #f5f6fa;
|
||||
flex-shrink: 0;
|
||||
border: 2rpx solid #f0f2f7;
|
||||
}
|
||||
|
||||
.c-content-wrap {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.c-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 8rpx;
|
||||
}
|
||||
|
||||
.c-user-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.c-name {
|
||||
font-size: 30rpx;
|
||||
font-weight: 800;
|
||||
color: #111;
|
||||
margin-right: 16rpx;
|
||||
}
|
||||
|
||||
.c-badge {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: linear-gradient(90deg, #f5f6fa, #f0f2f7);
|
||||
padding: 4rpx 16rpx;
|
||||
border-radius: 100rpx;
|
||||
}
|
||||
|
||||
.b-icon { font-size: 20rpx; margin-right: 6rpx; }
|
||||
.b-text { font-size: 20rpx; color: #666; font-weight: bold; }
|
||||
|
||||
.c-like {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
color: #999;
|
||||
font-size: 24rpx;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.like-icon {
|
||||
width: 32rpx;
|
||||
height: 32rpx;
|
||||
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3'%3E%3C/path%3E%3C/svg%3E");
|
||||
background-size: cover;
|
||||
margin-right: 8rpx;
|
||||
transition: transform 0.2s;
|
||||
}
|
||||
|
||||
.c-like:active .like-icon {
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
.c-time {
|
||||
font-size: 24rpx;
|
||||
color: #a1a1a1;
|
||||
display: block;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.c-text {
|
||||
font-size: 32rpx;
|
||||
color: #222;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.load-more {
|
||||
text-align: center;
|
||||
padding: 40rpx 0 0;
|
||||
|
||||
@@ -314,7 +314,7 @@ const handleAction = async (item, action) => {
|
||||
|
||||
const goToDetail = (itemId) => {
|
||||
uni.navigateTo({
|
||||
url: `/pages/rating/detail?itemId=${itemId}`
|
||||
url: `/pages/rating/detail?itemId=${itemId}&topicId=${currentTopicId.value}`
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user