index1.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <template>
  2. <view class="infoBox">
  3. <!-- :style="{top: `${statusBarHeight}px`}" -->
  4. <view class="headerBox">
  5. <view :style="{height: statusBarHeight + 'px'}"></view>
  6. <!-- 头部 -->
  7. <Header />
  8. <!-- 搜索框 -->
  9. <Search />
  10. <!-- 头部导航 -- tab标签 -->
  11. <MenuTab :typeList="typeList" @changeTab="handleSelectTab" />
  12. </view>
  13. <!-- 内容列表 -->
  14. <view class="content" :style="{marginTop:(statusBarHeight*2+100+88+40+80)+'rpx'}">
  15. <!-- 主资讯 -->
  16. <view class="firstInfo" @click="goDetail" v-if="mainInfo && mainInfo.id">
  17. <!-- <image src="@/static/2.jpg" alt=""></image> -->
  18. <!-- <image :src="getUrl(mainInfo.banner)" alt=""></image> -->
  19. <view class="left">
  20. <view class="time">
  21. {{mainInfo.updateTime ? parseTime(mainInfo.updateTime, '{y}/{m}/{d}'): ''}}
  22. </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. <template v-for="(item, index) in infoList">
  31. <view class="info" :key="index" @click="goDetail(item)">
  32. <view class="leftBox">
  33. <view class="title">
  34. {{item.title}}
  35. </view>
  36. <view class="attentionSituation">
  37. <view class="collectCount">
  38. <i class="custom-icon custom-icon-collected"></i>
  39. 2145
  40. </view>
  41. <!-- <view class="commentCount">
  42. <i class="custom-icon custom-icon-comment"></i>
  43. 543
  44. </view> -->
  45. <view class="time">
  46. {{item.updateTime ? formatDate(Date.parse(item.updateTime)): ""}}
  47. </view>
  48. </view>
  49. </view>
  50. <image :src="getUrl(item.banner)" alt="图片走丢啦" />
  51. </view>
  52. </template>
  53. <!-- 上拉Loading -->
  54. <u-loadmore :status="loadingStatus" marginTop="50px" loadmoreText="没有更多了" line />
  55. <!-- 上拉Loading -->
  56. </view>
  57. <!-- 底部导航 -->
  58. <Tabbar :current-page="0" />
  59. </view>
  60. </template>
  61. <script>
  62. import Header from "@/components/Header/index.vue";
  63. import Search from "@/components/Search/index.vue";
  64. import MenuTab from "@/components/MenuTab/index.vue";
  65. import Tabbar from "@/components/Tabbar/index.vue";
  66. import {
  67. getInfoList,
  68. getInfoType
  69. } from '@/api/info.js'
  70. import {
  71. baseUrl
  72. } from "@/utils/apiconfig.js";
  73. import {
  74. parseTime,
  75. formatDate
  76. } from '@/utils/util.js'
  77. export default {
  78. components: {
  79. Header,
  80. Search,
  81. MenuTab,
  82. Tabbar
  83. },
  84. data() {
  85. return {
  86. typeList: [], // 分类
  87. mainInfo: {}, // 主资讯(资讯列表的第一条数据)
  88. infoList: [], // 资讯列表(除资讯列表第一条数据的)
  89. total: 0, // 数据总量
  90. infoParams: {
  91. pageNum: 1,
  92. pageSize: 10,
  93. checkStatus: '5', // 已发布的数据
  94. categoryId: '', // 分类
  95. },
  96. statusBarHeight: getApp().globalData.statusBarHeight,
  97. loadingStatus: 'loadmore',
  98. isRequesting: false, // 是否正在请求,如果是则返回,用于节流
  99. }
  100. },
  101. onLoad() {
  102. this.getType();
  103. this.getList();
  104. },
  105. // 监控上拉默认距离底部50px触发
  106. onReachBottom() {
  107. console.log('触发底部啦')
  108. // 判断一下是否已经请求完所有数据,是的话return 不继续请求了
  109. if (this.loadingStatus === 'nomore') return
  110. if (this.isRequesting) return
  111. this.infoParams.pageNum += 1
  112. this.getList()
  113. },
  114. onPullDownRefresh(){
  115. console.log('下拉刷新啦')
  116. this.infoParams.pageNum = 1
  117. this.getList()
  118. },
  119. // 监控滚动(可用于判断是否展示返回顶部)
  120. // onPageScroll(e) {
  121. // },
  122. methods: {
  123. parseTime,
  124. formatDate,
  125. // 获取图片完整地址
  126. getUrl(url) {
  127. return baseUrl + url
  128. },
  129. // 获取资讯分类
  130. getType() {
  131. let params = {
  132. status: '0',
  133. pageNum: 1,
  134. pageSize: 9999,
  135. }
  136. getInfoType(params).then(res => {
  137. console.log(res)
  138. let obj = {
  139. id: -1,
  140. name: '全部'
  141. }
  142. this.typeList = [obj, ...res.rows]
  143. })
  144. },
  145. // 获取资讯列表
  146. getList() {
  147. this.isRequesting = true
  148. getInfoList(this.infoParams).then(res => {
  149. // console.log("res:", res)
  150. // this.infoList = [...this.infoList, ...res.rows]
  151. // 如果是第一页的数据,需要将第一条数据单独拿出来
  152. if (this.infoParams.pageNum === 1) {
  153. console.log('触发第一页的数据啦')
  154. this.mainInfo = res.rows[0]
  155. this.infoList = res.rows.filter((item, index) => index !== 0)
  156. } else {
  157. console.log('触发其余页码的数据啦')
  158. this.infoList = [...this.infoList, ...res.rows]
  159. }
  160. // console.log('infoList', this.infoList)
  161. this.total = res.total - 1
  162. this.loadingStatus = this.infoList.length >= this.total - 1 ? 'nomore' : 'loading'
  163. }).finally(() => this.isRequesting = false)
  164. },
  165. // 切换tab
  166. handleSelectTab(val) {
  167. // 切换tab时页面要回到顶部
  168. uni.pageScrollTo({
  169. scrollTop: 0,
  170. duration: 0, // 直接跳转到顶部,不需要动画
  171. })
  172. this.infoParams = {
  173. ...this.infoParams,
  174. pageNum: 1,
  175. categoryId: val.id === -1 ? '' : val.id,
  176. }
  177. this.getList()
  178. },
  179. // 点击资讯跳转详情
  180. goDetail(val) {
  181. console.log('跳转')
  182. uni.setStorageSync('infoDetail', val)
  183. uni.navigateTo({
  184. url: '/pages/index/detail'
  185. });
  186. },
  187. }
  188. }
  189. </script>
  190. <style lang="scss">
  191. page {
  192. background-color: #f9f9f9;
  193. font-size: 28rpx;
  194. height: 100%;
  195. // background-color: yellow;
  196. }
  197. .infoBox {
  198. height: 100%;
  199. padding-top: 1px;
  200. // position: relative;
  201. // background-color: red;
  202. .headerBox {
  203. width: 100%;
  204. background-color: #f9f9f9;
  205. position: fixed;
  206. top: 0;
  207. z-index: 20;
  208. }
  209. .Search {
  210. margin: 20rpx 0;
  211. // position: sticky;
  212. // top: 50;
  213. }
  214. .content {
  215. width: 100%;
  216. // height: calc(100% - 100rpx - (88rpx + 40rpx) - 80rpx);
  217. // background-color: yellow;
  218. .u-loadmore {
  219. padding-bottom: 200rpx;
  220. }
  221. }
  222. .firstInfo {
  223. margin: 20rpx auto;
  224. width: 90%;
  225. height: 320rpx;
  226. // background-image: url(../../static/2.jpg);
  227. // background-repeat: no-repeat;
  228. // background-size: 100% 100%;
  229. // border-radius: 30rpx;
  230. // background-color: red;
  231. display: flex;
  232. justify-content: space-between;
  233. padding: 40rpx;
  234. // color: #fff;
  235. color: #000;
  236. font-size: 32rpx;
  237. position: relative;
  238. z-index: 0;
  239. image {
  240. position: absolute;
  241. top: 0;
  242. left: 0;
  243. width: 100%;
  244. height: 320rpx;
  245. border-radius: 30rpx;
  246. z-index: -1;
  247. }
  248. .time {
  249. opacity: 0.8;
  250. font-size: 24rpx;
  251. }
  252. .title {
  253. margin: 10rpx 0;
  254. }
  255. .custom-icon-collect {
  256. font-size: 40rpx;
  257. }
  258. }
  259. .info {
  260. width: 90%;
  261. background-color: #fff;
  262. display: flex;
  263. padding: 20rpx;
  264. height: 260rpx;
  265. margin: 10rpx auto;
  266. border-radius: 24rpx;
  267. box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.2);
  268. .leftBox {
  269. width: 66%;
  270. display: flex;
  271. flex-direction: column;
  272. justify-content: space-between;
  273. }
  274. .title {
  275. overflow: hidden;
  276. text-overflow: ellipsis;
  277. display: -webkit-box;
  278. -webkit-line-clamp: 3;
  279. -webkit-box-orient: vertical;
  280. }
  281. .attentionSituation {
  282. font-size: 24rpx;
  283. display: flex;
  284. align-items: center;
  285. .collectCount,
  286. .commentCount {
  287. display: flex;
  288. align-items: center;
  289. }
  290. .custom-icon {
  291. margin-right: 10rpx;
  292. &::before {
  293. background: -webkit-linear-gradient(left, #f84a1a, #ffa53e);
  294. -webkit-background-clip: text;
  295. -webkit-text-fill-color: transparent;
  296. font-weight: bold;
  297. }
  298. }
  299. .collectCount {
  300. margin-right: 30rpx;
  301. }
  302. .time {
  303. color: #aaa;
  304. }
  305. }
  306. image {
  307. flex: 1;
  308. width: 100%;
  309. height: 100%;
  310. border-radius: 20rpx;
  311. }
  312. .rightBox {
  313. width: 100%;
  314. height: 100%;
  315. // background-color: yellow;
  316. image {
  317. width: 100%;
  318. height: 100%;
  319. }
  320. }
  321. }
  322. }
  323. </style>