Compare commits

..

1 Commits

Author SHA1 Message Date
Tim 2322b2da15 feat: remember selected tab 2025-08-16 16:10:37 +08:00
+11 -13
View File
@@ -147,18 +147,14 @@ const categoryOptions = ref([])
const isLoadingMore = ref(false) const isLoadingMore = ref(false)
const topics = ref(['最新回复', '最新', '排行榜' /*, '热门', '类别'*/]) const topics = ref(['最新回复', '最新', '排行榜' /*, '热门', '类别'*/])
const HOME_TAB_KEY = 'homeTab' const selectedTopic = ref(
const routeDefault = route.query.view === 'ranking' ? '排行榜' : route.query.view === 'latest' ? '最新' : '最新回复',
route.query.view === 'ranking' ? '排行榜' : route.query.view === 'latest' ? '最新' : null )
const selectedTopic = ref(routeDefault || '最新回复')
if (import.meta.client) { if (import.meta.client) {
if (routeDefault) { const storedTopic = localStorage.getItem('home-selected-topic')
localStorage.setItem(HOME_TAB_KEY, routeDefault) if (storedTopic && topics.value.includes(storedTopic)) {
} else { selectedTopic.value = storedTopic
const stored = localStorage.getItem(HOME_TAB_KEY)
if (stored && topics.value.includes(stored)) {
selectedTopic.value = stored
}
} }
} }
const articles = ref([]) const articles = ref([])
@@ -351,8 +347,10 @@ watch(
watch([selectedCategory, selectedTags], () => { watch([selectedCategory, selectedTags], () => {
loadOptions() loadOptions()
}) })
watch(selectedTopic, (val) => { watch(selectedTopic, (topic) => {
if (import.meta.client) localStorage.setItem(HOME_TAB_KEY, val) if (import.meta.client) {
localStorage.setItem('home-selected-topic', topic)
}
// 仅当需要额外选项时加载 // 仅当需要额外选项时加载
loadOptions() loadOptions()
}) })