index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <template>
  2. <view>
  3. <view class='newsList'>
  4. <!-- Banner 文章 -->
  5. <view class='swiper' v-if="imgUrls.length > 0">
  6. <swiper indicator-dots="true" :autoplay="autoplay" :circular="circular" :interval="interval" :duration="duration"
  7. indicator-color="rgba(102,102,102,0.3)" indicator-active-color="#666">
  8. <block v-for="(item,index) in imgUrls" :key="index">
  9. <swiper-item>
  10. <navigator :url="'/pages/news_details/index?id='+item.id">
  11. <image :src="item.picUrl" class="slide-image" />
  12. </navigator>
  13. </swiper-item>
  14. </block>
  15. </swiper>
  16. </view>
  17. <!-- 文章分类 -->
  18. <view class='nav' v-if="navList.length > 0">
  19. <scroll-view class="scroll-view_x" scroll-x scroll-with-animation :scroll-left="scrollLeft" style="width:auto;overflow:hidden;">
  20. <block v-for="(item,index) in navList" :key="index">
  21. <view class='item borRadius14' :class='active === item.id?"on":""' @click='tabSelect(item.id, index)'>
  22. <view>{{item.name}}</view>
  23. <view class='line bg-color' v-if="active === item.id"></view>
  24. </view>
  25. </block>
  26. </scroll-view>
  27. </view>
  28. <!-- 文章分类 -->
  29. <view class='list'>
  30. <block v-for="(item,index) in articleList" :key="index">
  31. <navigator :url='"/pages/news_details/index?id="+item.id' hover-class='none' class='item acea-row row-between-wrapper'>
  32. <view class='text acea-row row-column-between'>
  33. <view class='name line2'>{{item.title}}</view>
  34. <view>{{ formatDate(item.createTime) }}</view>
  35. </view>
  36. <view class='pictrue'>
  37. <image :src='item.picUrl'></image>
  38. </view>
  39. </navigator>
  40. </block>
  41. </view>
  42. </view>
  43. <view class='noCommodity' v-if="articleList.length === 0 && (page !== 1 || active === 0)">
  44. <view class='pictrue'>
  45. <image src='../../static/images/noNews.png' />
  46. </view>
  47. </view>
  48. <home></home>
  49. </view>
  50. </template>
  51. <script>
  52. import * as ArticleApi from '@/api/promotion/article.js';
  53. import dayjs from "@/plugin/dayjs/dayjs.min.js";
  54. import home from '@/components/home';
  55. export default {
  56. components: {
  57. home
  58. },
  59. data() {
  60. return {
  61. navList: [], // 文章分类
  62. active: 0, // 选中的分类编号,0 为热门
  63. imgUrls: [], // Banner 文章
  64. circular: true,
  65. autoplay: true,
  66. interval: 3000,
  67. duration: 500,
  68. articleList: [], // 普通文章
  69. page: 1,
  70. limit: 8,
  71. status: false,
  72. scrollLeft: 0
  73. };
  74. },
  75. /**
  76. * 生命周期函数--监听页面显示
  77. */
  78. onShow: function() {
  79. this.getArticleHot();
  80. this.getArticleBanner();
  81. this.getArticleCate();
  82. this.status = false;
  83. this.page = 1;
  84. this.articleList = [];
  85. this.getCidArticle();
  86. },
  87. /**
  88. * 页面上拉触底事件的处理函数
  89. */
  90. onReachBottom: function () {
  91. this.getCidArticle();
  92. },
  93. methods: {
  94. /**
  95. * 获得分类
  96. */
  97. getArticleCate: function() {
  98. ArticleApi.getArticleCategoryList().then(res => {
  99. let list = res.data;
  100. list.unshift({
  101. id: 0,
  102. name: '热门'
  103. });
  104. this.$set(this, 'navList', list);
  105. });
  106. },
  107. /**
  108. * 获得热门文章
  109. */
  110. getArticleHot: function() {
  111. ArticleApi.getArticleList({
  112. recommendHot: true
  113. }).then(res => {
  114. this.$set(this, 'articleList', res.data);
  115. });
  116. },
  117. /**
  118. * 获得 Banner 文章
  119. */
  120. getArticleBanner: function() {
  121. ArticleApi.getArticleList({
  122. recommendBanner: true
  123. }).then(res => {
  124. this.imgUrls = res.data;
  125. });
  126. },
  127. /**
  128. * 获得指定分类的文章列表
  129. */
  130. getCidArticle: function() {
  131. if (this.active === 0) {
  132. return;
  133. }
  134. if (this.status) {
  135. return;
  136. }
  137. ArticleApi.getArticlePage({
  138. categoryId: this.active,
  139. pageNo: this.page,
  140. pageSize: this.limit
  141. }).then(res => {
  142. let articleListNew = this.articleList.concat(res.data.list);
  143. this.page++;
  144. this.$set(this, 'articleList', articleListNew);
  145. this.status = this.limit > res.data.list.length;
  146. });
  147. },
  148. /**
  149. * 分类切换,重新加载文章列表
  150. */
  151. tabSelect(active, e) {
  152. this.active = active;
  153. this.scrollLeft = e * 60;
  154. if (this.active === 0) {
  155. this.getArticleHot();
  156. } else {
  157. this.$set(this, 'articleList', []);
  158. this.page = 1;
  159. this.status = false;
  160. this.getCidArticle();
  161. }
  162. },
  163. formatDate: function(date) {
  164. return dayjs(date).format("YYYY-MM-DD");
  165. }
  166. }
  167. }
  168. </script>
  169. <style lang="scss">
  170. page {
  171. background-color: #fff !important;
  172. }
  173. .newsList .swiper {
  174. width: 100%;
  175. position: relative;
  176. box-sizing: border-box;
  177. padding: 0 30rpx;
  178. }
  179. .newsList .swiper swiper {
  180. width: 100%;
  181. height: 365rpx;
  182. position: relative;
  183. }
  184. .newsList .swiper .slide-image {
  185. width: 100%;
  186. height: 335rpx;
  187. border-radius: 14rpx;
  188. }
  189. // #ifdef MP-WEIXIN
  190. .newsList .swiper .wx-swiper-dot {
  191. width: 12rpx !important;
  192. height: 12rpx !important;
  193. border-radius: 0;
  194. transform: rotate(-45deg);
  195. transform-origin: 0 100%;
  196. }
  197. .newsList .swiper .wx-swiper-dot~.wx-swiper-dot {
  198. margin-left: 5rpx;
  199. }
  200. .newsList .swiper .wx-swiper-dots.wx-swiper-dots-horizontal {
  201. margin-bottom: -15rpx;
  202. }
  203. // #endif
  204. .newsList .swiper .uni-swiper-dot {
  205. width: 12rpx !important;
  206. height: 12rpx !important;
  207. border-radius: 0;
  208. transform: rotate(-45deg);
  209. transform-origin: 0 100%;
  210. }
  211. .newsList .swiper .uni-swiper-dot~.uni-swiper-dot {
  212. margin-left: 5rpx;
  213. }
  214. .newsList .swiper .uni-swiper-dots.uni-swiper-dots-horizontal {
  215. margin-bottom: -15rpx;
  216. }
  217. .newsList .nav {
  218. padding: 0 24rpx;
  219. width: 100%;
  220. white-space: nowrap;
  221. box-sizing: border-box;
  222. margin-top: 43rpx;
  223. }
  224. .newsList .nav .item {
  225. display: inline-block;
  226. font-size: 32rpx;
  227. color: #999;
  228. }
  229. .newsList .nav .item.on {
  230. color: #282828;
  231. }
  232. .newsList .nav .item~.item {
  233. margin-left: 46rpx;
  234. }
  235. .newsList .nav .item .line {
  236. width: 24rpx;
  237. height: 4rpx;
  238. border-radius: 2rpx;
  239. margin: 10rpx auto 0 auto;
  240. }
  241. .newsList .list .item {
  242. margin: 0 24rpx;
  243. border-bottom: 1rpx solid #f0f0f0;
  244. padding: 35rpx 0;
  245. }
  246. .newsList .list .item .pictrue {
  247. width: 250rpx;
  248. height: 156rpx;
  249. }
  250. .newsList .list .item .pictrue image {
  251. width: 100%;
  252. height: 100%;
  253. border-radius: 14rpx;
  254. }
  255. .newsList .list .item .text {
  256. width: 420rpx;
  257. height: 156rpx;
  258. font-size: 24rpx;
  259. color: #999;
  260. }
  261. .newsList .list .item .text .name {
  262. font-size: 30rpx;
  263. color: #282828;
  264. }
  265. .newsList .list .item .picList .pictrue {
  266. width: 335rpx;
  267. height: 210rpx;
  268. margin-top: 30rpx;
  269. }
  270. .newsList .list .item .picList.on .pictrue {
  271. width: 217rpx;
  272. height: 136rpx;
  273. }
  274. .newsList .list .item .picList .pictrue image {
  275. width: 100%;
  276. height: 100%;
  277. border-radius: 6rpx;
  278. }
  279. .newsList .list .item .time {
  280. text-align: right;
  281. font-size: 24rpx;
  282. color: #999;
  283. margin-top: 22rpx;
  284. }
  285. </style>