newsList.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <template>
  2. <view class="container">
  3. <!-- 搜索框区域 -->
  4. <view class="search">
  5. <view class="add">
  6. <image class="img" src="../../static/index/search.png" mode="aspectFit"></image>
  7. </view>
  8. <input class="inp" type="text" v-model="keywords" placeholder="请输入关键字" />
  9. <view class="btnSearch" @click="searchHandler">搜索</view>
  10. </view>
  11. <!-- 资讯列表区域 -->
  12. <scroll-view class="list" scroll-y @scrolltolower="handleLower">
  13. <!-- 每一条资讯区域 -->
  14. <view class="box" v-for="item in list" :key="item.id" @click="handleGoDetail(item)">
  15. <uv-image width="253rpx" height="190rpx" radius="8rpx" mode="aspectFill" :src="item.url" />
  16. <view class="box_detail">
  17. <view class="detail_title">{{ item.title ? item.title : '无标题' }}</view>
  18. <view class="detail_time">{{ item.update_time }}</view>
  19. </view>
  20. <!-- 富文本区域 -->
  21. <mp-html v-if="item.showHtml" @load="htmlLoad(item)" :ref="item.id + 'html'" :content="item.content" />
  22. </view>
  23. </scroll-view>
  24. </view>
  25. </template>
  26. <script>
  27. export default {
  28. data() {
  29. return {
  30. // 搜索框绑定数据
  31. keywords: '',
  32. // 资讯列表
  33. list: [],
  34. // 当前页
  35. pageNews: 1,
  36. // 每页多少条
  37. rowsNews: 8,
  38. // 总条数
  39. totalNews: null
  40. }
  41. },
  42. onLoad() {
  43. this.getNews()
  44. },
  45. methods: {
  46. // 获取资讯列表
  47. async getNews() {
  48. const res = await this.$myRequest({
  49. url: '/mhotel/appnewlist.action',
  50. data: {
  51. page: this.pageNews,
  52. rows: this.rowsNews,
  53. title: this.keywords
  54. }
  55. })
  56. // console.log(res)
  57. if (res.code === 200) {
  58. this.list = [...this.list, ...res.rows]
  59. this.list.forEach((ele) => {
  60. this.$set(ele, 'showHtml', true)
  61. })
  62. this.totalNews = res.total
  63. }
  64. },
  65. // 点击搜索按钮回调
  66. searchHandler() {
  67. ;(this.list = []), (this.pageNews = 1)
  68. this.getNews()
  69. },
  70. // 页面到底触发回调
  71. handleLower() {
  72. if (this.list.length < this.totalNews) {
  73. this.pageNews++
  74. this.getNews()
  75. } else {
  76. uni.showToast({
  77. title: '没有更多数据了',
  78. icon: 'none'
  79. })
  80. }
  81. },
  82. // 跳转资讯详情回调
  83. handleGoDetail(item) {
  84. let info = encodeURIComponent(JSON.stringify(item))
  85. uni.navigateTo({
  86. url: `/pages/newsDetail/newsDetail?info=${info}`
  87. })
  88. },
  89. // 获取富文本信息回调
  90. htmlLoad(item) {
  91. let id = item.id + 'html'
  92. let ctx = this.$refs[id][0]
  93. let imgs = ctx.imgList[0]
  94. item.showHtml = false
  95. item.url = imgs
  96. }
  97. }
  98. }
  99. </script>
  100. <style lang="scss" scoped>
  101. .container {
  102. box-sizing: border-box;
  103. padding: 20rpx;
  104. height: 100vh;
  105. background-color: #f2f2f2;
  106. .search {
  107. display: flex;
  108. justify-content: space-between;
  109. align-items: center;
  110. height: 80rpx;
  111. opacity: 1;
  112. border-radius: 70px;
  113. background-color: #fff;
  114. .add {
  115. display: flex;
  116. justify-content: center;
  117. align-items: center;
  118. margin-left: 10rpx;
  119. width: 60rpx;
  120. height: 60rpx;
  121. .img {
  122. width: 30rpx;
  123. height: 30rpx;
  124. }
  125. }
  126. .inp {
  127. height: 60rpx;
  128. line-height: 60rpx;
  129. flex-grow: 1;
  130. font-size: 28rpx;
  131. }
  132. .btnSearch {
  133. margin-right: 10rpx;
  134. width: 100rpx;
  135. height: 60rpx;
  136. line-height: 60rpx;
  137. text-align: center;
  138. opacity: 1;
  139. font-size: 28rpx;
  140. color: #096562;
  141. }
  142. }
  143. .list {
  144. height: calc(100vh - 140rpx);
  145. padding: 20rpx 0;
  146. .box {
  147. box-sizing: border-box;
  148. padding: 20rpx 30rpx 20rpx 20rpx;
  149. margin-bottom: 20rpx;
  150. display: flex;
  151. width: 710rpx;
  152. height: 230rpx;
  153. background-color: #fff;
  154. // .box_img {
  155. // width: 253rpx;
  156. // height: 190rpx;
  157. // border-radius: 8rpx;
  158. // }
  159. .box_detail {
  160. flex: 1;
  161. display: flex;
  162. flex-direction: column;
  163. justify-content: space-between;
  164. margin-left: 20rpx;
  165. .detail_title {
  166. font-size: 32rpx;
  167. font-weight: bold;
  168. display: -webkit-box;
  169. -webkit-box-orient: vertical;
  170. -webkit-line-clamp: 2;
  171. overflow: hidden;
  172. }
  173. .detail_time {
  174. color: #666666;
  175. font-size: 24rpx;
  176. }
  177. }
  178. }
  179. }
  180. }
  181. </style>