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

@@ -5,7 +5,7 @@
<text class="item-name">{{ item.name }}</text> <text class="item-name">{{ item.name }}</text>
<view class="rank-tag" v-if="item.rank <= 3">NO.{{ item.rank }}</view> <view class="rank-tag" v-if="item.rank <= 3">NO.{{ item.rank }}</view>
<view class="flex-spacer"></view> <view class="flex-spacer"></view>
<text class="item-score">{{ item.score }}</text> <text class="item-score">{{ item.scoreAvg }}</text>
</view> </view>
<view class="quote-box" v-if="item.quote"> <view class="quote-box" v-if="item.quote">
<text class="quote-text">{{ item.quote }}</text> <text class="quote-text">{{ item.quote }}</text>
@@ -15,8 +15,8 @@
class="action-item" class="action-item"
v-for="(action, aIndex) in actions" v-for="(action, aIndex) in actions"
:key="aIndex" :key="aIndex"
:class="{ active: item.userAction === action.value }" :class="{ active: item.userAction === action.label }"
@tap.stop="handleAction(action.value)" @tap.stop="handleAction(action)"
> >
<view class="action-icon-wrap" :class="'icon-' + action.value"> <view class="action-icon-wrap" :class="'icon-' + action.value">
<text class="emoji">{{ action.emoji }}</text> <text class="emoji">{{ action.emoji }}</text>
@@ -30,16 +30,18 @@
<script setup> <script setup>
import { FILE_BASE_URL } from "@/utils/constants"; import { FILE_BASE_URL } from "@/utils/constants";
const actions = [
{ label: '拉', value: 'terrible', emoji: '👎', score: 2, scoreType:1 },
{ label: 'NPC', value: 'bad', emoji: '😐', score: 4, scoreType: 2},
{ label: '人上人', value: 'ok', emoji: '🙂', score: 6, scoreType: 3},
{ label: '顶级', value: 'good', emoji: '🔥', score: 8, scoreType: 4},
{ label: '夯', value: 'god', emoji: '👑', score: 10, scoreType: 5 }
];
const props = defineProps({ const props = defineProps({
item: { item: {
type: Object, type: Object,
required: true, required: true,
default: () => ({}) default: () => ({})
},
actions: {
type: Array,
required: true,
default: () => []
} }
}); });
@@ -49,8 +51,8 @@ const handleCardTap = () => {
emit('item-click', props.item.id); emit('item-click', props.item.id);
}; };
const handleAction = (actionValue) => { const handleAction = async (action) => {
emit('action-click', props.item, actionValue); emit('action-click', props.item, action);
}; };
</script> </script>

View File

@@ -26,7 +26,7 @@
<text class="rank-num" :class="'rank-' + (index + 1)">{{ index + 1 }}</text> <text class="rank-num" :class="'rank-' + (index + 1)">{{ index + 1 }}</text>
<image class="item-avatar" :src="FILE_BASE_URL + item.avatarUrl" mode="aspectFill"></image> <image class="item-avatar" :src="FILE_BASE_URL + item.avatarUrl" mode="aspectFill"></image>
<text class="item-name">{{ item.name }}</text> <text class="item-name">{{ item.name }}</text>
<text class="item-score" :class="'score-' + (index + 1)">{{ item.score }}</text> <text class="item-score" :class="'score-' + (index + 1)">{{ item.scoreAvg }}</text>
</view> </view>
</view> </view>

View File

@@ -46,7 +46,7 @@
</view> </view>
<view class="info-box box-2"> <view class="info-box box-2">
<text class="name">{{ ratingItems[1].name }}</text> <text class="name">{{ ratingItems[1].name }}</text>
<text class="score">分数 {{ ratingItems[1].score }}</text> <text class="score">分数 {{ ratingItems[1].scoreAvg }}</text>
</view> </view>
</view> </view>
<!-- 第一名 --> <!-- 第一名 -->
@@ -57,7 +57,7 @@
</view> </view>
<view class="info-box box-1"> <view class="info-box box-1">
<text class="name name-1">{{ ratingItems[0].name }}</text> <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>
</view> </view>
<!-- 第三名 --> <!-- 第三名 -->
@@ -68,7 +68,7 @@
</view> </view>
<view class="info-box box-3"> <view class="info-box box-3">
<text class="name">{{ ratingItems[2].name }}</text> <text class="name">{{ ratingItems[2].name }}</text>
<text class="score">分数 {{ ratingItems[2].score }}</text> <text class="score">分数 {{ ratingItems[2].scoreAvg }}</text>
</view> </view>
</view> </view>
</view> </view>
@@ -79,7 +79,6 @@
v-for="(item, index) in ratingItems" v-for="(item, index) in ratingItems"
:key="item.id" :key="item.id"
:item="item" :item="item"
:actions="actions"
@item-click="goToDetail" @item-click="goToDetail"
@action-click="handleAction" @action-click="handleAction"
/> />
@@ -159,7 +158,7 @@ import { onPullDownRefresh, onReachBottom, onLoad } from "@dcloudio/uni-app";
import { fetchTopicDetail, fetchTopicRatingItems } from "@/api/topic"; import { fetchTopicDetail, fetchTopicRatingItems } from "@/api/topic";
import { FILE_BASE_URL } from "@/utils/constants"; import { FILE_BASE_URL } from "@/utils/constants";
import RatingCard from "@/components/RatingCard/RatingCard.vue"; import RatingCard from "@/components/RatingCard/RatingCard.vue";
import { topicItemScore } from "@/api/topicItem";
// 状态栏高度处理 // 状态栏高度处理
const statusBarHeight = ref(getStatusBarHeight() || 44); const statusBarHeight = ref(getStatusBarHeight() || 44);
@@ -237,14 +236,6 @@ const confirmAddItem = () => {
uni.showToast({ title: '添加成功', icon: 'success' }); 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 ratingItems = ref([]);
const loadItems = async (topicId, page = 1) => { const loadItems = async (topicId, page = 1) => {
@@ -293,8 +284,25 @@ const mockComments = [
const comments = ref([...mockComments]); const comments = ref([...mockComments]);
const handleAction = (item, actionValue) => { const handleAction = async (item, action) => {
item.userAction = item.userAction === actionValue ? '' : actionValue; 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) => { const goToDetail = (itemId) => {