From 9d4a34aa7241e83e7ce5e69952f0563ec8076c43 Mon Sep 17 00:00:00 2001 From: KUN1007 Date: Tue, 17 Oct 2023 23:41:04 +0800 Subject: [PATCH] feat: ranking page topic --- src/api/ranking/types/ranking.ts | 2 +- .../article/components/header/navSortItem.ts | 4 +- .../ranking/components/KUNGalgamerForm.vue | 2 +- src/views/ranking/components/Topic.vue | 88 ++++++++---- src/views/ranking/components/TopicForm.vue | 134 ++++++++++++++++-- 5 files changed, 190 insertions(+), 40 deletions(-) diff --git a/src/api/ranking/types/ranking.ts b/src/api/ranking/types/ranking.ts index 790cf619..ac895814 100644 --- a/src/api/ranking/types/ranking.ts +++ b/src/api/ranking/types/ranking.ts @@ -2,7 +2,7 @@ export interface RankingGetTopicsRequestData { page: number limit: number sortField: string - sortOrder: string + sortOrder: 'asc' | 'desc' } export interface RankingTopics { diff --git a/src/views/Home/content/article/components/header/navSortItem.ts b/src/views/Home/content/article/components/header/navSortItem.ts index a5ea1cd7..26842862 100644 --- a/src/views/Home/content/article/components/header/navSortItem.ts +++ b/src/views/Home/content/article/components/header/navSortItem.ts @@ -34,13 +34,13 @@ export const navSortItem: Sort[] = [ index: 5, icon: 'line-md:thumbs-up-twotone', name: 'likes', - sortField: 'likes', + sortField: 'likes_count', }, { index: 6, icon: 'ri:reply-line', name: 'replies', - sortField: 'replies', + sortField: 'replies_count', }, { index: 7, diff --git a/src/views/ranking/components/KUNGalgamerForm.vue b/src/views/ranking/components/KUNGalgamerForm.vue index 2bfed3e2..77a11457 100644 --- a/src/views/ranking/components/KUNGalgamerForm.vue +++ b/src/views/ranking/components/KUNGalgamerForm.vue @@ -6,7 +6,7 @@ import KUNgalgamer from './KUNGalgamer.vue'
-
最萌的萝莉
+
用户
diff --git a/src/views/ranking/components/Topic.vue b/src/views/ranking/components/Topic.vue index 100c8f89..c655efc3 100644 --- a/src/views/ranking/components/Topic.vue +++ b/src/views/ranking/components/Topic.vue @@ -10,7 +10,7 @@ const props = defineProps<{ const topics = computed(() => props.topics) -const icons: Record = { +const iconMap: Record = { popularity: 'bi:fire', upvotes_count: 'bi:rocket', views: 'ic:outline-remove-red-eye', @@ -26,33 +26,50 @@ const parseTopicNumber = (field: string | string[]) => { diff --git a/src/views/ranking/components/TopicForm.vue b/src/views/ranking/components/TopicForm.vue index 83fb9bf3..735fcbab 100644 --- a/src/views/ranking/components/TopicForm.vue +++ b/src/views/ranking/components/TopicForm.vue @@ -9,8 +9,10 @@ import { storeToRefs } from 'pinia' import type { RankingTopics } from '@/api' import { topicNavSortItem } from './navSortItem' -const { topic, user } = storeToRefs(useKUNGalgameRankingStore()) +const { topic } = storeToRefs(useKUNGalgameRankingStore()) const topics = ref([]) +// 升序降序 +const isAscending = ref(false) // 获取话题 const getTopics = async () => { @@ -18,6 +20,15 @@ const getTopics = async () => { return responseData.data } +const iconMap: Record = { + popularity: 'bi:fire', + upvotes_count: 'bi:rocket', + views: 'ic:outline-remove-red-eye', + likes_count: 'line-md:thumbs-up-twotone', + replies_count: 'ri:reply-line', + comments: 'fa-regular:comment-dots', +} + // 监听话题数据获取新话题 watch( () => topic, @@ -31,29 +42,53 @@ watch( onMounted(async () => { topics.value = await getTopics() }) + +// 切换排序方式 +const handleClickSortOrder = () => { + isAscending.value = !isAscending.value + if (isAscending.value) { + topic.value.sortOrder = 'asc' + } else { + topic.value.sortOrder = 'desc' + } +}