WebIndex/components/card/ArticleCard.vue

47 lines
1.7 KiB
Vue
Raw Normal View History

2024-11-17 11:45:08 +08:00
<script lang="ts" setup>
import {computed} from "vue";
const props = defineProps<{
post: IPost
}>()
const thumbUrl = computed(() => {
// 如果文章缩略图为空,则从本地随机获取默认缩略图
props.post.fields.thumb.value = props.post.fields.thumb.value ? props.post.fields.thumb.value : getAssetURL(
2024-11-17 13:05:55 +08:00
`common/${Math.floor(Math.random() * (7 - 1 + 1)) + 1}.jpg`
2024-11-17 11:45:08 +08:00
)
return props.post.fields.thumb.value
})
</script>
<template>
2024-12-02 20:00:21 +08:00
<nuxt-link :title="post.title"
2024-11-17 11:45:08 +08:00
class="container relative h-56 overflow-hidden rounded-2xl text-white hover:cursor-pointer hover:text-amber-200 hover:shadow-lg"
2024-12-02 20:00:21 +08:00
:to="{name: 'blog-cid', params: {cid: post.cid}}">
2024-11-17 11:45:08 +08:00
<!-- 图片 -->
<div class="container h-full">
<img :src="thumbUrl" alt=""
class="h-full w-full object-cover object-center transition-all duration-300 hover:scale-110">
</div>
<!-- 文字部分 -->
<div class="container relative">
<div class="absolute bottom-0 h-12 w-full truncate bg-black bg-opacity-60 p-2 leading-8 backdrop-blur-3xl">
<span class="px-1 text-xl font-bold transition-all">{{ post.title }}</span>
</div>
</div>
<!-- 分类 -->
<div class="absolute top-0 left-0 m-2 rounded-lg bg-black bg-opacity-60 px-2 text-white backdrop-blur-3xl">
<span>{{ post.category }}</span>
</div>
<!-- 日期 -->
<div class="absolute right-0 bottom-12 m-2 rounded-lg bg-black bg-opacity-60 px-2 text-white backdrop-blur-3xl">
<font-awesome-icon :icon="['far', 'clock']" class="mr-1 text-sm"/>
<span>{{ post.date.year }}-{{ post.date.month }}-{{ post.date.day }}</span>
</div>
2024-12-02 20:00:21 +08:00
</nuxt-link>
2024-11-17 11:45:08 +08:00
</template>
<style scoped>
</style>