@ -61,7 +61,6 @@ const selectedTags = ref<string[]>(
: [ ] ,
: [ ] ,
)
)
const tagMode = ref < TagMode > ( route . query . tagMode === 'and' ? 'and' : 'or' )
const tagMode = ref < TagMode > ( route . query . tagMode === 'and' ? 'and' : 'or' )
const availableTags = ref < string [ ] > ( [ ] )
const tagModeItems = [
const tagModeItems = [
{ label : '任一命中 (OR)' , value : 'or' } ,
{ label : '任一命中 (OR)' , value : 'or' } ,
{ label : '全部命中 (AND)' , value : 'and' } ,
{ label : '全部命中 (AND)' , value : 'and' } ,
@ -98,12 +97,13 @@ const { data, pending, error } = await useAsyncData(
{ watch : [ slug , page , selectedTags , tagMode ] } ,
{ watch : [ slug , page , selectedTags , tagMode ] } ,
)
)
watch (
const availableTags = computed ( ( ) => {
( ) => data . value ? . availableTags ,
const byApi = data . value ? . availableTags ? ? [ ]
( ) => {
const byItems = ( data . value ? . items ? ? [ ] )
availableTags . value = data . value ? . availableTags ? ? [ ]
. flatMap ( item => item . tags ? ? [ ] )
} ,
. filter ( Boolean )
)
return [ ... new Set ( [ ... byApi , ... byItems ] ) ]
} )
watch (
watch (
( ) => [ route . query . tags , route . query . tagMode ] as const ,
( ) => [ route . query . tags , route . query . tagMode ] as const ,
@ -166,39 +166,39 @@ usePageTitle(() => {
class = "my-6"
class = "my-6"
/ >
/ >
< template v -else -if = " data " >
< template v -else -if = " data " >
< UCard class = "mb-4" : ui = "{ body: 'p-4 space-y-3' }" >
< div class = "flex items-center justify-between gap-2" >
< div class = "text-sm text-muted" >
标签筛选
< / div >
< UButton
size = "xs"
color = "neutral"
variant = "ghost"
@ click = "selectedTags = []; tagMode = 'or'; updateFilterQuery(1)"
>
清空
< / UButton >
< / div >
< PostTagsInput
: model - value = "selectedTags"
: suggestions = "availableTags"
placeholder = "输入标签回车筛选"
@ update : model - value = "(v) => { selectedTags = v; updateFilterQuery(1) }"
/ >
< USelect
v - model = "tagMode"
: items = "tagModeItems"
class = "w-full sm:w-56"
@ update : model - value = "() => updateFilterQuery(1)"
/ >
< / UCard >
< UEmpty
< UEmpty
v - if = "data.total === 0"
v - if = "data.total === 0"
: title = "selectedTags.length ? '没有匹配结果' : '暂无公开文章'"
: title = "selectedTags.length ? '没有匹配结果' : '暂无公开文章'"
: description = "selectedTags.length ? '请尝试调整标签筛选条件。' : '站主尚未发布任何公开文章。'"
: description = "selectedTags.length ? '请尝试调整标签筛选条件。' : '站主尚未发布任何公开文章。'"
/ >
/ >
< template v-else >
< template v-else >
< UCard class = "mb-4" : ui = "{ body: 'p-4 space-y-3' }" >
< div class = "flex items-center justify-between gap-2" >
< div class = "text-sm text-muted" >
标签筛选
< / div >
< UButton
size = "xs"
color = "neutral"
variant = "ghost"
@ click = "selectedTags = []; tagMode = 'or'; updateFilterQuery(1)"
>
清空
< / UButton >
< / div >
< PostTagsInput
: model - value = "selectedTags"
: suggestions = "availableTags"
placeholder = "输入标签回车筛选"
@ update : model - value = "(v) => { selectedTags = v; updateFilterQuery(1) }"
/ >
< USelect
v - model = "tagMode"
: items = "tagModeItems"
class = "w-full sm:w-56"
@ update : model - value = "() => updateFilterQuery(1)"
/ >
< / UCard >
< h2 class = "text-xs font-semibold uppercase tracking-wider text-muted mb-4" >
< h2 class = "text-xs font-semibold uppercase tracking-wider text-muted mb-4" >
文章
文章
< / h2 >
< / h2 >