index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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.image_input[0]" 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' :class='active==item.article_category_id?"on":""' @click='tabSelect(item.article_category_id)'>
  20. <view>{{item.title}}</view>
  21. <view class='line bg-color' v-if="active==item.article_category_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.article_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.create_time}}</view>
  32. </view>
  33. <view class='pictrue'>
  34. <image :src='item.image_input'></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. },
  88. /**
  89. * 页面上拉触底事件的处理函数
  90. */
  91. onReachBottom: function() {
  92. this.getCidArticle();
  93. },
  94. methods: {
  95. getArticleHot: function() {
  96. let that = this;
  97. getArticleHotList().then(res => {
  98. that.$set(that, 'articleList', res.data);
  99. });
  100. },
  101. getArticleBanner: function() {
  102. let that = this;
  103. getArticleBannerList().then(res => {
  104. that.imgUrls = res.data;
  105. });
  106. },
  107. getCidArticle: function() {
  108. let that = this;
  109. if (that.active == 0) return;
  110. let limit = that.limit;
  111. let page = that.page;
  112. let articleList = that.articleList;
  113. if (that.status) return;
  114. getArticleList(that.active, {
  115. page: page,
  116. limit: limit
  117. }).then(res => {
  118. let articleListNew = [];
  119. let len = res.length;
  120. articleListNew = articleList.concat(res.data.list);
  121. that.page++;
  122. that.$set(that, 'articleList', articleListNew);
  123. that.status = limit > len;
  124. that.page = that.page;
  125. });
  126. },
  127. getArticleCate: function() {
  128. let that = this;
  129. getArticleCategoryList().then(res => {
  130. this.active = res.data[0].article_category_id
  131. that.$set(that, 'navList', res.data);
  132. this.getCidArticle();
  133. });
  134. },
  135. tabSelect(active) {
  136. this.active = active;
  137. // this.scrollLeft = (active - 1) * 50;
  138. if (this.active == 0) this.getArticleHot();
  139. else {
  140. this.$set(this, 'articleList', []);
  141. this.page = 1;
  142. this.status = false;
  143. this.getCidArticle();
  144. }
  145. }
  146. }
  147. }
  148. </script>
  149. <style lang="scss">
  150. page {
  151. background-color: #fff !important;
  152. }
  153. .newsList .swiper {
  154. width: 100%;
  155. position: relative;
  156. box-sizing: border-box;
  157. padding: 0 30rpx;
  158. }
  159. .newsList .swiper swiper {
  160. width: 100%;
  161. height: 365rpx;
  162. position: relative;
  163. }
  164. .newsList .swiper .slide-image {
  165. width: 100%;
  166. height: 335rpx;
  167. border-radius: 6rpx;
  168. }
  169. // #ifdef MP-WEIXIN
  170. .newsList .swiper .wx-swiper-dot {
  171. width: 12rpx !important;
  172. height: 12rpx !important;
  173. border-radius: 0;
  174. transform: rotate(-45deg);
  175. transform-origin: 0 100%;
  176. }
  177. .newsList .swiper .wx-swiper-dot~.wx-swiper-dot {
  178. margin-left: 5rpx;
  179. }
  180. .newsList .swiper .wx-swiper-dots.wx-swiper-dots-horizontal {
  181. margin-bottom: -15rpx;
  182. }
  183. // #endif
  184. // #ifdef APP-PLUS || H5
  185. .newsList .swiper .uni-swiper-dot {
  186. width: 12rpx !important;
  187. height: 12rpx !important;
  188. border-radius: 0;
  189. transform: rotate(-45deg);
  190. transform-origin: 0 100%;
  191. }
  192. .newsList .swiper .uni-swiper-dot~.uni-swiper-dot {
  193. margin-left: 5rpx;
  194. }
  195. .newsList .swiper .uni-swiper-dots.uni-swiper-dots-horizontal {
  196. margin-bottom: -15rpx;
  197. }
  198. // #endif
  199. .newsList .nav {
  200. padding: 0 30rpx;
  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. min-width: 130rpx;
  211. white-space: nowrap;
  212. overflow: hidden;
  213. text-overflow: ellipsis;
  214. position: relative;
  215. padding-bottom: 20rpx;
  216. }
  217. .newsList .nav .item.on {
  218. color: #282828;
  219. }
  220. .newsList .nav .item~.item {
  221. margin-left: 46rpx;
  222. }
  223. .newsList .nav .item .line {
  224. width: 24rpx;
  225. height: 4rpx;
  226. border-radius: 2rpx;
  227. margin: 10rpx auto 0 auto;
  228. position: absolute;
  229. bottom: 5rpx;
  230. left: 50%;
  231. margin-left: -12rpx;
  232. }
  233. .newsList .list .item {
  234. margin: 0 30rpx;
  235. border-bottom: 1rpx solid #f0f0f0;
  236. padding: 35rpx 0;
  237. }
  238. .newsList .list .item .pictrue {
  239. width: 250rpx;
  240. height: 156rpx;
  241. }
  242. .newsList .list .item .pictrue image {
  243. width: 100%;
  244. height: 100%;
  245. border-radius: 6rpx;
  246. }
  247. .newsList .list .item .text {
  248. width: 420rpx;
  249. height: 156rpx;
  250. font-size: 24rpx;
  251. color: #999;
  252. }
  253. .newsList .list .item .text .name {
  254. font-size: 30rpx;
  255. color: #282828;
  256. }
  257. .newsList .list .item .picList .pictrue {
  258. width: 335rpx;
  259. height: 210rpx;
  260. margin-top: 30rpx;
  261. }
  262. .newsList .list .item .picList.on .pictrue {
  263. width: 217rpx;
  264. height: 136rpx;
  265. }
  266. .newsList .list .item .picList .pictrue image {
  267. width: 100%;
  268. height: 100%;
  269. border-radius: 6rpx;
  270. }
  271. .newsList .list .item .time {
  272. text-align: right;
  273. font-size: 24rpx;
  274. color: #999;
  275. margin-top: 22rpx;
  276. }
  277. </style>