Commit 5c242a50 by xiexiaoqin

修复和优化首页点击回到今天,增加上拉加载条数至40

parent 53ee4609
......@@ -126,7 +126,7 @@
padding: 0 32rpx;
display: flex;
justify-content: space-between;
box-shadow: 0 1rpx 10rpx 2rpx rgba(0, 0, 0, 0.04);
box-shadow: 0 2rpx 10rpx 3rpx rgba(0, 0, 0, 0.04);
z-index: 9;
position: relative;
}
......
......@@ -13,8 +13,8 @@ import {
getCreateShowTime
} from "../../utils/utils";
const currentDate = new Date();
let minYear = 2020;
let maxYear = currentDate.getFullYear() + 1;
const minYear = 2020;
const maxYear = currentDate.getFullYear() + 1;
let DateMap = getDateMap(minYear, maxYear);
const weekList = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
import create from "dd-store";
......@@ -45,10 +45,14 @@ create.Page({
scheduleList: [],
timer: null,
isFirstLoad: true,
blankDataLength: 0,
blankDataLengthAfter: 0,
minYear: minYear,
maxYear: maxYear,
onShow() {
//如果是重复会议重新算
if (this.$store.data.indexNeedUpdate) {
DateMap = getDateMap(minYear, maxYear);
DateMap = getDateMap(this.minYear, this.maxYear);
this.onLoad();
}
//单次会议往DateMap中添加
......@@ -221,8 +225,11 @@ create.Page({
this.totalPages = Math.ceil(scheduleList.length / this.pageSize);
for (let i = 0; i < scheduleList.length; i++) {
if (scheduleList[i].dateStr == toLocaleDateString(currentDate)) {
this.firstPage = Math.floor(i / this.pageSize) - 2;
this.currentPage = Math.floor(i / this.pageSize) + 2;
const centerPage = Math.floor(i / this.pageSize);
// firstPage转为4的倍数,一次下拉加载40条
const firstPage = centerPage - 2;
this.firstPage = firstPage % 4 == 0 ? firstPage : firstPage - firstPage % 4;
this.currentPage = centerPage + 2;
break
}
}
......@@ -233,12 +240,6 @@ create.Page({
endTime: "2025-12-30 23:59:59"
}).then(res => {
this.getScheduleList(res.data.data);
// this.getPagination(this.scheduleList);
// 第一次加载
// this.setData({
// scheduleList: this.scheduleList.slice(this.firstPage * this.pageSize, this.currentPage * this.pageSize),
// loading: false
// });
});
},
//生成DateMap值
......@@ -445,8 +446,10 @@ create.Page({
});
} else {
//超出加载一年的数据
maxYear++;
this.scheduleList.push(...getBlankList(maxYear));
this.maxYear++;
const yearData = getBlankList(this.maxYear);
this.blankDataLengthAfter += yearData.length;
this.scheduleList.push(...yearData);
this.setData({
scheduleList: this.scheduleList.slice(this.firstPage * this.pageSize)
})
......@@ -465,20 +468,21 @@ create.Page({
}
// const todayStr = this.data.scheduleList[0].dateStr;
if (this.firstPage > 0) {
this.firstPage--;
this.currentPage--;
this.firstPage -= 4;
this.currentPage -= 4;
this.setData({
todayStr: '',
scheduleList: this.scheduleList.slice(this.firstPage * this.pageSize, this.currentPage * this.pageSize)
}, () => {
this.setData({
todayStr: this.data.scheduleList[this.pageSize - 1].dateStr
todayStr: this.data.scheduleList[this.pageSize * 4 - 1].dateStr
});
dd.stopPullDownRefresh();
});
} else {
minYear--;
const yearData = getBlankList(minYear);
this.minYear--;
const yearData = getBlankList(this.minYear);
this.blankDataLength += yearData.length;
this.scheduleList.unshift(...yearData);
this.totalPages = Math.ceil(this.scheduleList.length / this.pageSize);
this.currentPage = Math.floor(yearData.length * 2 / this.pageSize);
......@@ -627,7 +631,28 @@ create.Page({
)}`
});
}, 1000),
backToToday() {
backToToday(type) {
if (!type) {
//如果当前的日期还没加载出来点击无效,下拉积累数据过长可以去掉
const isFindArr = this.data.scheduleList.filter(it => it.dateStr == toLocaleDateString(currentDate));
if (isFindArr.length == 0 || this.data.scheduleList.length > 100) {
//去掉头部空数据
if (this.minYear < minYear) {
this.scheduleList.splice(0, this.blankDataLength);
this.minYear = minYear;
}
//去掉尾部数据
if (this.maxYear > maxYear) {
this.scheduleList.splice(-this.blankDataLengthAfter);
this.maxYear = maxYear;
}
this.getPagination(this.scheduleList);
this.setData({
scheduleList: this.scheduleList.slice(this.firstPage * this.pageSize, this.currentPage * this.pageSize)
});
}
}
//需要先清空todayStr再设置才有效
this.setData(
{
......@@ -654,7 +679,7 @@ create.Page({
this.backToToday();
}
if (this.isFirstLoad) {
this.backToToday();
this.backToToday('first');
this.isFirstLoad = false;
this.resetToview = true;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment