new_list.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <view class="">
  3. <view class="bg">
  4. </view>
  5. <view class="new_list position">
  6. <view class="search">
  7. <image src="../../static/images/search.png" mode=""></image>
  8. <input type="text" v-model="search" placeholder="请输入搜索内容" placeholder-style="font-size:14px;color:#D9D0C8;"
  9. @change='Search' @confirm="Search" />
  10. </view>
  11. <view class="empty" v-if="news_list== undefined||news_list.length == 0">
  12. <u-empty text="没有内容哦!" mode="list"></u-empty>
  13. </view>
  14. <view class="news_item" v-for="(item,index) in news_list" :key="index" @click="to_new_detail(item.id)">
  15. <view class="item_left">
  16. <image :src="item.cover_resource?item.cover_resource.url:url" mode="aspectFill"></image>
  17. </view>
  18. <view class="item_right">
  19. <view class="item_title">
  20. {{item.title}}
  21. </view>
  22. <view class="item_num">
  23. <text>{{item.created_at}}</text>
  24. <text>阅读 {{item.view_count}}</text>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. export default{
  33. data(){
  34. return{
  35. news_list: [
  36. ],
  37. page:1,
  38. last:false,
  39. search: '',
  40. category_id:''
  41. }
  42. },
  43. onShow() {
  44. },
  45. onLoad(options) {
  46. this.category_id=options.category_id
  47. this.getNew()
  48. },
  49. // 触底加载更多
  50. onReachBottom() {
  51. if (!this.last) {
  52. this.page++
  53. }
  54. console.log(this.page)
  55. this.getNew()
  56. },
  57. methods:{
  58. getNew() {
  59. this.$u.get('/page/news', {
  60. title: this.search,
  61. page: this.page,
  62. category_id:this.category_id
  63. }).then(res => {
  64. console.log(res, '新闻详情')
  65. let data = res.data.data
  66. if (this.page > 1 && data.length == 0) {
  67. uni.showToast({
  68. title: '暂无更多',
  69. icon: 'none'
  70. })
  71. this.last = true
  72. } else {
  73. this.news_list = this.news_list.concat(data)
  74. }
  75. })
  76. },
  77. //搜索
  78. Search() {
  79. console.log('pppp')
  80. this.page = 1
  81. this.news_list = []
  82. this.getNew()
  83. },
  84. to_new_detail(id) {
  85. uni.navigateTo({
  86. url: 'news_detail?id=' + id
  87. })
  88. },
  89. }
  90. }
  91. </script>
  92. <style lang="scss" scoped>
  93. .new_list{
  94. padding: 20px 16px 20px;
  95. // background-color: #F9F9FB;
  96. .empty{
  97. margin-top: 45%;
  98. }
  99. .search {
  100. display: flex;
  101. align-items: center;
  102. height: 52px;
  103. box-shadow: 0px 8px 16px rgba(12, 20, 61, 0.06);
  104. border-radius: 10px;
  105. // padding-top: 20px;
  106. background-color: #fff;
  107. image {
  108. width: 16px;
  109. height: 16px;
  110. margin-left: 20px;
  111. margin-right: 20px;
  112. }
  113. }
  114. .news_item {
  115. background-color: #fff;
  116. display: flex;
  117. align-items: center;
  118. padding: 10px 8px;
  119. margin-top: 20px;
  120. box-shadow: 0px 8px 12px rgba(12, 20, 61, 0.06);
  121. border-radius: 4px;
  122. .item_left {
  123. width: 92px;
  124. height: 76px;
  125. overflow: hidden;
  126. flex-shrink: 0;
  127. margin-right: 8px;
  128. border-radius: 4px;
  129. image {
  130. width: 92px;
  131. height: 76px;
  132. }
  133. }
  134. .item_right {
  135. width: 100%;
  136. .item_title {
  137. height: 40px;
  138. overflow: hidden;
  139. -webkit-line-clamp: 2;
  140. text-overflow: ellipsis;
  141. display: -webkit-box;
  142. -webkit-box-orient: vertical;
  143. font-size: 15px;
  144. font-family: Graphit;
  145. font-weight: 500;
  146. line-height: 20px;
  147. color: #282828;
  148. }
  149. .item_num {
  150. margin-top: 10px;
  151. font-size: 10px;
  152. font-family: PingFang HK;
  153. font-weight: 400;
  154. color: #B2B2B2;
  155. text {
  156. display: inline-block;
  157. width: 50%;
  158. overflow: hidden;
  159. &:last-child {
  160. text-align: right;
  161. }
  162. }
  163. }
  164. }
  165. }
  166. }
  167. </style>