From 07a568c87861f4361ecb3122b2cbc13961a4868d Mon Sep 17 00:00:00 2001
From: zzc <1761997216@qq.com>
Date: Sat, 23 May 2026 23:24:57 +0800
Subject: [PATCH] fix: rating
---
components/RatingCard/RatingCard.vue | 22 ++++++++--------
components/TopicCard/TopicCard.vue | 2 +-
pages/rating/index.vue | 38 +++++++++++++++++-----------
3 files changed, 36 insertions(+), 26 deletions(-)
diff --git a/components/RatingCard/RatingCard.vue b/components/RatingCard/RatingCard.vue
index 86a83c5..ab8248c 100644
--- a/components/RatingCard/RatingCard.vue
+++ b/components/RatingCard/RatingCard.vue
@@ -5,7 +5,7 @@
{{ item.name }}
NO.{{ item.rank }}
- {{ item.score }}
+ {{ item.scoreAvg }}
β{{ item.quote }}β
@@ -15,8 +15,8 @@
class="action-item"
v-for="(action, aIndex) in actions"
:key="aIndex"
- :class="{ active: item.userAction === action.value }"
- @tap.stop="handleAction(action.value)"
+ :class="{ active: item.userAction === action.label }"
+ @tap.stop="handleAction(action)"
>
{{ action.emoji }}
@@ -30,16 +30,18 @@
diff --git a/components/TopicCard/TopicCard.vue b/components/TopicCard/TopicCard.vue
index ba1eaed..f254986 100644
--- a/components/TopicCard/TopicCard.vue
+++ b/components/TopicCard/TopicCard.vue
@@ -26,7 +26,7 @@
{{ index + 1 }}
{{ item.name }}
- {{ item.score }}
+ {{ item.scoreAvg }}
diff --git a/pages/rating/index.vue b/pages/rating/index.vue
index 4b1f212..227f2dd 100644
--- a/pages/rating/index.vue
+++ b/pages/rating/index.vue
@@ -46,7 +46,7 @@
{{ ratingItems[1].name }}
- εζ° {{ ratingItems[1].score }}
+ εζ° {{ ratingItems[1].scoreAvg }}
@@ -57,7 +57,7 @@
{{ ratingItems[0].name }}
- εζ° {{ ratingItems[0].score }}
+ εζ° {{ ratingItems[0].scoreAvg }}
@@ -68,7 +68,7 @@
{{ ratingItems[2].name }}
- εζ° {{ ratingItems[2].score }}
+ εζ° {{ ratingItems[2].scoreAvg }}
@@ -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) => {