Commit 5c242a50 by xiexiaoqin

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

parent 53ee4609
...@@ -126,7 +126,7 @@ ...@@ -126,7 +126,7 @@
padding: 0 32rpx; padding: 0 32rpx;
display: flex; display: flex;
justify-content: space-between; 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; z-index: 9;
position: relative; position: relative;
} }
......
...@@ -13,8 +13,8 @@ import { ...@@ -13,8 +13,8 @@ import {
getCreateShowTime getCreateShowTime
} from "../../utils/utils"; } from "../../utils/utils";
const currentDate = new Date(); const currentDate = new Date();
let minYear = 2020; const minYear = 2020;
let maxYear = currentDate.getFullYear() + 1; const maxYear = currentDate.getFullYear() + 1;
let DateMap = getDateMap(minYear, maxYear); let DateMap = getDateMap(minYear, maxYear);
const weekList = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"]; const weekList = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
import create from "dd-store"; import create from "dd-store";
...@@ -45,10 +45,14 @@ create.Page({ ...@@ -45,10 +45,14 @@ create.Page({
scheduleList: [], scheduleList: [],
timer: null, timer: null,
isFirstLoad: true, isFirstLoad: true,
blankDataLength: 0,
blankDataLengthAfter: 0,
minYear: minYear,
maxYear: maxYear,
onShow() { onShow() {
//如果是重复会议重新算 //如果是重复会议重新算
if (this.$store.data.indexNeedUpdate) { if (this.$store.data.indexNeedUpdate) {
DateMap = getDateMap(minYear, maxYear); DateMap = getDateMap(this.minYear, this.maxYear);
this.onLoad(); this.onLoad();
} }
//单次会议往DateMap中添加 //单次会议往DateMap中添加
...@@ -221,8 +225,11 @@ create.Page({ ...@@ -221,8 +225,11 @@ create.Page({
this.totalPages = Math.ceil(scheduleList.length / this.pageSize); this.totalPages = Math.ceil(scheduleList.length / this.pageSize);
for (let i = 0; i < scheduleList.length; i++) { for (let i = 0; i < scheduleList.length; i++) {
if (scheduleList[i].dateStr == toLocaleDateString(currentDate)) { if (scheduleList[i].dateStr == toLocaleDateString(currentDate)) {
this.firstPage = Math.floor(i / this.pageSize) - 2; const centerPage = Math.floor(i / this.pageSize);
this.currentPage = Math.floor(i / this.pageSize) + 2; // firstPage转为4的倍数,一次下拉加载40条
const firstPage = centerPage - 2;
this.firstPage = firstPage % 4 == 0 ? firstPage : firstPage - firstPage % 4;
this.currentPage = centerPage + 2;
break break
} }
} }
...@@ -233,12 +240,6 @@ create.Page({ ...@@ -233,12 +240,6 @@ create.Page({
endTime: "2025-12-30 23:59:59" endTime: "2025-12-30 23:59:59"
}).then(res => { }).then(res => {
this.getScheduleList(res.data.data); 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值 //生成DateMap值
...@@ -445,8 +446,10 @@ create.Page({ ...@@ -445,8 +446,10 @@ create.Page({
}); });
} else { } else {
//超出加载一年的数据 //超出加载一年的数据
maxYear++; this.maxYear++;
this.scheduleList.push(...getBlankList(maxYear)); const yearData = getBlankList(this.maxYear);
this.blankDataLengthAfter += yearData.length;
this.scheduleList.push(...yearData);
this.setData({ this.setData({
scheduleList: this.scheduleList.slice(this.firstPage * this.pageSize) scheduleList: this.scheduleList.slice(this.firstPage * this.pageSize)
}) })
...@@ -465,20 +468,21 @@ create.Page({ ...@@ -465,20 +468,21 @@ create.Page({
} }
// const todayStr = this.data.scheduleList[0].dateStr; // const todayStr = this.data.scheduleList[0].dateStr;
if (this.firstPage > 0) { if (this.firstPage > 0) {
this.firstPage--; this.firstPage -= 4;
this.currentPage--; this.currentPage -= 4;
this.setData({ this.setData({
todayStr: '', todayStr: '',
scheduleList: this.scheduleList.slice(this.firstPage * this.pageSize, this.currentPage * this.pageSize) scheduleList: this.scheduleList.slice(this.firstPage * this.pageSize, this.currentPage * this.pageSize)
}, () => { }, () => {
this.setData({ this.setData({
todayStr: this.data.scheduleList[this.pageSize - 1].dateStr todayStr: this.data.scheduleList[this.pageSize * 4 - 1].dateStr
}); });
dd.stopPullDownRefresh(); dd.stopPullDownRefresh();
}); });
} else { } else {
minYear--; this.minYear--;
const yearData = getBlankList(minYear); const yearData = getBlankList(this.minYear);
this.blankDataLength += yearData.length;
this.scheduleList.unshift(...yearData); this.scheduleList.unshift(...yearData);
this.totalPages = Math.ceil(this.scheduleList.length / this.pageSize); this.totalPages = Math.ceil(this.scheduleList.length / this.pageSize);
this.currentPage = Math.floor(yearData.length * 2 / this.pageSize); this.currentPage = Math.floor(yearData.length * 2 / this.pageSize);
...@@ -627,7 +631,28 @@ create.Page({ ...@@ -627,7 +631,28 @@ create.Page({
)}` )}`
}); });
}, 1000), }, 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再设置才有效 //需要先清空todayStr再设置才有效
this.setData( this.setData(
{ {
...@@ -654,7 +679,7 @@ create.Page({ ...@@ -654,7 +679,7 @@ create.Page({
this.backToToday(); this.backToToday();
} }
if (this.isFirstLoad) { if (this.isFirstLoad) {
this.backToToday(); this.backToToday('first');
this.isFirstLoad = false; this.isFirstLoad = false;
this.resetToview = true; 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