修复培训数据多时不显示问题

main
lj7788 2025-12-19 11:06:15 +08:00
parent dd92c84a9e
commit 003715b55d
3 changed files with 68 additions and 18 deletions

View File

@ -15,12 +15,16 @@ Page({
initData: {}, initData: {},
show:false, show:false,
listData:[], listData:[],
displayListData: [], // 用于显示的数据
trainType:"", trainType:"",
title:"", title:"",
minTitle:"", minTitle:"",
request:app.globalData.reqUrl request:app.globalData.reqUrl,
currentPage: 1, // 当前页码
pageSize: 20, // 每页显示条数
totalPage: 0, // 总页数
isLoading: false // 是否正在加载
}, },
onClose(){ onClose(){
this.setData({ show: false }); this.setData({ show: false });
}, },
@ -95,13 +99,20 @@ Page({
}, },
method: "get", method: "get",
success: function (res) { success: function (res) {
// 计算总页数
const total = res.data.data.length;
const pageSize = that.data.pageSize;
const totalPage = Math.ceil(total / pageSize);
that.setData({ that.setData({
listData:res.data.data listData: res.data.data,
totalPage: totalPage,
displayListData: res.data.data.slice(0, pageSize),
currentPage: 1
}) })
} }
}) })
}, },
returnToPage: function () { returnToPage: function () {
/*关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面*/ /*关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面*/
if(wx.getStorageSync('nav-menu')=="gd"){ if(wx.getStorageSync('nav-menu')=="gd"){
@ -156,16 +167,49 @@ Page({
* 页面相关事件处理函数--监听用户下拉动作 * 页面相关事件处理函数--监听用户下拉动作
*/ */
onPullDownRefresh() { onPullDownRefresh() {
// 下拉刷新,重新加载第一页数据
this.getListData(this.data.projectId, this.data.deptId, this.data.trainType);
wx.stopPullDownRefresh(); // 停止下拉刷新
}, },
/** /**
* 页面上拉触底事件的处理函数 * 页面上拉触底事件的处理函数
*/ */
onReachBottom() { onReachBottom() {
this.loadMoreData();
}, },
/**
* 加载更多数据
*/
loadMoreData() {
// 如果正在加载或已到最后一页,则不再加载
if (this.data.isLoading || this.data.currentPage >= this.data.totalPage) {
return;
}
this.setData({
isLoading: true
});
// 使用 setTimeout 模拟网络请求延迟
setTimeout(() => {
const nextPage = this.data.currentPage + 1;
const pageSize = this.data.pageSize;
const startIndex = (nextPage - 1) * pageSize;
const endIndex = Math.min(startIndex + pageSize, this.data.listData.length);
// 从完整数据中取出下一页的数据
const nextData = this.data.listData.slice(startIndex, endIndex);
const newData = [...this.data.displayListData, ...nextData];
this.setData({
displayListData: newData,
currentPage: nextPage,
isLoading: false
});
}, 300); // 减少模拟延迟时间
},
/** /**
* 用户点击右上角分享 * 用户点击右上角分享
*/ */

View File

@ -1,7 +1,10 @@
{ {
"usingComponents": { "usingComponents": {
"van-overlay": "@vant/weapp/overlay/index" , "van-overlay": "@vant/weapp/overlay/index" ,
"van-popup": "@vant/weapp/popup/index" "van-popup": "@vant/weapp/popup/index",
"van-loading": "@vant/weapp/loading/index"
}, },
"navigationStyle":"custom" "navigationStyle":"custom",
"enablePullDownRefresh": true,
"backgroundTextStyle": "dark"
} }

View File

@ -14,7 +14,7 @@
<project-select init="{{initData}}" bindchange="onProjectSelect"></project-select> <project-select init="{{initData}}" bindchange="onProjectSelect"></project-select>
<view class="inspect_max"> <view class="inspect_max">
<view class="inspect_list"> <view class="inspect_list">
<view class="inspect_for" wx:for="{{listData}}" wx:key="index" data-set="{{item}}" bindtap="getInfo"> <view class="inspect_for" wx:for="{{displayListData}}" wx:key="index" data-set="{{item}}" bindtap="getInfo">
<view class="inspect_for_bgd"> <view class="inspect_for_bgd">
<view class="inspect_list_title"> <view class="inspect_list_title">
<view class="inspect_list_title_label inspect_list_title_width"> <view class="inspect_list_title_label inspect_list_title_width">
@ -39,12 +39,22 @@
</view> </view>
</view> </view>
</view> </view>
<view wx:if="{{listData.length==0}}"> <view wx:if="{{displayListData.length==0}}">
<view style="padding-top: 70px;text-align: -webkit-center;"> <view style="padding-top: 70px;text-align: -webkit-center;">
<image src="https://szgcwx.jhncidg.com/staticFiles/nodata.png" style="width: 130px;height: 105px;"></image> <image src="https://szgcwx.jhncidg.com/staticFiles/nodata.png" style="width: 130px;height: 105px;"></image>
<view style="color: #a5abbb;">暂无数据</view> <view style="color: #a5abbb;">暂无数据</view>
</view> </view>
</view> </view>
<!-- 加载更多提示 -->
<view wx:if="{{isLoading}}" style="text-align: center; padding: 20rpx;">
<van-loading size="24px" vertical>加载中...</van-loading>
</view>
<view wx:elif="{{currentPage < totalPage && displayListData.length > 0}}" style="text-align: center; padding: 20rpx; color: #999;">
上拉加载更多
</view>
<view wx:elif="{{currentPage >= totalPage && displayListData.length > 0}}" style="text-align: center; padding: 20rpx; color: #999;">
没有更多数据了
</view>
</view> </view>
<view class="inspect_add_to" bindtap="skipAdd"> <view class="inspect_add_to" bindtap="skipAdd">
@ -53,10 +63,3 @@
<view>新增</view> <view>新增</view>
</view> </view>
</view></view> </view></view>