artList.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <view class="content">
  3. <view class="main">
  4. <view v-for="(item, index) in list">
  5. <view class="first" v-if="index == 0" @click="navToList(item.id)">
  6. <view class="title">{{item.title}}</view>
  7. <view class="image"><image :src="item.image_input[0]" mode=""></image></view>
  8. <view class="time">{{item.add_time}}</view>
  9. </view>
  10. <view class="item flex" @click="navToList(item.id)" v-else>
  11. <view class="item-left"><image :src="item.image_input[0]" mode=""></image></view>
  12. <view class="item-right">
  13. <view class="item-font clamp">{{item.title}}</view>
  14. <view class="item-time">{{item.add_time}}</view>
  15. </view>
  16. </view>
  17. </view>
  18. </view>
  19. <uni-load-more :status="loadingType"></uni-load-more>
  20. </view>
  21. </template>
  22. <script>
  23. import { article } from '@/api/user.js';
  24. export default {
  25. data() {
  26. return {
  27. list: [],
  28. page: 1.,
  29. limit: 10,
  30. loadingType: 'more'
  31. };
  32. },
  33. onLoad() {
  34. this.loadData();
  35. },
  36. onShareAppMessage(options) {
  37. // 设置菜单中的转发按钮触发转发事件时的转发内容
  38. let pages = getCurrentPages(); //获取加载的页面
  39. let currentPage = pages[pages.length - 1]; //获取当前页面的对象
  40. let url = currentPage.route; //当前页面url
  41. let item = currentPage.options; //如果要获取url中所带的参数可以查看options
  42. let shareObj = {
  43. title: '水箱计算', // 默认是小程序的名称(可以写slogan等)
  44. path: url, // 默认是当前页面,必须是以‘/’开头的完整路径
  45. imageUrl: '',
  46. success: function(res) {
  47. // 转发成功之后的回调
  48. if (res.errMsg == 'shareAppMessage:ok') {}
  49. },
  50. fail: function() {
  51. // 转发失败之后的回调
  52. if (res.errMsg == 'shareAppMessage:fail cancel') {
  53. // 用户取消转发
  54. } else if (res.errMsg == 'shareAppMessage:fail') {
  55. // 转发失败,其中 detail message 为详细失败信息
  56. }
  57. }
  58. };
  59. return shareObj;
  60. },
  61. methods: {
  62. // 载入数据
  63. async loadData() {
  64. let obj = this;
  65. if(obj.loadingType == 'noMore' || obj.loadingType == 'loading' ) {
  66. return
  67. }
  68. obj.loadingType = 'loading'
  69. article({page:obj.page,limit:obj.limit},1).then(({data}) =>{
  70. obj.list = obj.list.concat(data)
  71. obj.page++
  72. if(data.length == obj.limit) {
  73. obj.loadingType = 'more'
  74. }else {
  75. obj.loadingType = 'noMore'
  76. }
  77. })
  78. },
  79. navToList(id) {
  80. uni.navigateTo({
  81. url: '/pages/index/artDetail?id=' + id
  82. });
  83. }
  84. }
  85. };
  86. </script>
  87. <style lang="scss">
  88. page,
  89. .content {
  90. height: auto;
  91. min-height: 100%;
  92. background: #f5f5f5;
  93. }
  94. .main {
  95. // margin-top: 20rpx;
  96. background: #ffffff;
  97. .first {
  98. padding: 50rpx 0 18rpx;
  99. margin: 0 22rpx;
  100. border-bottom: 1px solid #e0e0e0;
  101. .title {
  102. font-size: 32rpx;
  103. font-family: PingFang SC;
  104. font-weight: bold;
  105. color: #333333;
  106. }
  107. .image {
  108. width: 710rpx;
  109. height: 400rpx;
  110. background: #eee;
  111. margin-top: 20rpx;
  112. image {
  113. width: 100%;
  114. height: 100%;
  115. }
  116. }
  117. .time {
  118. margin-top: 20rpx;
  119. font-size: 26rpx;
  120. font-family: PingFang SC;
  121. font-weight: 500;
  122. color: #666666;
  123. }
  124. }
  125. .item {
  126. padding: 26rpx 0 18rpx;
  127. margin: 0 22rpx;
  128. justify-content: flex-start;
  129. align-items: flex-start;
  130. border-bottom: 1px solid #e0e0e0;
  131. .item-left {
  132. width: 224rpx;
  133. height: 160rpx;
  134. image {
  135. width: 100%;
  136. height: 100%;
  137. }
  138. }
  139. .item-right {
  140. width: 458rpx;
  141. height: 160rpx;
  142. margin-left: 24rpx;
  143. padding: 18rpx 0;
  144. display: flex;
  145. flex-direction: column;
  146. justify-content: space-between;
  147. .item-font {
  148. font-size: 32rpx;
  149. font-family: PingFang SC;
  150. font-weight: bold;
  151. color: #333333;
  152. }
  153. .item-time {
  154. font-size: 28rpx;
  155. font-family: PingFang SC;
  156. font-weight: 500;
  157. color: #666666;
  158. }
  159. }
  160. }
  161. }
  162. </style>