fix: rating
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
<text class="item-name">{{ item.name }}</text>
|
||||
<view class="rank-tag" v-if="item.rank <= 3">NO.{{ item.rank }}</view>
|
||||
<view class="flex-spacer"></view>
|
||||
<text class="item-score">{{ item.score }}</text>
|
||||
<text class="item-score">{{ item.scoreAvg }}</text>
|
||||
</view>
|
||||
<view class="quote-box" v-if="item.quote">
|
||||
<text class="quote-text">“{{ item.quote }}”</text>
|
||||
@@ -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)"
|
||||
>
|
||||
<view class="action-icon-wrap" :class="'icon-' + action.value">
|
||||
<text class="emoji">{{ action.emoji }}</text>
|
||||
@@ -30,16 +30,18 @@
|
||||
<script setup>
|
||||
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({
|
||||
item: {
|
||||
type: Object,
|
||||
required: true,
|
||||
default: () => ({})
|
||||
},
|
||||
actions: {
|
||||
type: Array,
|
||||
required: true,
|
||||
default: () => []
|
||||
}
|
||||
});
|
||||
|
||||
@@ -49,8 +51,8 @@ const handleCardTap = () => {
|
||||
emit('item-click', props.item.id);
|
||||
};
|
||||
|
||||
const handleAction = (actionValue) => {
|
||||
emit('action-click', props.item, actionValue);
|
||||
const handleAction = async (action) => {
|
||||
emit('action-click', props.item, action);
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<text class="rank-num" :class="'rank-' + (index + 1)">{{ index + 1 }}</text>
|
||||
<image class="item-avatar" :src="FILE_BASE_URL + item.avatarUrl" mode="aspectFill"></image>
|
||||
<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>
|
||||
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user