list.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <view class="container">
  3. <u-navbar :is-fixed="false" :border-bottom="false" :is-back="true" back-icon-name="arrow-leftward"
  4. back-icon-color="#fff" back-icon-size="35" title="新闻动态" :background="{ background: 'linear-gradient(90deg, #69b0ff, #5f88ff)' }"
  5. title-color="#fff">
  6. <image slot="right" src="/static/images/home/message.png" class="message-icon" mode="widthFix"></image>
  7. </u-navbar>
  8. <view class="tab">
  9. <u-tabs :list="tabs" :is-scroll="false" :current="current" active-color="#69b0ff" inactive-color="#595959"
  10. height="100" @change="change"></u-tabs>
  11. </view>
  12. <swiper id="swiperBox" :style="{ height: swiperHeight + 'px' }" :current="current" @change="tabsChange">
  13. <swiper-item class="swiper-item" v-for="(pitem, pindex) in tabs" :key="pindex">
  14. <scroll-view scroll-y style="width: 100%;height: 100%;" refresher-enabled
  15. :refresher-triggered="pitem.triggered" @scrolltolower="onreachBottom"
  16. @refresherrefresh="refresherrefresh(pindex)" @refresherrestore="refresherrestore(pindex)"
  17. @refresherabort="refresherabort(pindex)">
  18. <view class="content">
  19. <navigator class="news" v-for="(item, index) in contentList[pindex].list" :key="index"
  20. url="/pages/news/detail" hover-class="none">
  21. <view class="head">
  22. <image src="" class="avatar" mode=""></image>
  23. <view class="info">
  24. <view class="name">
  25. 中国空间站
  26. <text class="tag">专栏作家</text>
  27. </view>
  28. <view class="date">11-12</view>
  29. </view>
  30. <u-icon name="arrow-right" size="35" color="#C5C5C5"></u-icon>
  31. </view>
  32. <view class="des">
  33. 天舟五号创造多个航天新纪录。
  34. </view>
  35. </navigator>
  36. <view class="nomore">
  37. <u-loadmore :status="contentList[pindex].status" />
  38. </view>
  39. </view>
  40. </scroll-view>
  41. </swiper-item>
  42. </swiper>
  43. </view>
  44. </template>
  45. <script>
  46. export default {
  47. data() {
  48. return {
  49. swiperHeight: 0,
  50. tabs: [{
  51. name: '互动',
  52. triggered: false,
  53. _triggered: false
  54. },
  55. {
  56. name: '动态',
  57. triggered: false,
  58. _triggered: false
  59. },
  60. {
  61. name: '通知',
  62. triggered: false,
  63. _triggered: false
  64. }
  65. ],
  66. contentList: [{
  67. list: 8,
  68. page: 1,
  69. status: 'loadmore'
  70. },
  71. {
  72. list: 8,
  73. page: 1,
  74. status: 'loadmore'
  75. },
  76. {
  77. list: 8,
  78. page: 1,
  79. status: 'loadmore'
  80. }
  81. ],
  82. current: 0
  83. };
  84. },
  85. onLoad() {},
  86. onReady() {
  87. let that = this;
  88. uni.getSystemInfo({
  89. success(e) {
  90. console.log(e);
  91. let {
  92. windowWidth,
  93. windowHeight,
  94. safeArea
  95. } = e;
  96. const query = uni.createSelectorQuery().in(that);
  97. query
  98. .select('#swiperBox')
  99. .boundingClientRect(data => {
  100. that.swiperHeight = safeArea.bottom - data.top;
  101. })
  102. .exec();
  103. }
  104. });
  105. },
  106. onPullDownRefresh() {
  107. setTimeout(() => {
  108. uni.stopPullDownRefresh();
  109. }, 1500);
  110. },
  111. methods: {
  112. tabsChange(e) {
  113. this.current = e.detail.current;
  114. },
  115. refresherrefresh(index) {
  116. console.log('自定义下拉刷新被触发');
  117. let _this = this;
  118. if (_this.tabs[index]._triggered) {
  119. return;
  120. }
  121. _this.tabs[index]._triggered = true;
  122. //界面下拉触发,triggered可能不是true,要设为true
  123. if (!_this.tabs[index].triggered) {
  124. _this.tabs[index].triggered = true;
  125. }
  126. setTimeout(() => {
  127. _this.tabs[index].triggered = false; //触发onRestore,并关闭刷新图标
  128. _this.tabs[index]._triggered = false;
  129. }, 10);
  130. },
  131. refresherrestore(index) {
  132. console.log('自定义下拉刷新被复位');
  133. let _this = this;
  134. _this.tabs[index].triggered = false;
  135. _this.tabs[index]._triggered = false;
  136. },
  137. refresherabort(index) {
  138. console.log('自定义下拉刷新被中止 ');
  139. let _this = this;
  140. _this.tabs[index].triggered = false;
  141. _this.tabs[index]._triggered = false;
  142. },
  143. // scroll-view到底部加载更多
  144. onreachBottom() {
  145. let current = this.current;
  146. if (this.contentList[current].page >= 3) return;
  147. this.contentList[current].status = 'loading';
  148. setTimeout(() => {
  149. this.contentList[current].page = ++this.contentList[current].page;
  150. this.contentList[current].list += 10;
  151. if (this.contentList[current].page >= 3)
  152. this.contentList[current].status = 'nomore';
  153. else this.contentList[current].status = 'loading';
  154. }, 2000);
  155. },
  156. change(index) {
  157. this.current = index;
  158. }
  159. }
  160. };
  161. </script>
  162. <style lang="scss">
  163. .message-icon {
  164. width: 32rpx;
  165. height: auto;
  166. margin-right: 27rpx;
  167. }
  168. .tab {
  169. margin: 0 0 10rpx;
  170. border-bottom: 1px solid #e4e7ed;
  171. }
  172. .content {
  173. padding: 0 0 150rpx;
  174. .news {
  175. &:not(:last-of-type) {
  176. border-bottom: 2rpx solid #e4e7ed;
  177. }
  178. }
  179. }
  180. .nomore {
  181. padding: 30rpx 20rpx;
  182. }
  183. .news {
  184. margin: 30rpx 30rpx 0;
  185. padding: 0 0 30rpx;
  186. .head {
  187. display: flex;
  188. .avatar {
  189. flex-shrink: 0;
  190. width: 69rpx;
  191. height: 69rpx;
  192. background: #ffffff;
  193. // border: 1px solid #14b9c8;
  194. border: 1px solid #5f88ff;
  195. border-radius: 50%;
  196. }
  197. .info {
  198. flex: 1;
  199. margin-left: 14rpx;
  200. .name {
  201. display: flex;
  202. align-items: center;
  203. font-size: 28rpx;
  204. font-family: PingFang SC;
  205. font-weight: bold;
  206. color: #000000;
  207. line-height: 36rpx;
  208. .tag {
  209. margin-left: 15rpx;
  210. display: inline-block;
  211. padding: 8rpx 10rpx;
  212. font-size: 14rpx;
  213. font-family: PingFang SC;
  214. font-weight: 500;
  215. color: #69b0ff;
  216. line-height: 21rpx;
  217. border: 1px solid #69b0ff;
  218. border-radius: 6px;
  219. }
  220. }
  221. .date {
  222. font-size: 24rpx;
  223. font-family: PingFang SC;
  224. font-weight: 500;
  225. color: #a3a3a3;
  226. line-height: 36rpx;
  227. }
  228. }
  229. }
  230. .des {
  231. margin-top: 40rpx;
  232. font-size: 30rpx;
  233. font-family: PingFang SC;
  234. color: #000000;
  235. line-height: 47rpx;
  236. }
  237. }
  238. .swiper-box {
  239. height: 100vh;
  240. }
  241. </style>