1
0
mirror of https://github.com/ialley-workshop-open/uni-halo.git synced 2026-07-27 04:20:43 +08:00
Files
uni-halo/src/components/uh-post-card/uh-post-card.vue
T
小莫唐尼 b56de87856 refactor(home&post-card): 调整点击事件绑定位置并优化空状态样式
1. 将作者卡片的点击事件从子组件移到父容器上,简化子组件依赖
2. 给空状态提示容器添加box-border类统一样式规范
3. 为文章卡片添加点击跳转详情页的逻辑
2026-06-15 13:32:56 +08:00

153 lines
4.2 KiB
Vue

<script setup lang="ts">
import { completeUrl } from '@/utils/url'
import { timeFrom } from '@/utils/base/timeFrom'
import type { ListedPostVo } from '@halo-dev/api-client'
interface IProps {
post?: ListedPostVo
type?: 'noCover' | 'leftCover' | 'bottomCover' | 'rightCover' | 'topCover'
}
const props = withDefaults(defineProps<IProps>(), {
type: 'leftCover',
post: undefined,
})
const wrapClass = computed(() => {
if (props.type === 'topCover') {
return 'flex-col gap-y-4'
}
if (props.type === 'rightCover') {
return 'relative h-28 p-0! border-2 border-solid border-white'
}
if (props.type === 'noCover') {
return 'pl-0'
}
if (props.type === 'leftCover') {
return ' '
}
if (props.type === 'bottomCover') {
return 'flex-col gap-y-2'
}
return ''
})
const coverClass = computed(() => {
if (props.type === 'topCover') {
return 'h-32 w-full'
}
if (props.type === 'rightCover') {
return 'absolute right-0 top-0 bottom-0 w-32 rounded-lt-0 rounded-lb-0'
}
if (props.type === 'noCover') {
return 'hidden!'
}
if (props.type === 'leftCover') {
return 'h-22 w-22'
}
if (props.type === 'bottomCover') {
return 'w-full h-32 order-2'
}
return ''
})
const textWrapClass = computed(() => {
if (props.type === 'topCover') {
return ''
}
if (props.type === 'rightCover') {
return 'p-4 pr-32 relative z-10'
}
if (props.type === 'bottomCover') {
return 'order-1'
}
return 'pl-4'
})
const textContainerClass = computed(() => {
if (props.type === 'topCover') {
return 'gap-y-2'
}
if (props.type === 'noCover') {
return 'gap-y-2'
}
if (props.type === 'rightCover') {
return ''
}
if (props.type === 'bottomCover') {
return 'gap-y-2'
}
return ''
})
const textFooterClass = computed(() => {
if (props.type === 'topCover') {
return 'justify-between gap-x-2'
}
if (props.type === 'rightCover') {
return 'gap-x-2'
}
if (props.type === 'bottomCover') {
return ''
}
return 'gap-x-2'
})
function handleToPostDetail() {
uni.navigateTo({
url: `/pages-blog/post-detail/post-detail?metadataName=${props.post.metadata.name}`,
})
}
</script>
<template>
<view v-if="post" class="uh-shadow-xs box-border w-full flex justify-center overflow-hidden rounded-2xl bg-white p-4" :class="wrapClass">
<view class="shrink-0 overflow-hidden rounded-lg" :class="coverClass" @click="handleToPostDetail">
<image :src="completeUrl(post.spec.cover)" mode="aspectFill" class="h-full w-full" />
<view v-if="props.type === 'rightCover'" class="absolute bottom-0 left-0 top-0 z-10 h-full w-full from-white/0 via-white/10 to-white bg-gradient-to-l" />
</view>
<view class="box-border flex-1" :class="textWrapClass">
<view class="h-full flex flex-1 flex-col justify-between" :class="textContainerClass">
<view class="line-clamp-1 text-sm text-gray-900 font-bold" @click="handleToPostDetail">
{{ post.spec.title }}
</view>
<view class="line-clamp-2 text-xs text-gray-500" @click="handleToPostDetail">
{{ post.status.excerpt }}
</view>
<view class="w-full flex items-center" :class="textFooterClass">
<view class="line-clamp-1 text-[11px] text-gray-600">
{{ timeFrom(post.spec.publishTime) }}
</view>
<view class="shrink-0 text-xs text-gray-600">
·
</view>
<view class="line-clamp-1 text-[11px] text-gray-600">
{{ post.categories.map(c => c.spec.displayName).join('·') }}
</view>
<template v-if="props.type === 'topCover'">
<view class="shrink-0 text-xs text-gray-600">
·
</view>
<view class="text-[11px] text-gray-600">
点赞 {{ post.stats.upvote }}
</view>
</template>
<view class="shrink-0 text-xs text-gray-600">
·
</view>
<view class="line-clamp-1 text-[11px] text-gray-600">
浏览 {{ post.stats.visit }}
</view>
</view>
</view>
</view>
</view>
</template>
<style scoped>
.uh-shadow-xs {
box-shadow: 0 0 24rpx rgba(0, 0, 0, 0.035);
}
</style>