index2.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <template>
  2. <view class="content">
  3. <!-- 头部 -->
  4. <Header />
  5. <!-- 搜索框 -->
  6. <Search />
  7. <!-- 头部导航 -- tab标签 -->
  8. <MenuTab />
  9. <!-- 内容列表 -->
  10. <scroll-view style="height:calc(100% - 100rpx - (88rpx + 40rpx) - 80rpx)" :scroll-y="true"
  11. :refresher-enabled="true" :refresher-triggered="triggered" @scrolltolower="scrolltolower"
  12. @refresherrefresh="onRefresh" refresher-default-style="black">
  13. <!-- 需要滚动的区域 -->
  14. <u-list @scrolltolower="scrolltolower">
  15. <!-- 主资讯 -->
  16. <u-list-item v-if="mainInfo">
  17. <view class="firstInfo" @click="goDetail">
  18. <!-- <image src="@/static/2.jpg" alt=""></image> -->
  19. <!-- <image :src="getUrl(mainInfo.banner)" alt=""></image> -->
  20. <view class="left">
  21. <!-- <view class="time">2024/11/07</view> -->
  22. <view class="time">{{parseTime(mainInfo.updateTime, '{y}/{m}/{d}')}}</view>
  23. <view class="title">{{mainInfo.title}}</view>
  24. <!-- <view class="subTitle">副标题副标题副标题</view> -->
  25. </view>
  26. <view>
  27. <i class="custom-icon custom-icon-collect"></i>
  28. </view>
  29. </view>
  30. </u-list-item>
  31. <!-- 其余资讯 -->
  32. <u-list-item v-for="(item, index) in infoList" :key="index">
  33. <view class="info" @click="goDetail(item)">
  34. <view class="leftBox">
  35. <view class="title">
  36. {{item.title}}
  37. </view>
  38. <view class="attentionSituation">
  39. <view class="collectCount">
  40. <i class="custom-icon custom-icon-collected"></i>
  41. 2145
  42. </view>
  43. <!-- <view class="commentCount">
  44. <i class="custom-icon custom-icon-comment"></i>
  45. 543
  46. </view> -->
  47. <view class="time">
  48. 3分钟前
  49. </view>
  50. </view>
  51. </view>
  52. <image :src="getUrl(item.banner)" alt="图片走丢啦" />
  53. </view>
  54. </u-list-item>
  55. </u-list>
  56. <view class="finished" v-if="finished">到底啦~~</view>
  57. </scroll-view>
  58. <!-- 底部导航 -->
  59. <Tabbar :current-page="0" />
  60. </view>
  61. </template>
  62. <script>
  63. import Header from "@/components/Header/index.vue";
  64. import Search from "@/components/Search/index.vue";
  65. import MenuTab from "@/components/MenuTab/index.vue";
  66. import Tabbar from "@/components/Tabbar/index.vue";
  67. import {
  68. getInfoList
  69. } from '@/api/info.js'
  70. import {
  71. baseUrl
  72. } from "@/utils/apiconfig.js";
  73. import {
  74. parseTime
  75. } from '@/utils/util.js'
  76. export default {
  77. components: {
  78. Header,
  79. Search,
  80. MenuTab,
  81. Tabbar
  82. },
  83. data() {
  84. return {
  85. triggered: false, // 下拉是否激活
  86. tabDetailList: [],
  87. total: 0,
  88. pageNum: 1,
  89. pageSize: 10,
  90. isRequesting: false, // 是否正在请求,如果是则返回,用于节流
  91. infoList: [], // 资讯列表(除资讯列表第一条数据的)
  92. mainInfo: {}, // 主资讯(资讯列表的第一条数据)
  93. finished: false, // 是否请求完所有的数据
  94. }
  95. },
  96. onLoad() {
  97. this.getInfoType();
  98. this.loadmore();
  99. },
  100. methods: {
  101. parseTime,
  102. // 获取图片完整地址
  103. getUrl(url) {
  104. return baseUrl + url
  105. },
  106. // 获取资讯分类
  107. getInfoType() {
  108. // this.request('/info/category/list', 'GET').then(res => {
  109. // console.log("res:", res)
  110. // if (res) {}
  111. // })
  112. },
  113. // 上拉加载
  114. scrolltolower() {
  115. if (this.infoList.length < this.total) {
  116. this.pageNum += 1;
  117. // 继续请求下一页,记得保留原先数组
  118. this.loadmore();
  119. } else {
  120. this.finished = true
  121. uni.showToast({
  122. title: "没有更多了",
  123. icon: "none",
  124. duration: 2000,
  125. });
  126. return;
  127. }
  128. },
  129. // 自定义下拉刷新被触发
  130. onRefresh() {
  131. // 开启下拉自定义样式
  132. this.triggered = true;
  133. // 重新调用
  134. this.loadmore();
  135. // 1秒之后复位
  136. setTimeout(() => {
  137. this.triggered = false;
  138. }, 1000);
  139. },
  140. loadmore() {
  141. // console.log('parseTime', parseTime('2025-01-01 10:22:22', '{y}/{m}/{d}'))
  142. // this.request('/info/infoContent/list', 'GET').then(res => {
  143. // console.log("res:", res)
  144. // if (res) {}
  145. // })
  146. let params = {
  147. pageNum: this.pageNum,
  148. pageSize: this.pageSize,
  149. }
  150. getInfoList(params).then(res => {
  151. console.log("res:", res)
  152. this.infoList = [...this.infoList, ...res.rows]
  153. console.log("res:", this.infoList)
  154. // 如果是第一页的数据,需要将第一条数据单独拿出来
  155. if (this.pageNum === 1) {
  156. this.mainInfo = res.rows[0]
  157. this.infoList = res.rows.filter((item, index) => index !== 0)
  158. } else {
  159. this.infoList = [...this.infoList, ...res.rows]
  160. }
  161. this.total = res.total - 1
  162. })
  163. },
  164. // 点击资讯跳转详情
  165. goDetail(val) {
  166. console.log('跳转')
  167. uni.navigateTo({
  168. url: '/pages/index/detail'
  169. });
  170. },
  171. }
  172. }
  173. </script>
  174. <style lang="scss">
  175. page {
  176. background-color: #f9f9f9;
  177. font-size: 28rpx;
  178. height: 100%;
  179. // background-color: yellow;
  180. }
  181. .content {
  182. height: 100%;
  183. padding-top: 20rpx;
  184. // display: flex;
  185. // flex-direction: column;
  186. // background-color: red;
  187. .Search {
  188. margin: 20rpx 0;
  189. }
  190. .u-list {
  191. display: inline-block;
  192. // margin-bottom: 200rpx;
  193. // height: calc(100% - 100rpx - 88rpx - 80rpx - 120rpx) !important;
  194. // background-color: red;
  195. height: 100% !important;
  196. // margin-bottom: 100px;
  197. }
  198. .firstInfo {
  199. margin: 20rpx auto;
  200. width: 90%;
  201. height: 320rpx;
  202. // background-image: url(../../static/2.jpg);
  203. // background-repeat: no-repeat;
  204. // background-size: 100% 100%;
  205. // border-radius: 30rpx;
  206. // background-color: red;
  207. display: flex;
  208. justify-content: space-between;
  209. padding: 40rpx;
  210. color: #fff;
  211. font-size: 32rpx;
  212. position: relative;
  213. z-index: 0;
  214. image {
  215. position: absolute;
  216. top: 0;
  217. left: 0;
  218. width: 100%;
  219. height: 320rpx;
  220. border-radius: 30rpx;
  221. z-index: -1;
  222. }
  223. .time {
  224. opacity: 0.8;
  225. font-size: 24rpx;
  226. }
  227. .title {
  228. margin: 10rpx 0;
  229. }
  230. .custom-icon-collect {
  231. font-size: 40rpx;
  232. }
  233. }
  234. .info {
  235. width: 90%;
  236. background-color: #fff;
  237. display: flex;
  238. padding: 20rpx;
  239. height: 260rpx;
  240. margin: 10rpx auto;
  241. border-radius: 24rpx;
  242. box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.2);
  243. .leftBox {
  244. width: 66%;
  245. display: flex;
  246. flex-direction: column;
  247. justify-content: space-between;
  248. }
  249. .title {
  250. overflow: hidden;
  251. text-overflow: ellipsis;
  252. display: -webkit-box;
  253. -webkit-line-clamp: 3;
  254. -webkit-box-orient: vertical;
  255. }
  256. .attentionSituation {
  257. font-size: 24rpx;
  258. display: flex;
  259. align-items: center;
  260. .collectCount,
  261. .commentCount {
  262. display: flex;
  263. align-items: center;
  264. }
  265. .custom-icon {
  266. margin-right: 10rpx;
  267. &::before {
  268. background: -webkit-linear-gradient(left, #f84a1a, #ffa53e);
  269. -webkit-background-clip: text;
  270. -webkit-text-fill-color: transparent;
  271. font-weight: bold;
  272. }
  273. }
  274. .collectCount {
  275. margin-right: 30rpx;
  276. }
  277. .time {
  278. color: #aaa;
  279. }
  280. }
  281. image {
  282. flex: 1;
  283. width: 100%;
  284. height: 100%;
  285. border-radius: 20rpx;
  286. }
  287. .rightBox {
  288. width: 100%;
  289. height: 100%;
  290. // background-color: yellow;
  291. image {
  292. width: 100%;
  293. height: 100%;
  294. }
  295. }
  296. }
  297. }
  298. </style>