index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <view>
  3. <view class="article_list">
  4. <view class="article_item" v-for="(item,index) in articleList" @click.stop="goDetail(item.id)">
  5. <image class="thumb_img" :src="item.thumb" mode="aspectFit"></image>
  6. <view class="article_info">
  7. <view class="article_title">{{item.title}}</view>
  8. <view class="article_census">
  9. <text class="">阅读:{{item.read_count}}</text> <text class="">点赞:{{item.hand_count}}</text>
  10. </view>
  11. <view class="article_time">{{item.insert_time}}</view>
  12. </view>
  13. </view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. data() {
  20. return {
  21. // 产品列表
  22. articleList: [],
  23. // 请求参数
  24. requestParam: {
  25. page: 1,
  26. status: 0,
  27. },
  28. // 是否最后一页
  29. isLast: false,
  30. // 是否请求中
  31. isReqing: false,
  32. };
  33. },
  34. onLoad() {},
  35. onShow() {
  36. // 没有数据的话,或者请求中,不允许刷新
  37. if (this.isReqing) return;
  38. // 初始化页码为1
  39. this.requestParam.page = 1;
  40. // 是否是最后一页
  41. this.isLast = false;
  42. // 设置请求中
  43. this.isReqing = true;
  44. // 请求列表
  45. this.$http.request("api/article/get_list", this.requestParam).then((re) => {
  46. // 设置非请求中
  47. this.isReqing = false;
  48. // 成功结果
  49. if (re.code == "success") {
  50. if (re.data.last_page <= this.requestParam.page) this.isLast = true;
  51. this.articleList = re.data.data;
  52. }
  53. });
  54. },
  55. onPullDownRefresh() {
  56. // 如果请求中,不允许请求,
  57. if (this.isReqing) return false;
  58. // 初始化页码为1
  59. this.requestParam.page = 1;
  60. // 是否是最后一页
  61. this.isLast = false;
  62. // 设置请求中
  63. this.isReqing = true;
  64. // 请求列表
  65. this.$http.request("api/article/get_list", this.requestParam).then((re) => {
  66. // 设置非请求中
  67. this.isReqing = false;
  68. // 成功结果
  69. if (re.code == "success") {
  70. if (re.data.last_page <= this.requestParam.page) this.isLast = true;
  71. this.articleList = re.data.data;
  72. }
  73. });
  74. uni.stopPullDownRefresh();
  75. },
  76. onReachBottom() {
  77. // 如果页码是0,避免第一页重复
  78. if (this.requestParam.page < 1) return;
  79. // 最后一页不请求
  80. if (this.isLast) return;
  81. // 请求中,不再请求
  82. if (this.isReqing) return;
  83. // 增加一页
  84. this.requestParam.page = this.requestParam.page + 1;
  85. // 设置请求中
  86. this.isReqing = true;
  87. // 请求列表
  88. this.$http.request("api/article/get_list", this.requestParam).then((re) => {
  89. // 设置非请求中
  90. this.isReqing = false;
  91. // 成功结果
  92. if (re.code == "success") {
  93. // 数据
  94. if (re.data.last_page <= this.requestParam.page) this.isLast = true;
  95. // 追加数据
  96. this.articleList.push(...re.data.data);
  97. }
  98. });
  99. },
  100. methods: {
  101. goDetail(id) {
  102. uni.navigateTo({
  103. url: "/pages/article/detail?id=" + id,
  104. });
  105. },
  106. }
  107. }
  108. </script>
  109. <style lang="less">
  110. .article_list{
  111. float: left;
  112. width: 750rpx;
  113. display: block;
  114. overflow: hidden;
  115. .article_item{
  116. display: block;
  117. width: 700rpx;
  118. height: 200rpx;
  119. overflow: hidden;
  120. margin-bottom: 10rpx;
  121. padding: 20rpx 25rpx;
  122. border-radius: 10rpx;
  123. background-color: #FFFFFF;
  124. .thumb_img{
  125. float: left;
  126. width: 200rpx;
  127. height: 200rpx;
  128. display: block;
  129. border-radius: 10rpx;
  130. }
  131. .article_info{
  132. float: right;
  133. width: 480rpx;
  134. display: block;
  135. margin-left: 20rpx;
  136. .article_title{
  137. width: 480rpx;
  138. display: block;
  139. height: 120rpx;
  140. font-size: 34rpx;
  141. overflow: hidden;
  142. font-weight: bold;
  143. line-height: 40rpx;
  144. text-overflow: ellipsis;
  145. }
  146. .article_census{
  147. color: #999999;
  148. width: 480rpx;
  149. display: block;
  150. height: 40rpx;
  151. font-size: 26rpx;
  152. line-height: 40rpx;
  153. text:nth-child(2){
  154. margin-left: 20rpx;
  155. }
  156. }
  157. .article_time{
  158. color: #999999;
  159. width: 480rpx;
  160. display: block;
  161. height: 60rpx;
  162. font-size: 26rpx;
  163. text-align: right;
  164. line-height: 60rpx;
  165. }
  166. }
  167. }
  168. }
  169. </style>