Files
schoolNews/schoolNewsWeb/src/views/public/article/card/HotArticleCard.vue

196 lines
4.7 KiB
Vue
Raw Normal View History

2025-10-27 19:05:56 +08:00
<template>
2025-10-31 19:13:21 +08:00
<div class="article-card" @click="handleClick">
2025-10-27 19:05:56 +08:00
<div class="article-image">
2025-10-31 19:13:21 +08:00
<img v-if="resource?.coverImage" :src="FILE_DOWNLOAD_URL + resource.coverImage" :alt="resource.title" />
<div v-else class="image-placeholder"></div>
2025-10-27 19:05:56 +08:00
<div class="article-tag">精选文章</div>
</div>
<div class="article-content">
2025-10-31 19:13:21 +08:00
<h3 class="article-title">{{ resource?.title || '标题' }}</h3>
2025-10-27 19:05:56 +08:00
<p class="article-desc">
2025-10-31 19:13:21 +08:00
{{ resource?.summary || '暂无简介' }}
2025-10-27 19:05:56 +08:00
</p>
<div class="article-footer">
<div class="meta-tag">
<el-icon><Document /></el-icon>
<span>热门文章</span>
</div>
2025-10-31 19:13:21 +08:00
<span class="view-count">{{ formatViewCount(resource?.viewCount || 0) }}</span>
2025-10-27 19:05:56 +08:00
</div>
</div>
</div>
</template>
<script setup lang="ts">
2025-10-31 19:13:21 +08:00
import { computed } from 'vue';
import { useRouter } from 'vue-router';
2025-10-27 19:05:56 +08:00
import { Document } from '@element-plus/icons-vue';
2025-10-31 19:13:21 +08:00
import type { ResourceRecommendVO } from '@/types';
import { FILE_DOWNLOAD_URL } from '@/config';
const props = defineProps<{
resource?: ResourceRecommendVO;
}>();
const router = useRouter();
// 格式化浏览量
function formatViewCount(count: number): string {
if (count < 1000) {
return `${count}次浏览`;
} else if (count < 10000) {
return `${(count / 1000).toFixed(1)}k次浏览`;
} else {
return `${(count / 10000).toFixed(1)}w次浏览`;
}
}
// 点击卡片
function handleClick() {
if (props.resource?.resourceID) {
router.push(`/article/show?articleId=${props.resource.resourceID}`);
}
}
2025-10-27 19:05:56 +08:00
</script>
<style lang="scss" scoped>
.article-card {
background: #FFFFFF;
border-radius: 0.625em;
overflow: hidden;
box-shadow: 0px 0.5em 1.25em 0px rgba(164, 182, 199, 0.2);
transition: all 0.3s;
cursor: pointer;
display: flex;
flex-direction: column;
&:hover {
transform: translateY(-0.25em);
box-shadow: 0px 0.75em 1.75em 0px rgba(164, 182, 199, 0.3);
}
.article-image {
width: 100%;
aspect-ratio: 384 / 221;
position: relative;
overflow: hidden;
flex-shrink: 0;
2025-10-31 19:13:21 +08:00
img {
width: 100%;
height: 100%;
object-fit: cover;
}
2025-10-27 19:05:56 +08:00
.image-placeholder {
width: 100%;
height: 100%;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
position: relative;
&::after {
content: '';
position: absolute;
width: 100%;
height: 100%;
background: url('data:image/svg+xml,<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg"><defs><pattern id="grid" width="40" height="40" patternUnits="userSpaceOnUse"><path d="M 40 0 L 0 0 0 40" fill="none" stroke="rgba(255,255,255,0.1)" stroke-width="1"/></pattern></defs><rect width="100%" height="100%" fill="url(%23grid)" /></svg>');
}
}
.article-tag {
position: absolute;
top: 0;
left: 0;
background: #D1AD79;
border-radius: 0px 0px 0.625em 0px;
padding: 0.2em 1.6em;
min-width: 5.4em;
min-height: 2.1em;
display: flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
font-family: 'PingFang SC';
font-weight: 600;
font-size: 0.875em;
line-height: 1.57;
color: #FFFFFF;
}
}
.article-content {
padding: 5.2% 5.7% 5.7% 5.7%;
flex: 1;
display: flex;
flex-direction: column;
.article-title {
font-family: 'PingFang SC';
font-weight: 600;
font-size: 1.25em;
line-height: 1.4;
color: #141F38;
margin: 0 0 0.2em 0;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 1;
line-clamp: 1;
-webkit-box-orient: vertical;
}
.article-desc {
font-family: 'PingFang SC';
font-weight: 400;
font-size: 0.875em;
line-height: 1.57;
color: rgba(0, 0, 0, 0.3);
margin: 0;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 4;
line-clamp: 4;
-webkit-box-orient: vertical;
}
.article-footer {
margin-top: 1.25em;
display: flex;
justify-content: space-between;
align-items: center;
.meta-tag {
display: flex;
align-items: center;
gap: 0.25em;
.el-icon {
width: 1em;
height: 1em;
color: #FFFFFF;
}
span {
font-family: 'PingFang SC';
font-weight: 500;
font-size: 0.875em;
line-height: 1.57;
color: #C62828;
}
}
.view-count {
font-family: 'PingFang SC';
font-weight: 400;
font-size: 0.875em;
line-height: 1.57;
color: rgba(0, 0, 0, 0.3);
}
}
}
}
</style>