数据结构优化
This commit is contained in:
@@ -226,8 +226,34 @@ const highlightText = (text: string | undefined) => {
|
||||
return text.replace(regex, '<span class="text-art-accent bg-art-accent/10 font-bold">$1</span>')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadFilters()
|
||||
onMounted(async () => {
|
||||
// 先加载筛选选项
|
||||
await loadFilters()
|
||||
|
||||
// 从 sessionStorage 读取传递的参数(不在URL显示)
|
||||
const categoryId = sessionStorage.getItem('blogFilterCategoryId')
|
||||
const tagId = sessionStorage.getItem('blogFilterTagId')
|
||||
|
||||
// 如果存在参数,设置对应的选中值
|
||||
if (categoryId) {
|
||||
const id = Number(categoryId)
|
||||
if (id > 0) {
|
||||
selectedCategoryId.value = id
|
||||
// 读取后清除,避免下次访问时仍然应用
|
||||
sessionStorage.removeItem('blogFilterCategoryId')
|
||||
}
|
||||
}
|
||||
|
||||
if (tagId) {
|
||||
const id = Number(tagId)
|
||||
if (id > 0) {
|
||||
selectedTagId.value = id
|
||||
// 读取后清除,避免下次访问时仍然应用
|
||||
sessionStorage.removeItem('blogFilterTagId')
|
||||
}
|
||||
}
|
||||
|
||||
// 应用筛选并获取文章列表
|
||||
fetchBlogPosts()
|
||||
refreshIcons()
|
||||
})
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
分类
|
||||
</h3>
|
||||
<a
|
||||
@click.prevent="router.push(`/blog?category=${post.categoryId}`)"
|
||||
@click.prevent="handleCategoryClick(post.categoryId)"
|
||||
href="#"
|
||||
class="block p-3 rounded-lg bg-white/5 border border-white/10 hover:bg-white/10 hover:border-art-accent/50 transition-all duration-200 group"
|
||||
>
|
||||
@@ -84,7 +84,7 @@
|
||||
<a
|
||||
v-for="tag in post.tags"
|
||||
:key="tag.id"
|
||||
@click.prevent="router.push(`/blog?tag=${tag.id}`)"
|
||||
@click.prevent="handleTagClick(tag.id)"
|
||||
href="#"
|
||||
class="px-2.5 py-1 rounded-md bg-white/5 border border-white/10 hover:bg-art-accent/20 hover:border-art-accent/50 hover:text-art-accent text-xs text-art-muted transition-all duration-200"
|
||||
>
|
||||
@@ -139,7 +139,7 @@
|
||||
<a
|
||||
v-for="tag in post.tags"
|
||||
:key="tag.id"
|
||||
@click.prevent="router.push(`/blog?tag=${tag.id}`)"
|
||||
@click.prevent="handleTagClick(tag.id)"
|
||||
href="#"
|
||||
class="px-3 py-1.5 rounded-full bg-white/5 border border-white/10 text-xs text-art-muted hover:text-white hover:bg-white/10 transition-colors"
|
||||
>
|
||||
@@ -314,6 +314,18 @@ const router = useRouter()
|
||||
const postId = route.params.id as string
|
||||
const articleRef = ref<HTMLElement | null>(null)
|
||||
|
||||
// 处理分类点击,使用 sessionStorage 传递参数(不在URL显示)
|
||||
const handleCategoryClick = (categoryId: number) => {
|
||||
sessionStorage.setItem('blogFilterCategoryId', categoryId.toString())
|
||||
router.push('/blog')
|
||||
}
|
||||
|
||||
// 处理标签点击,使用 sessionStorage 传递参数(不在URL显示)
|
||||
const handleTagClick = (tagId: number) => {
|
||||
sessionStorage.setItem('blogFilterTagId', tagId.toString())
|
||||
router.push('/blog')
|
||||
}
|
||||
|
||||
// 目录相关状态
|
||||
interface TocItem {
|
||||
id: string
|
||||
|
||||
Reference in New Issue
Block a user