From baad90fb0e404c2d3a68ffed246570e17af7e18f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=8E=AB=E5=94=90=E5=B0=BC?= Date: Wed, 9 Sep 2026 03:13:20 +0800 Subject: [PATCH] =?UTF-8?q?refactor(articles):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E7=AD=9B=E9=80=89=E6=8E=92=E5=BA=8FUI=E4=B8=8E=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将原有的弹窗筛选改为顶部分类tab和内联排序行,拆分筛选配置为分类和排序独立数据,移除筛选弹层逻辑 --- src/pages-blog/articles/articles.vue | 131 +++++++++------------------ 1 file changed, 43 insertions(+), 88 deletions(-) diff --git a/src/pages-blog/articles/articles.vue b/src/pages-blog/articles/articles.vue index a2bbce7..417a6d1 100644 --- a/src/pages-blog/articles/articles.vue +++ b/src/pages-blog/articles/articles.vue @@ -32,18 +32,12 @@ const hasNext = ref(false) const isLoadMore = ref(false) const loadMoreText = ref(t('common.loading')) -/* ---------------- 筛选与排序(参考投票中心) ---------------- */ +/* ---------------- 筛选与排序(内联:分类参考图库顶部,排序一排) ---------------- */ interface IFilterOption { label: string value: string } -interface IFilterItem { - key: 'category' | 'sort' - label: string - options: IFilterOption[] -} - /** 分类列表(筛选选项数据源) */ const categoryList = ref([]) @@ -55,55 +49,28 @@ const sortMap: Record = { pinned: ['spec.pinned,desc'], } -/** 筛选维度:分类筛选 + 排序 */ -const filterConfig = computed(() => [ - { - key: 'category', - label: '分类', - options: [ - { label: '全部', value: '' }, - ...categoryList.value.map(c => ({ label: c.spec.displayName, value: c.metadata.name })), - ], - }, - { - key: 'sort', - label: '排序', - options: [ - { label: '默认排序', value: 'default' }, - { label: '最新', value: 'latest' }, - { label: '最旧', value: 'oldest' }, - { label: '置顶', value: 'pinned' }, - ], - }, +/** 分类选项(含"全部",参考图库顶部设计) */ +const categoryOptions = computed(() => [ + { label: '全部', value: '' }, + ...categoryList.value.map(c => ({ label: c.spec.displayName, value: c.metadata.name })), ]) +/** 排序选项(一排内联) */ +const sortOptions: IFilterOption[] = [ + { label: '默认排序', value: 'default' }, + { label: '最新', value: 'latest' }, + { label: '最旧', value: 'oldest' }, + { label: '置顶', value: 'pinned' }, +] + /** 各维度当前选中值(空串 = 全部) */ const filterValues = ref>({ category: '', sort: 'default' }) -/** 当前选中中文标签(用于筛选栏展示) */ -const filterLabels = computed(() => { - const map: Record = {} - for (const f of filterConfig.value) { - const cur = filterValues.value[f.key] - map[f.key] = f.options.find(o => o.value === cur)?.label || f.options[0].label - } - return map -}) - -/** 筛选弹层 */ -const filterPopup = ref<{ show: boolean, item: IFilterItem | null }>({ show: false, item: null }) - -function handleOpenFilter(item: IFilterItem) { - filterPopup.value = { show: true, item } -} - -/** 选择筛选/排序:重置分页并重新查询 */ -function handleSelectFilter(option: IFilterOption) { - const item = filterPopup.value.item - if (!item) +/** 切换分类/排序:重置分页并重新查询 */ +function handleSelectFilter(key: 'category' | 'sort', value: string) { + if (filterValues.value[key] === value) return - filterValues.value[item.key] = option.value - filterPopup.value.show = false + filterValues.value[key] = value isLoadMore.value = false articleList.value = [] queryParams.value.page = 1 @@ -228,18 +195,33 @@ onReachBottom(() => { - - - - {{ filterLabels[f.key] }} - + + + + + {{ cate.label }} + + + + + + + + + {{ opt.label }} + - + { {{ loadMoreText }} - - - - - - - - - - - {{ filterPopup.item.label }} - - - - {{ opt.label }} - - - -