dietaryNutritionTips8 改为本地缓存数据
This commit is contained in:
@@ -66,7 +66,6 @@
|
||||
|
||||
<script>
|
||||
import { httpRequest } from "@/XMLHttpRequest";
|
||||
import { getCurrentDate } from "@/utils/times";
|
||||
|
||||
export default {
|
||||
name: "dietaryNutritionTips",
|
||||
@@ -79,8 +78,7 @@ export default {
|
||||
url: "api.cqygjk.com",
|
||||
suffix: "",
|
||||
urlPrefix: "/health-intervene/api/anon",
|
||||
orgCode: "",
|
||||
pageSize: 0
|
||||
orgCode: ""
|
||||
},
|
||||
},
|
||||
|
||||
@@ -110,12 +108,42 @@ export default {
|
||||
if (code) {
|
||||
this.rankingConfig.requestConfig.orgCode = Array.isArray(code) ? code[0] : code;
|
||||
}
|
||||
this.loadDataUrl();
|
||||
this.load();
|
||||
this.dailyTaskScheduler();
|
||||
},
|
||||
beforeDestroy() {
|
||||
this.stopAllLoops();
|
||||
},
|
||||
methods: {
|
||||
dailyTaskScheduler() {
|
||||
const weekDays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
|
||||
|
||||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
const month = (now.getMonth() + 1).toString().padStart(2, "0");
|
||||
const day = (now.getDate()).toString().padStart(2, "0");
|
||||
const week = now.getDay();
|
||||
const hours = now.getHours();
|
||||
const minutes = now.getMinutes();
|
||||
const seconds = now.getSeconds();
|
||||
this.dataConfig.currentDate = year + "年" + month + "月" + day + "日 " + weekDays[week];
|
||||
|
||||
this.dataConfig.doingDay = this.daysSinceDate("2025-05-07");
|
||||
this.dataConfig.startDay = "2025年5月7日";
|
||||
|
||||
if (hours === 23 && minutes === 59 && seconds === 50) {
|
||||
sessionStorage.removeItem('staff');
|
||||
sessionStorage.removeItem('department');
|
||||
}
|
||||
|
||||
if (hours === 0 && minutes === 0 && seconds === 10) {
|
||||
this.load();
|
||||
}
|
||||
|
||||
setTimeout(this.dailyTaskScheduler, 1000);
|
||||
},
|
||||
|
||||
|
||||
stopAllLoops() {
|
||||
if (this.scrollConfig.scrollAnimationFrameId) {
|
||||
cancelAnimationFrame(this.scrollConfig.scrollAnimationFrameId);
|
||||
@@ -138,25 +166,37 @@ export default {
|
||||
})
|
||||
},
|
||||
|
||||
load() {
|
||||
let _this = this;
|
||||
_this.rankingConfig.personnelType = _this.rankingConfig.personnelType === "staff" ? "department" : "staff";
|
||||
let data = sessionStorage.getItem(_this.rankingConfig.personnelType) || null;
|
||||
if(data) {
|
||||
let dataLength = JSON.parse(data);
|
||||
if(dataLength && dataLength.length) {
|
||||
_this.dataConfig.personnelType = _this.rankingConfig.personnelType;
|
||||
_this.dataConfig.list = JSON.parse(data);
|
||||
_this.$nextTick(() => {
|
||||
_this.startOneTimeScroll();
|
||||
});
|
||||
} else {
|
||||
_this.loadDataUrl();
|
||||
}
|
||||
} else {
|
||||
_this.loadDataUrl();
|
||||
}
|
||||
},
|
||||
|
||||
loadDataUrl() {
|
||||
let _this = this;
|
||||
_this.stopAllLoops(); // 在请求数据前,停止所有正在进行的循环
|
||||
|
||||
_this.dataConfig.currentDate = getCurrentDate();
|
||||
_this.rankingConfig.personnelType = _this.rankingConfig.personnelType === "staff" ? "department" : "staff";
|
||||
_this.rankingConfig.requestConfig.pageSize = _this.rankingConfig.personnelType === "staff" ? 50 : 100;
|
||||
|
||||
let serve = _this.rankingConfig.requestConfig.agreement + "://" + _this.rankingConfig.requestConfig.url;
|
||||
let url = serve + _this.rankingConfig.requestConfig.suffix + _this.rankingConfig.requestConfig.urlPrefix + (_this.rankingConfig.personnelType === "staff" ? "/userRank" : "/deptRank");
|
||||
let serve = _this.rankingConfig.requestConfig.agreement + "://" + _this.rankingConfig.requestConfig.url + _this.rankingConfig.requestConfig.suffix + _this.rankingConfig.requestConfig.urlPrefix;
|
||||
let url = serve + (_this.rankingConfig.personnelType === "staff" ? "/userRank" : "/deptRank") + "?pageNo=1&pageSize=" + (_this.rankingConfig.personnelType === "staff" ? "50" : "100") + "&orgCode=";
|
||||
Promise.all([
|
||||
_this.orgCodeRequest(url + "?orgCode=A01A86&pageNo=1&pageSize=" + _this.rankingConfig.requestConfig.pageSize),
|
||||
_this.orgCodeRequest(url + "?orgCode=A01A37&pageNo=1&pageSize=" + _this.rankingConfig.requestConfig.pageSize),
|
||||
_this.orgCodeRequest(url + "A01A86"),
|
||||
_this.orgCodeRequest(url + "A01A37"),
|
||||
]).then((res) => {
|
||||
_this.dataConfig.list = [];
|
||||
_this.dataConfig.doingDay = _this.daysSinceDate("2025-05-07");
|
||||
_this.dataConfig.startDay = "2025年5月7日";
|
||||
_this.dataConfig.personnelType = _this.rankingConfig.personnelType;
|
||||
let data = _this.combineAndSortAndTakeTop50(res[0], res[1], _this.dataConfig.personnelType);
|
||||
sessionStorage.setItem(_this.rankingConfig.personnelType, JSON.stringify(data));
|
||||
if (data && data.length) {
|
||||
_this.dataConfig.list = data;
|
||||
_this.$nextTick(() => {
|
||||
@@ -166,7 +206,6 @@ export default {
|
||||
_this.startBannerLoop();
|
||||
}
|
||||
}).catch((error) => {
|
||||
console.error("请求失败:", error);
|
||||
_this.dataConfig.list = [];
|
||||
_this.startBannerLoop();
|
||||
})
|
||||
@@ -249,7 +288,7 @@ export default {
|
||||
}
|
||||
});
|
||||
|
||||
const top50Array = processedArraySortMap.slice(0, this.rankingConfig.requestConfig.pageSize);
|
||||
const top50Array = processedArraySortMap.slice(0, 50);
|
||||
return top50Array;
|
||||
},
|
||||
|
||||
@@ -284,7 +323,7 @@ export default {
|
||||
console.log(`列表滚动完成,等待 ${this.scrollConfig.dynamicScrollWaitTime} 秒并请求下一批数据`);
|
||||
this.scrollConfig.scrollAnimationFrameId = null;
|
||||
this.rankingConfig.setTimeOutFun = setTimeout(() => {
|
||||
this.loadDataUrl();
|
||||
this.load();
|
||||
}, this.scrollConfig.dynamicScrollWaitTime * 1000);
|
||||
}
|
||||
};
|
||||
@@ -295,7 +334,7 @@ export default {
|
||||
startBannerLoop() {
|
||||
setTimeout(() => {
|
||||
this.stopAllLoops();
|
||||
this.loadDataUrl();
|
||||
this.load();
|
||||
}, 5000)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user