1
0
mirror of https://github.com/ialley-workshop-open/uni-halo.git synced 2026-11-13 22:11:42 +08:00

feat: 重构文章卡片与列表页,新增多布局与筛选功能

1. 新增文章卡片grid紧凑布局,支持隐藏分类标签与单行摘要
2. 重构文章列表页,添加分类筛选、排序功能与两列卡片布局
3. 首页新增推荐模式切换,支持默认/置顶/最新/最旧排序
4. 统一代码缩进与格式规范,完善类型定义与注释
This commit is contained in:
小莫唐尼
2026-09-09 03:06:17 +08:00
parent 9cd21be138
commit b4239da1af
3 changed files with 646 additions and 312 deletions
@@ -1,105 +1,125 @@
<script lang="ts" setup>
import { computed } from 'vue'
import { checkThumbnailUrl } from '@/utils/url'
import { useSettingStore } from '@/store/setting'
import { formatTime } from '@/utils/formatTime'
import type { IPost,ICategory } from '@/api/types/halo'
import { computed } from 'vue'
import { checkThumbnailUrl } from '@/utils/url'
import { useSettingStore } from '@/store/setting'
import { formatTime } from '@/utils/formatTime'
import type { ICategory, IPost } from '@/api/types/halo'
const props = withDefaults(defineProps<{
from ?: string
auditMode?: boolean
article : IPost
}>(), {
auditMode: false,
from: '',
})
const props = withDefaults(defineProps<{
from?: string
auditMode?: boolean
article: IPost
/** 卡片形态:list=常规列表卡(默认),grid=两列紧凑卡(隐藏分类/标签,摘要单行) */
variant?: 'list' | 'grid'
}>(), {
auditMode: false,
from: '',
variant: 'list',
})
const settingStore = useSettingStore()
const settingStore = useSettingStore()
/** 卡片布局 class(由全局设置 layout 决定) */
const cardType = computed(() => {
const layout = settingStore.settings.layout
// 首页双列时强制上图下文布局,除非显式指定其他
if (props.from === 'home' && layout.home === 'h_row_col2') {
if (!['tb_image_text', 'tb_text_image', 'only_text'].includes(layout.cardType)) {
return [props.from, layout.home, 'tb_image_text']
}
return [props.from, layout.home, layout.cardType]
}
return [layout.home, layout.cardType]
})
/** 卡片布局 class(由全局设置 layout 决定) */
const cardType = computed(() => {
const layout = settingStore.settings.layout
// 首页双列时强制上图下文布局,除非显式指定其他
if (props.from === 'home' && layout.home === 'h_row_col2') {
if (!['tb_image_text', 'tb_text_image', 'only_text'].includes(layout.cardType)) {
return [props.from, layout.home, 'tb_image_text']
}
return [props.from, layout.home, layout.cardType]
}
return [layout.home, layout.cardType]
})
/** 发布时间格式化 yyyy-MM-dd */
const publishTimeText = computed(() => {
const time = props.article.spec.publishTime
return time ? formatTime({ d: time, f: 'yyyy-MM-dd' }) : ''
})
/** grid 紧凑模式(两列:隐藏分类/标签,摘要单行,底部精简) */
const isGrid = computed(() => props.variant === 'grid')
/** 阅读数(兼容 status.stats.visits 与旧版顶层 stats.visit) */
const visitCount = computed(() => {
return props.article.status?.stats?.visits ?? props.article.stats?.visit ?? 0
})
/** 发布时间格式化 yyyy-MM-dd */
const publishTimeText = computed(() => {
const time = props.article.spec.publishTime
return time ? formatTime({ d: time, f: 'yyyy-MM-dd' }) : ''
})
function handleToArticleDetail() {
uni.navigateTo({
url: `/pages-blog/article-detail/article-detail?name=${props.article.metadata.name}`,
animationType: 'slide-in-right',
})
}
function handleToCategory(category : ICategory) {
if (props.auditMode) {
return
}
uni.navigateTo({
url: `/pages-blog/category-articles/category-articles?name=${category.metadata.name}&title=${category.spec.displayName}`,
})
}
/** 阅读数(兼容 status.stats.visits 与旧版顶层 stats.visit) */
const visitCount = computed(() => {
return props.article.status?.stats?.visits ?? props.article.stats?.visit ?? 0
})
function handleToArticleDetail() {
uni.navigateTo({
url: `/pages-blog/article-detail/article-detail?name=${props.article.metadata.name}`,
animationType: 'slide-in-right',
})
}
function handleToCategory(category: ICategory) {
if (props.auditMode) {
return
}
uni.navigateTo({
url: `/pages-blog/category-articles/category-articles?name=${category.metadata.name}&title=${category.spec.displayName}`,
})
}
</script>
<template>
<view class="uh-global-card-glass uh-shadow-xs overflow-hidden relative rounded-xl p-3"
@click.stop="handleToArticleDetail()">
<text v-if="article.spec.pinned"
class="absolute right-6 top-6 z-1 bg-secondary text-gray-60 text-xs px-2 py-1 rounded-lg"> 置顶 </text>
<image class="w-full h-36 rounded-lg" :src="checkThumbnailUrl(article.spec.cover)" mode="aspectFill"
lazy-load />
<view class="flex flex-col w-full gap-y-2 text-sm">
<view class="mt-2 font-bold truncate">
{{ article.spec.title }}
</view>
<view class="content line-clamp-2 text-gray-600">
{{ article.status?.excerpt }}
</view>
<view class="my-1 box-border flex flex-wrap gap-2">
<template v-if="article.categories && article.categories.length !== 0">
<text v-for="cate in article.categories" :key="cate.metadata.name"
class="py-1 px-2 text-xs rounded-xl bg-secondary" @click.stop="handleToCategory(cate)">
{{ cate.spec.displayName }}
</text>
</template>
<template v-if="article.tags && article.tags.length !== 0">
<text v-for="tag in article.tags" :key="tag.metadata.name"
class="py-1 px-2 text-xs rounded-xl bg-secondary">
# {{ tag.spec.displayName }}
</text>
</template>
</view>
<view class="flex items-center justify-between text-xs text-gray-500">
<view class="flex items-center gap-x-1">
<image :src="article.owner.avatar" class="uh-global-card-glass rounded-full w-5 h-5"
mode="aspectFill"></image>
<text>{{article.owner.displayName}}</text>
</view>
<view class="flex items-center gap-x-2">
{{ publishTimeText }}
</view>
<view class="visits">
浏览
<text class="number">{{ visitCount }}</text>
次
</view>
</view>
</view>
</view>
</template>
<view
class="uh-global-card-glass uh-shadow-xs relative overflow-hidden rounded-xl p-3"
@click.stop="handleToArticleDetail()"
>
<text
v-if="article.spec.pinned"
class="text-gray-60 absolute right-6 top-6 z-1 rounded-lg bg-secondary px-2 py-1 text-xs"
>
置顶
</text>
<image
:class="isGrid ? 'w-full h-24 rounded-lg' : 'w-full h-36 rounded-lg'"
:src="checkThumbnailUrl(article.spec.cover)" mode="aspectFill" lazy-load
/>
<view class="w-full flex flex-col gap-y-2 text-sm">
<view class="mt-2 truncate font-bold">
{{ article.spec.title }}
</view>
<view :class="isGrid ? 'content line-clamp-1 text-gray-600' : 'content line-clamp-2 text-gray-600'">
{{ article.status?.excerpt }}
</view>
<view v-if="!isGrid" class="my-1 box-border flex flex-wrap gap-2">
<template v-if="article.categories && article.categories.length !== 0">
<text
v-for="cate in article.categories" :key="cate.metadata.name"
class="rounded-xl bg-secondary px-2 py-1 text-xs" @click.stop="handleToCategory(cate)"
>
{{ cate.spec.displayName }}
</text>
</template>
<template v-if="article.tags && article.tags.length !== 0">
<text
v-for="tag in article.tags" :key="tag.metadata.name"
class="rounded-xl bg-secondary px-2 py-1 text-xs"
>
# {{ tag.spec.displayName }}
</text>
</template>
</view>
<view class="mt-1 flex items-center justify-between text-xs text-gray-500">
<view v-if="!isGrid" class="flex items-center gap-x-1">
<image
:src="article.owner.avatar" class="uh-global-card-glass h-5 w-5 rounded-full"
mode="aspectFill"
/>
<text>{{ article.owner.displayName }}</text>
</view>
<view class="flex items-center gap-x-2">
{{ publishTimeText }}
</view>
<view class="visits">
浏览
<text class="number">{{ visitCount }}</text>
次
</view>
</view>
</view>
</view>
</template>