index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <view class="news">
  3. <view class="news-box">
  4. <!-- 置顶 -->
  5. <template v-if="dataList.length > 0">
  6. <view class="news-item" v-for="(item, index) in dataList" :key="item.id" @click="goNewsDetail(item)">
  7. <template v-if="item.thumbnail && item.thumbnail.length > 1">
  8. <view class="item-imgs-box">
  9. <view class="txt">
  10. <view class="title">
  11. {{item.title}}
  12. </view>
  13. </view>
  14. <view class="imgs">
  15. <image v-for="(el, j) in item.thumbnail" :key="j" class="img" :src="el" mode="aspectFill">
  16. </image>
  17. </view>
  18. <view class="tag-time">
  19. <image class="top" v-if="item.stick" src="/static/common/top.png" mode="widthFix"></image>
  20. <text class="time">{{item.publisher||'松河公益'}} {{$u.timeFormat(item.create_time, 'yyyy-mm-dd')}}</text>
  21. <text class="browse_sum">{{item.browse_sum || 0}} 浏览量</text>
  22. </view>
  23. </view>
  24. </template>
  25. <template v-else>
  26. <view class="item-img-box">
  27. <view class="txt">
  28. <view class="title">{{item.title}}</view>
  29. <view class="tag-time">
  30. <image class="top" v-if="item.stick" src="/static/common/top.png" mode="widthFix"></image>
  31. <text class="time">{{item.publisher||'松河公益'}} {{$u.timeFormat(item.create_time, 'yyyy-mm-dd')}}</text>
  32. <text class="browse_sum">{{item.browse_sum || 0}} 浏览</text>
  33. </view>
  34. </view>
  35. <view class="imgs" v-if="item.thumbnail && item.thumbnail.length">
  36. <image class="img" :src="item.thumbnail[0]" mode="aspectFill"></image>
  37. </view>
  38. </view>
  39. </template>
  40. </view>
  41. </template>
  42. <template v-else>
  43. <noData :config="{top:0}"></noData>
  44. </template>
  45. <view class="loadmoreBox" v-if="dataList.length>0">
  46. <u-loadmore :status="status" />
  47. </view>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. import noData from "@/components/noData/nodata.vue"
  53. export default {
  54. components: {
  55. noData
  56. },
  57. name: 'news',
  58. props: {
  59. classify_id: {
  60. type: [Number, String],
  61. default: ''
  62. }
  63. },
  64. data() {
  65. return {
  66. dataList: [],
  67. params: {
  68. page: 1,
  69. limit: 10,
  70. },
  71. totalCount: 0,
  72. totalPage: 0,
  73. currPage: 0,
  74. status: ''
  75. }
  76. },
  77. methods: {
  78. // 获取资讯分类列表
  79. loadData(e, type) {
  80. if (type == 'more') {
  81. if (this.currPage < this.totalPage) {
  82. this.params.page++
  83. } else {
  84. return false
  85. }
  86. } else if (type == 'refresh') {
  87. this.params.page = 1
  88. }
  89. if (e == 0) this.params.recommend = 1
  90. if (this.params.page == 1) this.dataList = []
  91. uni.showLoading({
  92. title: '加载中..'
  93. })
  94. this.$http.get('/information/page', {
  95. ...this.params,
  96. classify_id: this.classify_id,
  97. }).then(res => {
  98. if (res && res.code == 200) {
  99. this.dataList = [...this.dataList, ...res.page.list]
  100. this.totalCount = res.page.totalCount
  101. this.totalPage = res.page.totalPage
  102. this.currPage = res.page.currPage
  103. this.status = this.dataList.length >= res.page.totalCount ? 'nomore' : 'loadmore'
  104. this.$emit('getSwiperHeight')
  105. setTimeout(() => {
  106. uni.hideLoading()
  107. }, 300)
  108. }
  109. }).catch(err => {
  110. setTimeout(() => {
  111. uni.hideLoading()
  112. }, 300)
  113. })
  114. },
  115. goNewsDetail(item) {
  116. uni.navigateTo({
  117. url: `/pages/index/news_detail?id=${item.id}`
  118. })
  119. },
  120. }
  121. }
  122. </script>
  123. <style lang="scss" scoped>
  124. .news-box {
  125. padding: 30rpx;
  126. .news-item {
  127. width: 100%;
  128. padding: 40rpx 0;
  129. border-bottom: 1rpx solid #e6e6e6;
  130. font-family: PingFang SC, PingFang SC-Regular;
  131. font-weight: 400;
  132. &:nth-child(1) {
  133. padding-top: 0;
  134. }
  135. .txt {
  136. font-size: 28rpx;
  137. color: #1a1a1a;
  138. .title {
  139. margin-bottom: 10rpx;
  140. word-break: break-all;
  141. text-overflow: ellipsis;
  142. overflow: hidden;
  143. display: -webkit-box;
  144. -webkit-box-orient: vertical;
  145. -webkit-line-clamp: 3;
  146. .top {
  147. width: 72rpx;
  148. height: 33rpx;
  149. font-size: 0;
  150. margin-right: 22rpx;
  151. flex-shrink: 0;
  152. vertical-align: middle;
  153. margin-bottom: 2rpx;
  154. // image {
  155. // width: 100%;
  156. // height: 100%;
  157. // }
  158. }
  159. }
  160. }
  161. .tag-time {
  162. display: flex;
  163. align-items: center;
  164. font-size: 24rpx;
  165. color: #999999;
  166. .time {
  167. max-width: 70%;
  168. overflow: hidden;
  169. white-space: nowrap;
  170. text-overflow: ellipsis;
  171. }
  172. .top {
  173. width: 72rpx;
  174. height: 33rpx;
  175. font-size: 0;
  176. margin-right: 22rpx;
  177. flex-shrink: 0;
  178. vertical-align: middle;
  179. // margin-bottom: 2rpx;
  180. }
  181. }
  182. // 无图及一张图片
  183. .item-img-box {
  184. display: flex;
  185. justify-content: space-between;
  186. .txt {
  187. flex: 1;
  188. width: 0;
  189. display: flex;
  190. flex-direction: column;
  191. justify-content: space-between;
  192. .title {
  193. margin-bottom: 0;
  194. }
  195. }
  196. .imgs {
  197. margin-left: 40rpx;
  198. font-size: 0;
  199. flex-shrink: 0;
  200. .img {
  201. width: 240rpx;
  202. height: 160rpx;
  203. border-radius: 10rpx;
  204. }
  205. }
  206. }
  207. // 多图
  208. .item-imgs-box {
  209. .imgs {
  210. display: flex;
  211. margin-bottom: 10rpx;
  212. font-size: 0;
  213. .img {
  214. width: 225rpx;
  215. height: 150rpx;
  216. margin-right: 8rpx;
  217. border-radius: 10rpx;
  218. }
  219. .img:nth-child(3n) {
  220. margin-right: 0;
  221. }
  222. }
  223. }
  224. .browse_sum {
  225. flex-shrink: 0;
  226. margin-left: 20rpx;
  227. }
  228. }
  229. }
  230. </style>