From 0f9e35a0df57a12a360e89a06ff61495c0bc79bf Mon Sep 17 00:00:00 2001 From: Mohan Date: Mon, 17 Aug 2026 17:50:31 +0800 Subject: [PATCH] feat(page): add homepage carousel for top 3 popular articles --- src/components/Carousel.vue | 236 ++++++++++++++++++++++++++++++++++++ src/views/HomeView.vue | 48 +++++--- 2 files changed, 270 insertions(+), 14 deletions(-) create mode 100644 src/components/Carousel.vue diff --git a/src/components/Carousel.vue b/src/components/Carousel.vue new file mode 100644 index 0000000..d5d4079 --- /dev/null +++ b/src/components/Carousel.vue @@ -0,0 +1,236 @@ + + + + + diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index 3fce5ab..d11ff7b 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -6,6 +6,7 @@ import { ArticleStatus, type ArticleListItem } from '@/generated/api' import ArticleCard from '@/components/ArticleCard.vue' import Pagination from '@/components/Pagination.vue' import TagCloud from '@/components/TagCloud.vue' +import Carousel from '@/components/Carousel.vue' const route = useRoute() @@ -16,6 +17,8 @@ const totalPages = ref(0) const loading = ref(false) const error = ref(null) +const popularArticles = ref([]) + async function load() { loading.value = true error.value = null @@ -33,12 +36,25 @@ async function load() { } } +async function loadPopular() { + try { + const resp = await articleApi.apiArticlesPopularGet(3) + const data = resp.data.data + popularArticles.value = (data as ArticleListItem[]) ?? [] + } catch (e) { + console.error(e) + } +} + function onPageChange(p: number) { page.value = p load() } -onMounted(load) +onMounted(() => { + load() + loadPopular() +}) watch( () => route.query.tag, @@ -50,20 +66,23 @@ watch( @@ -72,6 +91,7 @@ watch( display: flex; gap: 24px; align-items: flex-start; + margin-top: 24px; } .home-main { @@ -115,4 +135,4 @@ watch( width: 100%; } } - \ No newline at end of file +