index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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='empty-box acea-row row-middle' v-if="articleList.length == 0 && (page != 1 || active== 0)">
  41. <view class='pictrue'>
  42. <image src='../../static/images/empty-box.png'></image>
  43. <view class="txt">暂无新闻信息~</view>
  44. </view>
  45. </view>
  46. <home></home>
  47. </view>
  48. </template>
  49. <script>
  50. // +----------------------------------------------------------------------
  51. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  52. // +----------------------------------------------------------------------
  53. // | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
  54. // +----------------------------------------------------------------------
  55. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  56. // +----------------------------------------------------------------------
  57. // | Author: CRMEB Team <admin@crmeb.com>
  58. // +----------------------------------------------------------------------
  59. import {
  60. getArticleCategoryList,
  61. getArticleList,
  62. getArticleHotList,
  63. getArticleBannerList
  64. } from '@/api/api.js';
  65. import home from '@/components/home';
  66. export default {
  67. components: {
  68. home
  69. },
  70. data() {
  71. return {
  72. imgUrls: [],
  73. articleList: [],
  74. indicatorDots: false,
  75. circular: true,
  76. autoplay: true,
  77. interval: 3000,
  78. duration: 500,
  79. navList: [],
  80. active: 0,
  81. page: 1,
  82. limit: 8,
  83. status: false,
  84. scrollLeft: 0
  85. };
  86. },
  87. /**
  88. * 生命周期函数--监听页面显示
  89. */
  90. onShow: function() {
  91. // this.getArticleHot();
  92. // this.getArticleBanner();
  93. // this.getArticleCate();
  94. // this.status = false;
  95. // this.page = 1;
  96. // this.articleList = [];
  97. },
  98. /**
  99. * 生命周期函数--监听页面显示
  100. */
  101. onLoad: function() {
  102. // this.getArticleHot();
  103. // this.getArticleBanner();
  104. this.getArticleCate();
  105. this.status = false;
  106. this.page = 1;
  107. this.articleList = [];
  108. },
  109. /**
  110. * 页面上拉触底事件的处理函数
  111. */
  112. onReachBottom: function() {
  113. this.getCidArticle();
  114. },
  115. methods: {
  116. getArticleHot: function() {
  117. let that = this;
  118. getArticleHotList().then(res => {
  119. that.$set(that, 'articleList', res.data);
  120. });
  121. },
  122. getArticleBanner: function() {
  123. let that = this;
  124. getArticleBannerList().then(res => {
  125. that.imgUrls = res.data;
  126. });
  127. },
  128. getCidArticle: function() {
  129. let that = this;
  130. if (that.active == 0) return;
  131. let limit = that.limit;
  132. let page = that.page;
  133. let articleList = that.articleList;
  134. if (that.status) return;
  135. getArticleList(that.active, {
  136. page: page,
  137. limit: limit
  138. }).then(res => {
  139. let articleListNew = [];
  140. let len = res.length;
  141. articleListNew = articleList.concat(res.data.list);
  142. that.page++;
  143. that.$set(that, 'articleList', articleListNew);
  144. that.status = limit > len;
  145. that.page = that.page;
  146. });
  147. },
  148. getArticleCate: function() {
  149. let that = this;
  150. getArticleCategoryList().then(res => {
  151. this.active = res.data[0].article_category_id
  152. that.$set(that, 'navList', res.data);
  153. this.getCidArticle();
  154. });
  155. },
  156. tabSelect(active) {
  157. this.active = active;
  158. // this.scrollLeft = (active - 1) * 50;
  159. if (this.active == 0) this.getArticleHot();
  160. else {
  161. this.$set(this, 'articleList', []);
  162. this.page = 1;
  163. this.status = false;
  164. this.getCidArticle();
  165. }
  166. }
  167. }
  168. }
  169. </script>
  170. <style lang="scss">
  171. page {
  172. background-color: #fff !important;
  173. }
  174. .newsList .swiper {
  175. width: 100%;
  176. position: relative;
  177. box-sizing: border-box;
  178. padding: 0 30rpx;
  179. }
  180. .newsList .swiper swiper {
  181. width: 100%;
  182. height: 365rpx;
  183. position: relative;
  184. }
  185. .newsList .swiper .slide-image {
  186. width: 100%;
  187. height: 335rpx;
  188. border-radius: 6rpx;
  189. }
  190. // #ifdef MP-WEIXIN
  191. .newsList .swiper .wx-swiper-dot {
  192. width: 12rpx !important;
  193. height: 12rpx !important;
  194. border-radius: 0;
  195. transform: rotate(-45deg);
  196. transform-origin: 0 100%;
  197. }
  198. .newsList .swiper .wx-swiper-dot~.wx-swiper-dot {
  199. margin-left: 5rpx;
  200. }
  201. .newsList .swiper .wx-swiper-dots.wx-swiper-dots-horizontal {
  202. margin-bottom: -15rpx;
  203. }
  204. // #endif
  205. // #ifdef APP-PLUS || H5
  206. .newsList .swiper .uni-swiper-dot {
  207. width: 12rpx !important;
  208. height: 12rpx !important;
  209. border-radius: 0;
  210. transform: rotate(-45deg);
  211. transform-origin: 0 100%;
  212. }
  213. .newsList .swiper .uni-swiper-dot~.uni-swiper-dot {
  214. margin-left: 5rpx;
  215. }
  216. .newsList .swiper .uni-swiper-dots.uni-swiper-dots-horizontal {
  217. margin-bottom: -15rpx;
  218. }
  219. // #endif
  220. .newsList .nav {
  221. padding: 0 30rpx;
  222. width: 100%;
  223. white-space: nowrap;
  224. box-sizing: border-box;
  225. margin-top: 43rpx;
  226. }
  227. .newsList .nav .item {
  228. display: inline-block;
  229. font-size: 32rpx;
  230. color: #999;
  231. min-width: 130rpx;
  232. white-space: nowrap;
  233. overflow: hidden;
  234. text-overflow: ellipsis;
  235. position: relative;
  236. padding-bottom: 20rpx;
  237. }
  238. .newsList .nav .item.on {
  239. color: #282828;
  240. }
  241. .newsList .nav .item~.item {
  242. margin-left: 46rpx;
  243. }
  244. .newsList .nav .item .line {
  245. width: 24rpx;
  246. height: 4rpx;
  247. border-radius: 2rpx;
  248. margin: 10rpx auto 0 auto;
  249. position: absolute;
  250. bottom: 5rpx;
  251. left: 50%;
  252. margin-left: -12rpx;
  253. }
  254. .newsList .list .item {
  255. margin: 0 30rpx;
  256. border-bottom: 1px solid #f0f0f0;
  257. padding: 35rpx 0;
  258. }
  259. .newsList .list .item .pictrue {
  260. width: 250rpx;
  261. height: 156rpx;
  262. }
  263. .newsList .list .item .pictrue image {
  264. width: 100%;
  265. height: 100%;
  266. border-radius: 6rpx;
  267. }
  268. .newsList .list .item .text {
  269. width: 420rpx;
  270. height: 156rpx;
  271. font-size: 24rpx;
  272. color: #999;
  273. }
  274. .newsList .list .item .text .name {
  275. font-size: 30rpx;
  276. color: #282828;
  277. }
  278. .newsList .list .item .picList .pictrue {
  279. width: 335rpx;
  280. height: 210rpx;
  281. margin-top: 30rpx;
  282. }
  283. .newsList .list .item .picList.on .pictrue {
  284. width: 217rpx;
  285. height: 136rpx;
  286. }
  287. .newsList .list .item .picList .pictrue image {
  288. width: 100%;
  289. height: 100%;
  290. border-radius: 6rpx;
  291. }
  292. .newsList .list .item .time {
  293. text-align: right;
  294. font-size: 24rpx;
  295. color: #999;
  296. margin-top: 22rpx;
  297. }
  298. .noCommodity{
  299. border: none;
  300. }
  301. .empty-box{
  302. display: flex;
  303. flex-direction: column;
  304. justify-content: center;
  305. align-items: center;
  306. margin-top: 200rpx;
  307. image{
  308. width: 414rpx;
  309. height: 240rpx;
  310. }
  311. .txt{
  312. font-size: 26rpx;
  313. color: #999;
  314. text-align: center;
  315. }
  316. }
  317. </style>