articleList.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <view>
  3. <scroll-view
  4. class="scroll-view"
  5. scroll-y="true"
  6. :style="{ height: scrollViewHeight + 'px' }"
  7. :refresher-enabled="true"
  8. :refresher-triggered="isRefreshing"
  9. @refresherrefresh="handleRefresh"
  10. @scrolltolower="loadMore">
  11. <u-empty v-if="listData.length === 0" text="当前暂无数据"></u-empty>
  12. <view v-for="item in listData" @click="navToDetail(item.id)" style="width: 90%;margin: 0rpx auto 40rpx auto;display: flex;flex-direction: column;">
  13. <image style="width: 100%;" mode="widthFix" src="/static/applicationList/picture1.png"></image>
  14. <view class="item-content">
  15. <view style="width: 98%;display: flex;flex-direction: row;align-items: center;">
  16. <text style="font-size: 30rpx;font-weight: bold;width: 100%;margin: 20rpx;">{{item.title}}</text>
  17. </view>
  18. <view style="width: 98%;display: flex;flex-direction: row;justify-content: flex-end;">
  19. <text style="font-size: 26rpx;color: #999;">{{item.createTime}}</text>
  20. </view>
  21. </view>
  22. </view>
  23. <!-- 加载状态提示 -->
  24. <view style="text-align: center;" v-if="isLoadingMore">正在加载更多数据...</view>
  25. <view style="text-align: center;" v-if="!hasNextPage&&listData.length>0">已无更多数据</view>
  26. <view style="height: 20rpx;"></view>
  27. </scroll-view>
  28. </view>
  29. </template>
  30. <script>
  31. export default {
  32. data() {
  33. return {
  34. listData:[],
  35. currentPage: 1, // 当前页码
  36. pageSize: 10, // 每页数据条数
  37. totalCount: 0, // 数据总数(可从后端获取)
  38. isLoadingMore: false, // 是否正在加载更多
  39. isRefreshing: false, // 是否正在下拉刷新
  40. hasNextPage: true, // 是否存在下一页
  41. scrollViewHeight: 0, // scroll-view动态高度
  42. parentId:null
  43. }
  44. },
  45. onLoad(e) {
  46. this.parentId = e.parentId
  47. this.fetchData(); // 初始加载数据
  48. },
  49. mounted() {
  50. this.calculateScrollViewHeight(); // 计算scroll-view可用高度
  51. },
  52. methods: {
  53. navToDetail(id){
  54. uni.navigateTo({
  55. url:'/pages/articleDetail/articleDetail?id='+id
  56. })
  57. console.log(id)
  58. },
  59. calculateScrollViewHeight() {
  60. const systemInfo = uni.getSystemInfoSync();
  61. // 假设顶部有导航栏(占50px),底部无其他固定元素
  62. this.scrollViewHeight = systemInfo.windowHeight;
  63. },
  64. // 模拟获取数据(在实际应用中替换为你的API请求)
  65. fetchData(pageNum = 1, pageSize = this.pageSize, isRefresh = false) {
  66. // 模拟网络请求延迟
  67. return this.$http.get('appraisal/articleContentInfo/list',{
  68. pageNum:pageNum,
  69. pageSize:pageSize,
  70. parentId:this.parentId
  71. }).then(res => {
  72. // 处理响应数据
  73. const newData = res.rows; // 根据你的接口结构调整
  74. // ...更新列表数据和状态...
  75. if (isRefresh) {
  76. this.listData = newData;
  77. } else {
  78. this.listData = [...this.listData, ...newData];
  79. }
  80. this.hasNextPage = pageNum < Math.ceil(res.total/this.pageSize); // 假设接口返回总页数
  81. }).catch(err => {
  82. // 错误处理
  83. console.error('请求失败:', err);
  84. uni.showToast({ title: '加载失败', icon: 'none' });
  85. });
  86. },
  87. // 处理下拉刷新
  88. handleRefresh() {
  89. if (this.isRefreshing) return;
  90. this.isRefreshing = true;
  91. this.currentPage = 1; // 重置页码
  92. this.hasNextPage = true; // 重置下一页状态
  93. this.fetchData(1, this.pageSize, true).finally(() => {
  94. this.isRefreshing = false;
  95. uni.stopPullDownRefresh(); // 如果需要调用API停止动画
  96. uni.showToast({ title: '刷新成功', icon: 'none' });
  97. });
  98. },
  99. // 处理上拉加载更多
  100. loadMore() {
  101. // 如果没有下一页数据,或正在加载中,则直接返回
  102. if (!this.hasNextPage || this.isLoadingMore || this.isRefreshing) return;
  103. this.isLoadingMore = true;
  104. this.currentPage += 1; // 页码增加
  105. this.fetchData(this.currentPage).finally(() => {
  106. this.isLoadingMore = false;
  107. });
  108. }
  109. }
  110. }
  111. </script>
  112. <style>
  113. .item-content{
  114. width: 100%;
  115. padding-bottom: 20rpx;
  116. background-color: #fff;
  117. border-right: 3rpx solid #000;
  118. border-bottom: 3rpx solid #000;
  119. border-left: 3rpx solid #000;
  120. background-image: url('https://www.nmglzrj.com/photo/dogManagementSystem/picture7.png');
  121. background-size: 895rpx 207rpx; /* 关键修改:保持图片比例并覆盖整个区域 */
  122. background-position: center; /* 确保背景图居中显示 */
  123. background-repeat: repeat; /* 防止图片重复 */
  124. border-bottom-left-radius: 40rpx;
  125. border-bottom-right-radius: 40rpx;
  126. box-sizing: border-box;
  127. display: flex;
  128. flex-direction: column;
  129. flex-wrap: wrap;
  130. justify-content: space-between;
  131. }
  132. .scroll-view{
  133. background-color: #fef7e5;
  134. }
  135. </style>