fix: rating

This commit is contained in:
zzc
2026-05-23 23:24:57 +08:00
parent 0270ba084f
commit 07a568c878
3 changed files with 36 additions and 26 deletions

View File

@@ -46,7 +46,7 @@
</view>
<view class="info-box box-2">
<text class="name">{{ ratingItems[1].name }}</text>
<text class="score">分数 {{ ratingItems[1].score }}</text>
<text class="score">分数 {{ ratingItems[1].scoreAvg }}</text>
</view>
</view>
<!-- 第一名 -->
@@ -57,7 +57,7 @@
</view>
<view class="info-box box-1">
<text class="name name-1">{{ ratingItems[0].name }}</text>
<text class="score score-1">分数 {{ ratingItems[0].score }}</text>
<text class="score score-1">分数 {{ ratingItems[0].scoreAvg }}</text>
</view>
</view>
<!-- 第三名 -->
@@ -68,7 +68,7 @@
</view>
<view class="info-box box-3">
<text class="name">{{ ratingItems[2].name }}</text>
<text class="score">分数 {{ ratingItems[2].score }}</text>
<text class="score">分数 {{ ratingItems[2].scoreAvg }}</text>
</view>
</view>
</view>
@@ -79,7 +79,6 @@
v-for="(item, index) in ratingItems"
:key="item.id"
:item="item"
:actions="actions"
@item-click="goToDetail"
@action-click="handleAction"
/>
@@ -159,7 +158,7 @@ import { onPullDownRefresh, onReachBottom, onLoad } from "@dcloudio/uni-app";
import { fetchTopicDetail, fetchTopicRatingItems } from "@/api/topic";
import { FILE_BASE_URL } from "@/utils/constants";
import RatingCard from "@/components/RatingCard/RatingCard.vue";
import { topicItemScore } from "@/api/topicItem";
// 状态栏高度处理
const statusBarHeight = ref(getStatusBarHeight() || 44);
@@ -237,14 +236,6 @@ const confirmAddItem = () => {
uni.showToast({ title: '添加成功', icon: 'success' });
};
const actions = [
{ label: '离谱', value: 'terrible', emoji: '👎' },
{ label: '一般', value: 'bad', emoji: '😐' },
{ label: '不错', value: 'ok', emoji: '🙂' },
{ label: '很强', value: 'good', emoji: '🔥' },
{ label: '封神', value: 'god', emoji: '👑' }
];
const ratingItems = ref([]);
const loadItems = async (topicId, page = 1) => {
@@ -293,8 +284,25 @@ const mockComments = [
const comments = ref([...mockComments]);
const handleAction = (item, actionValue) => {
item.userAction = item.userAction === actionValue ? '' : actionValue;
const handleAction = async (item, action) => {
const originAction = item.userAction;
const originScore = item.scoreAvg;
try {
item.userAction = item.userAction === action.label ? '' : action.label;
const res = await topicItemScore({
topicId: currentTopicId.value,
itemId: item.id,
scoreType: action.scoreType
});
item.scoreAvg = res?.scoreAvg || originScore;
} catch (error) {
uni.showToast({
title: '评分失败',
icon: 'none'
});
item.userAction = originAction;
item.scoreAvg = originScore;
}
};
const goToDetail = (itemId) => {