Compare commits

..

1 Commits

Author SHA1 Message Date
Tim
2322b2da15 feat: remember selected tab 2025-08-16 16:10:37 +08:00
2 changed files with 13 additions and 49 deletions

View File

@@ -150,6 +150,13 @@ const topics = ref(['最新回复', '最新', '排行榜' /*, '热门', '类别'
const selectedTopic = ref(
route.query.view === 'ranking' ? '排行榜' : route.query.view === 'latest' ? '最新' : '最新回复',
)
if (import.meta.client) {
const storedTopic = localStorage.getItem('home-selected-topic')
if (storedTopic && topics.value.includes(storedTopic)) {
selectedTopic.value = storedTopic
}
}
const articles = ref([])
const page = ref(0)
const pageSize = 10
@@ -340,7 +347,10 @@ watch(
watch([selectedCategory, selectedTags], () => {
loadOptions()
})
watch(selectedTopic, () => {
watch(selectedTopic, (topic) => {
if (import.meta.client) {
localStorage.setItem('home-selected-topic', topic)
}
// 仅当需要额外选项时加载
loadOptions()
})

View File

@@ -204,32 +204,12 @@
</div>
<div v-else-if="selectedTab === 'timeline'" class="profile-timeline">
<div class="timeline-tabs">
<div
:class="['timeline-tab-item', { selected: timelineFilter === 'all' }]"
@click="timelineFilter = 'all'"
>
全部
</div>
<div
:class="['timeline-tab-item', { selected: timelineFilter === 'articles' }]"
@click="timelineFilter = 'articles'"
>
文章
</div>
<div
:class="['timeline-tab-item', { selected: timelineFilter === 'comments' }]"
@click="timelineFilter = 'comments'"
>
评论和回复
</div>
</div>
<BasePlaceholder
v-if="filteredTimelineItems.length === 0"
v-if="timelineItems.length === 0"
text="暂无时间线"
icon="fas fa-inbox"
/>
<BaseTimeline :items="filteredTimelineItems">
<BaseTimeline :items="timelineItems">
<template #item="{ item }">
<template v-if="item.type === 'post'">
发布了文章
@@ -344,15 +324,6 @@ const hotPosts = ref([])
const hotReplies = ref([])
const hotTags = ref([])
const timelineItems = ref([])
const timelineFilter = ref('all')
const filteredTimelineItems = computed(() => {
if (timelineFilter.value === 'articles') {
return timelineItems.value.filter((item) => item.type === 'post')
} else if (timelineFilter.value === 'comments') {
return timelineItems.value.filter((item) => item.type === 'comment' || item.type === 'reply')
}
return timelineItems.value
})
const followers = ref([])
const followings = ref([])
const medals = ref([])
@@ -806,23 +777,6 @@ watch(selectedTab, async (val) => {
width: 40%;
}
.timeline-tabs {
display: flex;
flex-direction: row;
border-bottom: 1px solid var(--normal-border-color);
margin-bottom: 10px;
}
.timeline-tab-item {
padding: 10px 20px;
cursor: pointer;
}
.timeline-tab-item.selected {
color: var(--primary-color);
border-bottom: 2px solid var(--primary-color);
}
.profile-timeline {
padding: 20px;
}