1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<template>
<div class="padding-box">
<div class="news-card">
<div v-for="item in props.content3" :key="item.id" class="news-item" @click="handleNewsClick(item)">
<div class="image-wrapper">
<img :src="getImageUrl(item.photo)" :alt="item.title" loading="lazy" />
</div>
<div class="content">
<h3 class="title">{{ item.title }}</h3>
<time class="subtitle">{{item.createTime}}</time>
</div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
interface NewsItem {
id: number | string
noticeTitle: string
remark: string
// 添加其他需要的属性
}
// Props 定义
interface Props {
content3: NewsItem[]
action?: string
}
const props = withDefaults(defineProps<Props>(), {
content3: () => [],
action: ''
})
// 事件
const emit = defineEmits<{
(e: 'itemClick', item: NewsItem): void
}>()
// 获取完整图片URL
const getImageUrl = (remark: string) => {
return 'http://118.107.9.143:8080/jeecg-boot/' + remark
}
// 处理新闻点击
const handleNewsClick = (item: NewsItem) => {
emit('itemClick', item)
}
</script>
<style lang="scss" scoped>
.news-card {
margin: 7.5px 0; // 15rpx / 2
padding: 0;
border-radius: 5px; // 10rpx / 2
font-family: pingfang;
overflow: hidden;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.news-item {
display: flex;
padding: 15px;
gap: 15px;
cursor: pointer;
transition: background-color 0.3s ease;
&:hover {
background-color: rgba(0, 0, 0, 0.02);
}
&:active {
background-color: rgba(0, 0, 0, 0.05);
}
&:not(:last-child) {
border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}
}
.image-wrapper {
flex-shrink: 0;
width: 80px;
height: 80px;
border-radius: 4px;
overflow: hidden;
img {
width: 100%;
height: 100%;
object-fit: cover;
transition: transform 0.3s ease;
&:hover {
transform: scale(1.05);
}
}
}
.content {
flex: 1;
min-width: 0; // 防止文本溢出
display: flex;
flex-direction: column;
justify-content: space-between;
}
.title {
margin: 0;
font-size: 16px;
font-weight: 500;
color: #333;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
line-height: 1.4;
}
.subtitle {
font-size: 14px;
color: #999;
margin-top: auto;
}
</style>