From f73a0d2d439cb9851d0b0aa3bbd75fd0d6fa0516 Mon Sep 17 00:00:00 2001 From: npmrun <1549469775@qq.com> Date: Sun, 26 Apr 2026 02:26:26 +0800 Subject: [PATCH] refactor(tags): streamline tag handling in post lists - Removed redundant state for available tags and replaced it with a computed property that consolidates tags from API and post items. - Enhanced the tag filtering UI by maintaining the existing structure while improving the logic for tag selection and clearing. - Updated the posts page to ensure consistent tag management across user and public views. These changes improve the efficiency of tag management and enhance the user experience in filtering posts by tags. --- app/pages/@[publicSlug]/posts/index.vue | 68 ++++++++++++++++---------------- app/pages/me/posts/index.vue | 10 ++++- packages/drizzle-pkg/db.sqlite | Bin 188416 -> 188416 bytes 3 files changed, 42 insertions(+), 36 deletions(-) diff --git a/app/pages/@[publicSlug]/posts/index.vue b/app/pages/@[publicSlug]/posts/index.vue index bfb9621..5c6d830 100644 --- a/app/pages/@[publicSlug]/posts/index.vue +++ b/app/pages/@[publicSlug]/posts/index.vue @@ -61,7 +61,6 @@ const selectedTags = ref( : [], ) const tagMode = ref(route.query.tagMode === 'and' ? 'and' : 'or') -const availableTags = ref([]) const tagModeItems = [ { label: '任一命中 (OR)', value: 'or' }, { label: '全部命中 (AND)', value: 'and' }, @@ -98,12 +97,13 @@ const { data, pending, error } = await useAsyncData( { watch: [slug, page, selectedTags, tagMode] }, ) -watch( - () => data.value?.availableTags, - () => { - availableTags.value = data.value?.availableTags ?? [] - }, -) +const availableTags = computed(() => { + const byApi = data.value?.availableTags ?? [] + const byItems = (data.value?.items ?? []) + .flatMap(item => item.tags ?? []) + .filter(Boolean) + return [...new Set([...byApi, ...byItems])] +}) watch( () => [route.query.tags, route.query.tagMode] as const, @@ -166,39 +166,39 @@ usePageTitle(() => { class="my-6" />