info.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <scroll-view style="height:100%" :scroll-y="true" :refresher-enabled="true" :refresher-triggered="triggered"
  3. @scrolltolower="scrolltolower" @refresherrefresh="onRefresh" refresher-default-style="black">
  4. <view class="infoBox" v-for="item in infoList" :key="item" @click="goDetail(item)">
  5. <view class="title">{{item.title}}</view>
  6. <view class="info">
  7. <view class="leftBox">
  8. <view class="content">
  9. {{item.content}}
  10. </view>
  11. <view class="attentionSituation">
  12. <view class="collectCount">
  13. <i class="custom-icon custom-icon-collected"></i>
  14. 2145
  15. </view>
  16. <!-- <view class="commentCount">
  17. <i class="custom-icon custom-icon-comment"></i>
  18. 543
  19. </view> -->
  20. <view class="time">
  21. {{item.updateTime ? formatDate(Date.parse(item.updateTime)): ""}}
  22. </view>
  23. </view>
  24. </view>
  25. <!-- <image src="@/static/1.png" alt="图片走丢啦" /> -->
  26. </view>
  27. </view>
  28. </scroll-view>
  29. </template>
  30. <script>
  31. import { getInfoList } from '@/api/info.js'
  32. import { formatDate } from '@/utils/util.js'
  33. export default {
  34. data() {
  35. return {
  36. loadingStatus: 'loadmore', // 上拉loading
  37. triggered: false, // 下拉是否激活
  38. infoList: [],
  39. total: 0,
  40. pageNum: 1,
  41. pageSize: 10,
  42. isRequesting: false, // 是否正在请求,如果是则返回,用于节流
  43. infoParams: {
  44. pageNum: 1,
  45. pageSize: 10,
  46. checkStatus: '5', // 已发布的数据
  47. },
  48. };
  49. },
  50. methods: {
  51. // 上拉加载
  52. scrolltolower() {
  53. if (this.infoList.length < this.total) {
  54. this.pageNum += 1;
  55. // 继续请求下一页,记得保留原先数组
  56. this.getList();
  57. } else {
  58. uni.showToast({
  59. title: "没有更多了",
  60. icon: "none",
  61. duration: 2000,
  62. });
  63. return;
  64. }
  65. },
  66. // 自定义下拉刷新被触发
  67. onRefresh() {
  68. // 开启下拉自定义样式
  69. this.triggered = true;
  70. // 重新调用
  71. this.getList();
  72. // 1秒之后复位
  73. setTimeout(() => {
  74. this.triggered = false;
  75. }, 1000);
  76. },
  77. getList(params={}) {
  78. this.isRequesting = true
  79. getInfoList({
  80. ...this.infoParams,
  81. ...params
  82. }).then(res => {
  83. // console.log("res:", res)
  84. this.infoList = [...this.infoList, ...res.rows]
  85. // console.log('infoList', this.infoList)
  86. this.total = res.total
  87. this.loadingStatus = this.infoList.length >= this.total ? 'nomore' : 'loading'
  88. }).finally(() => this.isRequesting = false)
  89. },
  90. // 点击资讯跳转详情
  91. goDetail(val) {
  92. console.log('跳转')
  93. uni.navigateTo({
  94. url: '/pages/index/detail'
  95. });
  96. },
  97. }
  98. }
  99. </script>
  100. <style lang="scss">
  101. .infoBox {
  102. width: 96%;
  103. background-color: #fff;
  104. padding: 20rpx;
  105. height: 260rpx;
  106. margin: 0 auto;
  107. margin-top: 20rpx;
  108. border-radius: 24rpx;
  109. box-shadow: 0 0 10rpx 6rpx rgba(0, 0, 0, 0.1);
  110. color: #666;
  111. .title {
  112. font-size: 32rpx;
  113. font-weight: 600;
  114. white-space: nowrap;
  115. overflow: hidden;
  116. text-overflow: ellipsis;
  117. height: 26%;
  118. }
  119. .info {
  120. width: 100%;
  121. height: 74%;
  122. display: flex;
  123. // align-items: center;
  124. image {
  125. width: 160rpx;
  126. height: 160rpx;
  127. border-radius: 10rpx;
  128. }
  129. .leftBox {
  130. flex: 1;
  131. // width: 66%;
  132. display: flex;
  133. flex-direction: column;
  134. justify-content: space-between;
  135. .content {
  136. overflow: hidden;
  137. text-overflow: ellipsis;
  138. display: -webkit-box;
  139. -webkit-line-clamp: 3;
  140. -webkit-box-orient: vertical;
  141. }
  142. .attentionSituation {
  143. font-size: 24rpx;
  144. display: flex;
  145. align-items: center;
  146. .collectCount,
  147. .commentCount {
  148. display: flex;
  149. align-items: center;
  150. }
  151. .custom-icon {
  152. margin-right: 10rpx;
  153. &::before {
  154. background: -webkit-linear-gradient(left, #f84a1a, #ffa53e);
  155. -webkit-background-clip: text;
  156. -webkit-text-fill-color: transparent;
  157. font-weight: bold;
  158. }
  159. }
  160. .commentCount {
  161. margin: 0 30rpx;
  162. }
  163. .time {
  164. color: #aaa;
  165. }
  166. }
  167. }
  168. }
  169. }
  170. </style>