HomeNewsList.vue
2.66 KB
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
<template>
<!-- 新闻公告 -->
<div class="news-list">
<div
v-for="newsItem in newsList"
:key="newsItem.id"
class="news-item"
@click="readNewsItem(newsItem)"
>
<div class="news-item__left">
<div class="news-item__title">
<i :class="newsItem.icon ? newsItem.iocn : 'iconfont icon-read1'"></i>
<el-tooltip
class="item"
effect="dark"
:content="newsItem.title"
placement="top"
>
<span>{{ newsItem.title }}</span>
</el-tooltip>
</div>
<div v-if="newsItem.titleDescription" class="news-item__desc">
{{ newsItem.titleDescription }}
</div>
</div>
<div class="news-item__right">
{{ newsItem.drafter }}
{{ newsItem.createTime | dateTimeFormat }}
</div>
</div>
<home-news-read ref="newsRead" :news-id="newsId" />
</div>
</template>
<script>
import HomeNewsRead from './HomeNewsRead'
import { getNewsList } from '@/api/portal'
export default {
name: 'HomeNewsList',
components: {
HomeNewsRead,
},
filters: {
dateTimeFormat(val) {
const moment = require('moment')
return val ? moment(val).format('YYYY-MM-DD HH:mm') : ''
},
},
props: {
classifyId: {
type: String,
default: 'all',
},
},
data() {
return {
newsId: '',
newsList: [],
}
},
created() {
this.initData()
},
methods: {
initData() {
getNewsList(this.classifyId).then((data) => {
this.newsList = data ? data : []
})
},
readNewsItem(news) {
this.newsId = news.id
this.$refs.newsRead.showDialog()
},
},
}
</script>
<style lang="scss" scoped>
.news-list {
width: 100%;
cursor: pointer;
.news-item {
width: calc(100% - 20px);
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px;
border-radius: $base-border-radius;
.news-item__left {
width: 50%;
.news-item__title {
span {
color: $base-font-color;
font-size: $base-font-size-default;
}
}
.news-item__desc {
color: $base-color-grey;
font-size: $base-font-size-small;
margin-top: 10px;
}
}
.news-item__right {
color: $base-font-color;
font-size: $base-font-size-small;
}
&:hover {
background: #f5f7fa;
}
&:not(:last-child) {
border-bottom: 1px solid $base-border-color;
}
}
}
</style>