-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
209 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,38 @@ | ||
import { ref } from 'vue' | ||
import { ref, provide, inject } from 'vue' | ||
|
||
export const useBannerContent = () => { | ||
const bannerContentSymbol = Symbol('bannerContent') | ||
|
||
export function useBannerContent() { | ||
const bannerContent = ref('') | ||
const bannerImageUrl = ref('/banner2.jpeg') // 默认背景图 | ||
|
||
const setBannerContent = (content: string) => { | ||
bannerContent.value = content | ||
} | ||
|
||
const setBannerImage = (url: string) => { | ||
bannerImageUrl.value = url | ||
} | ||
|
||
provide(bannerContentSymbol, { | ||
bannerContent, | ||
bannerImageUrl, | ||
setBannerContent, | ||
setBannerImage | ||
}) | ||
|
||
return { | ||
bannerContent, | ||
setBannerContent | ||
bannerImageUrl, | ||
setBannerContent, | ||
setBannerImage | ||
} | ||
} | ||
|
||
export function useBannerContentInjection() { | ||
const bannerContext = inject(bannerContentSymbol) | ||
if (!bannerContext) { | ||
throw new Error('useBannerContentInjection must be used within a component that has called useBannerContent') | ||
} | ||
return bannerContext | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,45 @@ | ||
<template> | ||
<div class="container mx-auto px-4"> | ||
<RepoTimeline :blogPosts="blogPosts" /> | ||
<RepoTimeline :blogPosts="blogPosts" :current-page="currentPage" :total-items="totalItems" :per-page="perPage" @page-change="onPageChange" /> | ||
</div> | ||
</template> | ||
<script setup lang="ts"> | ||
import { useRoute } from 'vue-router' | ||
import { useBannerContent } from '~/composables/useBannerContent' | ||
import { useBannerContentInjection } from '~/composables/useBannerContent' | ||
const { setBannerContent, setBannerImage } = useBannerContentInjection() | ||
const route = useRoute() | ||
const { setBannerContent } = useBannerContent() | ||
const config = useRuntimeConfig() | ||
const { data: fetchedBlogPosts } = await useAsyncData('taggedPosts', () => | ||
$fetch(`/api/repo/${route.params.repo_owner}/${route.params.repo_name}/blog-posts`, { | ||
params: { tag: route.params.name } | ||
}) | ||
) | ||
const blogPosts = ref([]) | ||
// 当数据获取完成后,更新 blogPosts | ||
blogPosts.value = fetchedBlogPosts.value?.blogPosts || [] | ||
const currentPage = ref(1) | ||
const totalItems = ref(0) | ||
const perPage = ref(parseInt(config.public.perPageSize) || 20) | ||
const fetchBlogPosts = async (page = 1) => { | ||
const { data: fetchedData } = await useAsyncData('blogPosts', () => | ||
$fetch(`/api/repo/${config.public.repoOwner}/${config.public.repoName}/blog-posts`, { | ||
params: { page, perPage: perPage.value, tag: route.params.name } | ||
}) | ||
) | ||
blogPosts.value = fetchedData.value?.blogPosts || [] | ||
totalItems.value = fetchedData.value?.pagination.totalItems || 0 | ||
perPage.value = fetchedData.value?.pagination.perPage || 20 | ||
currentPage.value = fetchedData.value?.pagination.currentPage || 1 | ||
} | ||
console.log(blogPosts.value) | ||
// Fetch initial data | ||
await fetchBlogPosts() | ||
// console.log(totalItems.value, perPage.value, currentPage.value) | ||
// Handle page changes | ||
const onPageChange = async (page: number) => { | ||
await fetchBlogPosts(page) | ||
} | ||
setBannerContent(`<h1 class="text-4xl font-extrabold text-center text-white mb-6">Posts tagged with "${route.params.name}"</h1>`) | ||
setBannerImage("/banner3.jpeg") | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.