mall-uniapp/pages/news_list/index.vue

311 lines
6.9 KiB
Vue
Raw Normal View History

2020-08-13 08:12:57 +00:00
<template>
<view>
<view class='newsList'>
2023-06-26 15:47:06 +00:00
<!-- Banner 文章 -->
2020-08-13 08:12:57 +00:00
<view class='swiper' v-if="imgUrls.length > 0">
<swiper indicator-dots="true" :autoplay="autoplay" :circular="circular" :interval="interval" :duration="duration"
indicator-color="rgba(102,102,102,0.3)" indicator-active-color="#666">
<block v-for="(item,index) in imgUrls" :key="index">
<swiper-item>
<navigator :url="'/pages/news_details/index?id='+item.id">
2023-06-26 15:47:06 +00:00
<image :src="item.picUrl" class="slide-image" />
2020-08-13 08:12:57 +00:00
</navigator>
</swiper-item>
</block>
</swiper>
</view>
2023-06-26 15:47:06 +00:00
<!-- 文章分类 -->
<view class='nav' v-if="navList.length > 0">
2020-08-13 08:12:57 +00:00
<scroll-view class="scroll-view_x" scroll-x scroll-with-animation :scroll-left="scrollLeft" style="width:auto;overflow:hidden;">
<block v-for="(item,index) in navList" :key="index">
2023-06-26 15:47:06 +00:00
<view class='item borRadius14' :class='active === item.id?"on":""' @click='tabSelect(item.id, index)'>
2020-08-13 08:12:57 +00:00
<view>{{item.name}}</view>
2023-06-26 15:47:06 +00:00
<view class='line bg-color' v-if="active === item.id"></view>
2020-08-13 08:12:57 +00:00
</view>
</block>
</scroll-view>
</view>
2023-06-26 15:47:06 +00:00
<!-- 文章分类 -->
<view class='list'>
2020-08-13 08:12:57 +00:00
<block v-for="(item,index) in articleList" :key="index">
<navigator :url='"/pages/news_details/index?id="+item.id' hover-class='none' class='item acea-row row-between-wrapper'>
2020-08-13 08:12:57 +00:00
<view class='text acea-row row-column-between'>
<view class='name line2'>{{item.title}}</view>
2023-06-26 15:47:06 +00:00
<view>{{ formatDate(item.createTime) }}</view>
2020-08-13 08:12:57 +00:00
</view>
<view class='pictrue'>
2023-06-26 15:47:06 +00:00
<image :src='item.picUrl'></image>
2020-08-13 08:12:57 +00:00
</view>
</navigator>
</block>
</view>
</view>
2023-06-26 15:47:06 +00:00
<view class='noCommodity' v-if="articleList.length === 0 && (page !== 1 || active === 0)">
2020-08-13 08:12:57 +00:00
<view class='pictrue'>
2023-06-26 15:47:06 +00:00
<image src='../../static/images/noNews.png' />
2020-08-13 08:12:57 +00:00
</view>
</view>
<home></home>
</view>
</template>
<script>
2023-06-26 15:47:06 +00:00
import * as ArticleApi from '@/api/promotion/article.js';
import dayjs from "@/plugin/dayjs/dayjs.min.js";
import home from '@/components/home';
2020-08-13 08:12:57 +00:00
export default {
components: {
home
},
data() {
return {
2023-06-26 15:47:06 +00:00
navList: [], // 文章分类
active: 0, // 选中的分类编号0 为热门
imgUrls: [], // Banner 文章
2020-08-13 08:12:57 +00:00
circular: true,
autoplay: true,
interval: 3000,
duration: 500,
2023-06-26 15:47:06 +00:00
articleList: [], // 普通文章
page: 1,
2020-08-13 08:12:57 +00:00
limit: 8,
status: false,
scrollLeft: 0
};
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
this.getArticleHot();
this.getArticleBanner();
this.getArticleCate();
this.status = false;
this.page = 1;
this.articleList = [];
this.getCidArticle();
},
2023-06-26 15:47:06 +00:00
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
this.getCidArticle();
},
2020-08-13 08:12:57 +00:00
methods: {
2023-06-26 15:47:06 +00:00
/**
* 获得分类
*/
getArticleCate: function() {
ArticleApi.getArticleCategoryList().then(res => {
let list = res.data;
list.unshift({
id: 0,
name: '热门'
});
this.$set(this, 'navList', list);
});
},
/**
* 获得热门文章
*/
2020-08-13 08:12:57 +00:00
getArticleHot: function() {
2023-06-26 15:47:06 +00:00
ArticleApi.getArticleList({
recommendHot: true
}).then(res => {
this.$set(this, 'articleList', res.data);
2020-08-13 08:12:57 +00:00
});
},
2023-06-26 15:47:06 +00:00
/**
* 获得 Banner 文章
*/
2020-08-13 08:12:57 +00:00
getArticleBanner: function() {
2023-06-26 15:47:06 +00:00
ArticleApi.getArticleList({
recommendBanner: true
}).then(res => {
this.imgUrls = res.data;
2020-08-13 08:12:57 +00:00
});
},
2023-06-26 15:47:06 +00:00
/**
* 获得指定分类的文章列表
*/
2020-08-13 08:12:57 +00:00
getCidArticle: function() {
2023-06-26 15:47:06 +00:00
if (this.active === 0) {
return;
}
if (this.status) {
return;
}
ArticleApi.getArticlePage({
categoryId: this.active,
pageNo: this.page,
pageSize: this.limit
2020-08-13 08:12:57 +00:00
}).then(res => {
2023-06-26 15:47:06 +00:00
let articleListNew = this.articleList.concat(res.data.list);
this.page++;
this.$set(this, 'articleList', articleListNew);
this.status = this.limit > res.data.list.length;
2020-08-13 08:12:57 +00:00
});
},
2023-06-26 15:47:06 +00:00
/**
* 分类切换重新加载文章列表
*/
tabSelect(active, e) {
2020-08-13 08:12:57 +00:00
this.active = active;
this.scrollLeft = e * 60;
2023-06-26 15:47:06 +00:00
if (this.active === 0) {
this.getArticleHot();
} else {
2020-08-13 08:12:57 +00:00
this.$set(this, 'articleList', []);
this.page = 1;
this.status = false;
this.getCidArticle();
}
2023-06-26 15:47:06 +00:00
},
formatDate: function(date) {
return dayjs(date).format("YYYY-MM-DD");
}
2020-08-13 08:12:57 +00:00
}
}
</script>
<style lang="scss">
page {
background-color: #fff !important;
}
.newsList .swiper {
width: 100%;
position: relative;
box-sizing: border-box;
padding: 0 30rpx;
}
.newsList .swiper swiper {
width: 100%;
height: 365rpx;
position: relative;
}
.newsList .swiper .slide-image {
width: 100%;
height: 335rpx;
border-radius: 14rpx;
2020-08-13 08:12:57 +00:00
}
// #ifdef MP-WEIXIN
.newsList .swiper .wx-swiper-dot {
width: 12rpx !important;
height: 12rpx !important;
border-radius: 0;
transform: rotate(-45deg);
transform-origin: 0 100%;
}
2023-06-26 15:47:06 +00:00
2020-08-13 08:12:57 +00:00
.newsList .swiper .wx-swiper-dot~.wx-swiper-dot {
margin-left: 5rpx;
}
.newsList .swiper .wx-swiper-dots.wx-swiper-dots-horizontal {
margin-bottom: -15rpx;
}
// #endif
.newsList .swiper .uni-swiper-dot {
width: 12rpx !important;
height: 12rpx !important;
border-radius: 0;
transform: rotate(-45deg);
transform-origin: 0 100%;
}
2023-06-26 15:47:06 +00:00
2020-08-13 08:12:57 +00:00
.newsList .swiper .uni-swiper-dot~.uni-swiper-dot {
margin-left: 5rpx;
}
2023-06-26 15:47:06 +00:00
2020-08-13 08:12:57 +00:00
.newsList .swiper .uni-swiper-dots.uni-swiper-dots-horizontal {
margin-bottom: -15rpx;
}
.newsList .nav {
padding: 0 24rpx;
2020-08-13 08:12:57 +00:00
width: 100%;
white-space: nowrap;
box-sizing: border-box;
margin-top: 43rpx;
}
.newsList .nav .item {
display: inline-block;
font-size: 32rpx;
color: #999;
}
.newsList .nav .item.on {
color: #282828;
}
.newsList .nav .item~.item {
margin-left: 46rpx;
}
.newsList .nav .item .line {
width: 24rpx;
height: 4rpx;
border-radius: 2rpx;
margin: 10rpx auto 0 auto;
}
.newsList .list .item {
margin: 0 24rpx;
2020-08-13 08:12:57 +00:00
border-bottom: 1rpx solid #f0f0f0;
padding: 35rpx 0;
}
.newsList .list .item .pictrue {
width: 250rpx;
height: 156rpx;
}
.newsList .list .item .pictrue image {
width: 100%;
height: 100%;
border-radius: 14rpx;
2020-08-13 08:12:57 +00:00
}
.newsList .list .item .text {
width: 420rpx;
height: 156rpx;
font-size: 24rpx;
color: #999;
}
.newsList .list .item .text .name {
font-size: 30rpx;
color: #282828;
}
.newsList .list .item .picList .pictrue {
width: 335rpx;
height: 210rpx;
margin-top: 30rpx;
}
.newsList .list .item .picList.on .pictrue {
width: 217rpx;
height: 136rpx;
}
.newsList .list .item .picList .pictrue image {
width: 100%;
height: 100%;
border-radius: 6rpx;
}
.newsList .list .item .time {
text-align: right;
font-size: 24rpx;
color: #999;
margin-top: 22rpx;
}
</style>