| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- <template>
- <div>
- <el-row class="movie-list">
- <el-col :md="12">
- <el-row v-for="(item, index) in dataList" :key="index" class="movie-list">
- <el-card class="box-card">
- <div slot="header" class="clearfix">
- <span style="left: 0;margin-bottom: 0px;color: black;">{{ item.publishAt }}</span>
- </div>
- <div class="text item">
- <el-row>
- <el-col :md="4">
- <router-link target="_blank" :to="`/news/${item.contentId}`">
- <el-image
- lazy
- fit="cover"
- :src="item.coverUrl"
- class="coverImg"
- />
- </router-link>
- </el-col>
- <el-col :md="20">
- <router-link style="text-decoration-line: none" target="_blank" :to="`/news/${item.contentId}`">
- <el-row>
- <div style="padding: 14px">
- <span style="left: 0;margin-bottom: 0px;color: black;">{{ item.title | ellipsis }}</span>
- </div>
- </el-row>
- </router-link>
- <el-row>
- <div style="padding: 14px">
- <span style="left: 0;margin-bottom: 0px;color: black;">{{ item.excerpt }}</span>
- </div>
- </el-row>
- </el-col>
- </el-row>
- </div>
- </el-card>
- </el-row>
- <el-row>
- <div v-if="hasMore" style="display: flex; justify-content: center;">
- <el-button link type="plain" icon="el-icon-bottom" @click="loadMore">
- 加载更多
- </el-button>
- </div>
- </el-row>
- </el-col>
- <el-col :md="6">
- <el-row class="movie-list">
- <el-card class="box-card">
- <div slot="header" class="clearfix">
- <el-row>
- <span>热门</span>
- </el-row>
- </div>
- <div class="text item">
- <el-row />
- </div>
- </el-card>
- </el-row>
- </el-col>
- </el-row>
- </div>
- </template>
- <script>
- import { getNewsList } from '@/api/blog'
- export default {
- name: 'ArticleIndex',
- metaInfo: {
- meta: [
- { name: 'referrer', content: 'no-referrer' }
- ]
- },
- filters: {
- ellipsis(value) {
- if (!value) return ''
- const max = 50
- if (value.length > max) {
- return value.slice(0, max) + '...'
- }
- return value
- }
- },
- components: {},
- data() {
- return {
- // 屏幕宽度, 为了控制分页条的大小
- screenWidth: document.body.clientWidth,
- currentPage: 1,
- pageSize: 12,
- totalSize: 0,
- dataList: [],
- hasMore: true
- }
- },
- created() {
- document.title = 'News'
- this.getArticlesWrapper(this.currentPage)
- },
- mounted() {
- // 当窗口宽度改变时获取屏幕宽度
- window.onresize = () => {
- return () => {
- window.screenWidth = document.body.clientWidth
- this.screenWidth = window.screenWidth
- }
- }
- },
- methods: {
- handleCurrentChange(currentPage) {
- this.currentPage = currentPage
- this.getArticlesWrapper(this.currentPage)
- // 回到顶部
- scrollTo(0, 0)
- },
- getArticlesWrapper(page) {
- getNewsList(page).then(resp => {
- if (resp.code === 0) {
- const respData = resp.data
- this.hasMore = respData.hasNext
- for (const item of respData.list) {
- this.dataList.push(item)
- }
- }
- })
- },
- loadMore() {
- this.currentPage = this.currentPage + 1
- this.getArticlesWrapper(this.currentPage)
- },
- refresh() {
- this.$message.info('暂未实现')
- }
- }
- }
- </script>
- <style scoped>
- /*处于手机屏幕时*/
- @media screen and (max-width: 768px) {
- .movie-list {
- padding: 5px;
- }
- .coverImg {
- height: 120px !important;
- }
- }
- .movie-list {
- padding: 5px;
- }
- .coverImg {
- width: 100%;
- height: 120px;
- display: block;
- }
- .clearfix:before,
- .clearfix:after {
- display: table;
- content: "";
- }
- .clearfix:after {
- clear: both;
- }
- .not-result {
- padding-top: 100px;
- padding-bottom: 100px;
- text-align: center;
- }
- </style>
|