index.vue 6.4 KB

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