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) => {