You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

343 lines
8.3 KiB

3 months ago
  1. <template>
  2. <view :data-theme="theme">
  3. <skeleton :show="showSkeleton" :isNodes="isNodes" ref="skeleton" loading="chiaroscuro" selector="skeleton"
  4. bgcolor="#FFF"></skeleton>
  5. <view class='newsList skeleton' :style="{visibility: showSkeleton ? 'hidden' : 'visible'}">
  6. <view class='swiper skeleton-rect' v-if="imgUrls.length > 0">
  7. <swiper indicator-dots="true" :autoplay="autoplay" :circular="circular" :interval="interval" :duration="duration"
  8. indicator-color="rgba(102,102,102,0.3)" indicator-active-color="#666">
  9. <block v-for="(item,index) in imgUrls" :key="index">
  10. <swiper-item>
  11. <navigator :url="'/pages/news/news_details/index?id='+item.id">
  12. <image :src="item.imageInput" class="slide-image" mode="aspectFill" />
  13. </navigator>
  14. </swiper-item>
  15. </block>
  16. </swiper>
  17. </view>
  18. <view class='nav'>
  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 skeleton-rect' :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. <view class='list'>
  29. <block v-for="(item,index) in articleList" :key="index">
  30. <view class='item acea-row row-between-wrapper' @click="toNewDetail(item.id)">
  31. <view class='text acea-row row-column-between'>
  32. <view class='name line2 skeleton-rect'>{{item.title}}</view>
  33. <view class="skeleton-rect">{{item.createTime}}</view>
  34. </view>
  35. <view class='pictrue skeleton-rect'>
  36. <image :src='item.imageInput'></image>
  37. </view>
  38. </view>
  39. </block>
  40. </view>
  41. </view>
  42. <view class='noCommodity' v-if="articleList.length == 0 && (page != 1 || active== 0) && isShow">
  43. <view class='pictrue'>
  44. <image :src="urlDomain+'crmebimage/perset/staticImg/noNews.png'"></image>
  45. </view>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. import {
  51. getArticleCategoryList,
  52. getArticleList,
  53. getArticleHotList,
  54. getArticleBannerList,
  55. } from '@/api/api.js';
  56. import animationType from '@/utils/animationType.js'
  57. let app = getApp();
  58. export default {
  59. data() {
  60. return {
  61. urlDomain: this.$Cache.get("imgHost"),
  62. showSkeleton: true, //骨架屏显示隐藏
  63. isNodes: 0, //控制什么时候开始抓取元素节点,只要数值改变就重新抓取
  64. imgUrls: [{imageInput:''}],
  65. articleList: [{imageInput:'',title: '占位占位',createTime:'占位'}],
  66. indicatorDots: false,
  67. circular: true,
  68. autoplay: true,
  69. interval: 3000,
  70. duration: 500,
  71. navList: [{id:0,name:'占位'},{id:0,name:'占位'},{id:0,name:'占位'}],
  72. active: 0,
  73. page: 1,
  74. limit: 8,
  75. status: false,
  76. scrollLeft: 0,
  77. isShow: false,
  78. theme:app.globalData.theme,
  79. };
  80. },
  81. onLoad(){
  82. setTimeout(() => {
  83. //this.couponsList = [{name:''}]
  84. this.isNodes++;
  85. // #ifdef H5
  86. this.setShare();
  87. // #endif
  88. }, 500);
  89. this.getArticleHot();
  90. this.getArticleBanner();
  91. this.getArticleCate();
  92. this.status = false;
  93. this.page = 1;
  94. //this.articleList = [];
  95. this.getCidArticle();
  96. },
  97. /**
  98. * 生命周期函数--监听页面显示
  99. */
  100. onShow: function() {
  101. // this.getArticleHot();
  102. // this.getArticleBanner();
  103. // this.getArticleCate();
  104. // this.status = false;
  105. // this.page = 1;
  106. // //this.articleList = [];
  107. // this.getCidArticle();
  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.list);
  120. });
  121. },
  122. getArticleBanner: function() {
  123. let that = this;
  124. getArticleBannerList().then(res => {
  125. that.imgUrls = res.data.list;
  126. setTimeout(() => {
  127. this.showSkeleton = false
  128. }, 1000)
  129. });
  130. },
  131. getCidArticle: function() {
  132. let that = this;
  133. if (that.active == 0) return;
  134. let limit = that.limit;
  135. let page = that.page;
  136. let articleList = that.articleList;
  137. if (that.status) return;
  138. getArticleList(that.active, {
  139. page: page,
  140. limit: limit
  141. }).then(res => {
  142. let articleListNew = [];
  143. let len = res.data.list.length;
  144. articleListNew = articleList.concat(res.data.list);
  145. that.page++;
  146. that.$set(that, 'articleList', articleListNew);
  147. that.status = limit > len;
  148. that.page = that.page;
  149. that.isShow = true;
  150. });
  151. },
  152. getArticleCate: function() {
  153. let that = this;
  154. getArticleCategoryList().then(res => {
  155. let list = res.data.list;
  156. list.unshift({id:0,name:'热门'});
  157. that.$set(that, 'navList', list);
  158. setTimeout(() => {
  159. this.showSkeleton = false
  160. }, 1000)
  161. });
  162. },
  163. tabSelect(active,e) {
  164. this.active = active;
  165. this.scrollLeft = e * 60;
  166. // this.scrollLeft = (active - 1) * 50;
  167. if (this.active == 0) this.getArticleHot();
  168. else {
  169. this.$set(this, 'articleList', []);
  170. this.page = 1;
  171. this.status = false;
  172. this.getCidArticle();
  173. }
  174. },
  175. // '"/pages/news_details/index?id="+item.id'
  176. toNewDetail(id){
  177. uni.navigateTo({
  178. animationType: animationType.type, animationDuration: animationType.duration,
  179. url:"/pages/news/news_details/index?id="+id
  180. })
  181. },
  182. setShare: function() {
  183. this.$wechat.isWeixin() &&
  184. this.$wechat.wechatEvevt([
  185. "updateAppMessageShareData",
  186. "updateTimelineShareData",
  187. "onMenuShareAppMessage",
  188. "onMenuShareTimeline"
  189. ], {
  190. desc: this.articleList[0].title,
  191. title: this.articleList[0].title,
  192. link: location.href,
  193. imgUrl:this.articleList[0].imageInput
  194. }).then(res => {
  195. }).catch(err => {
  196. console.log(err);
  197. });
  198. },
  199. }
  200. }
  201. </script>
  202. <style lang="scss">
  203. page {
  204. background-color: #fff !important;
  205. }
  206. .newsList .swiper {
  207. width: 100%;
  208. position: relative;
  209. box-sizing: border-box;
  210. padding: 0 30rpx;
  211. }
  212. .newsList .swiper swiper {
  213. width: 100%;
  214. height: 365rpx;
  215. position: relative;
  216. }
  217. .newsList .swiper .slide-image {
  218. width: 100%;
  219. height: 335rpx;
  220. border-radius: 14rpx;
  221. }
  222. // #ifdef MP-WEIXIN
  223. .newsList .swiper .wx-swiper-dot {
  224. width: 12rpx !important;
  225. height: 12rpx !important;
  226. border-radius: 0;
  227. transform: rotate(-45deg);
  228. transform-origin: 0 100%;
  229. }
  230. .newsList .swiper .wx-swiper-dot~.wx-swiper-dot {
  231. margin-left: 5rpx;
  232. }
  233. .newsList .swiper .wx-swiper-dots.wx-swiper-dots-horizontal {
  234. margin-bottom: -15rpx;
  235. }
  236. // #endif
  237. // #ifdef APP-PLUS || H5
  238. .newsList .swiper .uni-swiper-dot {
  239. width: 12rpx !important;
  240. height: 12rpx !important;
  241. border-radius: 0;
  242. transform: rotate(-45deg);
  243. transform-origin: 0 100%;
  244. }
  245. .newsList .swiper .uni-swiper-dot~.uni-swiper-dot {
  246. margin-left: 5rpx;
  247. }
  248. .newsList .swiper .uni-swiper-dots.uni-swiper-dots-horizontal {
  249. margin-bottom: -15rpx;
  250. }
  251. // #endif
  252. .newsList .nav {
  253. padding: 0 24rpx;
  254. width: 100%;
  255. white-space: nowrap;
  256. box-sizing: border-box;
  257. margin-top: 43rpx;
  258. }
  259. .newsList .nav .item {
  260. display: inline-block;
  261. font-size: 32rpx;
  262. color: #999;
  263. }
  264. .newsList .nav .item.on {
  265. color: #282828;
  266. }
  267. .newsList .nav .item~.item {
  268. margin-left: 46rpx;
  269. }
  270. .newsList .nav .item .line {
  271. width: 24rpx;
  272. height: 4rpx;
  273. border-radius: 2rpx;
  274. margin: 10rpx auto 0 auto;
  275. @include main_bg_color(theme);
  276. }
  277. .newsList .list .item {
  278. margin: 0 24rpx;
  279. border-bottom: 1rpx solid #f0f0f0;
  280. padding: 35rpx 0;
  281. }
  282. .newsList .list .item .pictrue {
  283. width: 250rpx;
  284. height: 156rpx;
  285. }
  286. .newsList .list .item .pictrue image {
  287. width: 100%;
  288. height: 100%;
  289. border-radius: 14rpx;
  290. }
  291. .newsList .list .item .text {
  292. width: 420rpx;
  293. height: 156rpx;
  294. font-size: 24rpx;
  295. color: #999;
  296. }
  297. .newsList .list .item .text .name {
  298. font-size: 30rpx;
  299. color: #282828;
  300. }
  301. .newsList .list .item .picList .pictrue {
  302. width: 335rpx;
  303. height: 210rpx;
  304. margin-top: 30rpx;
  305. }
  306. .newsList .list .item .picList.on .pictrue {
  307. width: 217rpx;
  308. height: 136rpx;
  309. }
  310. .newsList .list .item .picList .pictrue image {
  311. width: 100%;
  312. height: 100%;
  313. border-radius: 6rpx;
  314. }
  315. .newsList .list .item .time {
  316. text-align: right;
  317. font-size: 24rpx;
  318. color: #999;
  319. margin-top: 22rpx;
  320. }
  321. </style>