dietaryNutritionTips8 dietaryNutritionTips9
This commit is contained in:
@@ -67,6 +67,24 @@ const routes = [
|
||||
},
|
||||
component: () => import('@/views/dietaryNutritionTips/dietaryNutritionTips7.vue')
|
||||
},
|
||||
{
|
||||
path: '/dietaryNutritionTips8',
|
||||
name: 'dietaryNutritionTips8',
|
||||
meta: {
|
||||
title: '膳食营养温馨提示',
|
||||
rootValue: 108
|
||||
},
|
||||
component: () => import('@/views/dietaryNutritionTips/dietaryNutritionTips8.vue')
|
||||
},
|
||||
{
|
||||
path: '/dietaryNutritionTips9',
|
||||
name: 'dietaryNutritionTips9',
|
||||
meta: {
|
||||
title: '膳食营养温馨提示',
|
||||
rootValue: 108
|
||||
},
|
||||
component: () => import('@/views/dietaryNutritionTips/dietaryNutritionTips9.vue')
|
||||
},
|
||||
{
|
||||
path: '/dataBoard',
|
||||
name: 'dataBoard',
|
||||
|
||||
@@ -0,0 +1,589 @@
|
||||
<template>
|
||||
<div id="dietaryNutritionTips">
|
||||
<div class="tips">
|
||||
<div></div>
|
||||
<div>温馨提示</div>
|
||||
<div></div>
|
||||
</div>
|
||||
|
||||
<div class="title">
|
||||
<div></div>
|
||||
<div>
|
||||
<div>体重管理行动({{dataConfig.personnelType === 'staff' ? '员工' : '部门'}})</div>
|
||||
<div>
|
||||
<div>{{ dataConfig.currentDate }}</div>
|
||||
<div>
|
||||
活动开始第<span>{{ dataConfig.doingDay }}</span>天
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div></div>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<div class="contentHeader">
|
||||
<div>序号</div>
|
||||
<div>单位(部门)</div>
|
||||
<template v-if="dataConfig.personnelType === 'staff'">
|
||||
<div class="staff-userName">姓名</div>
|
||||
<div class="staff-fraction">体重管理得分</div>
|
||||
</template>
|
||||
<template v-if="dataConfig.personnelType === 'department'">
|
||||
<div class="department-avgFraction">人均体重管理得分</div>
|
||||
</template>
|
||||
</div>
|
||||
<div class="contentBody" ref="scrollContentBody">
|
||||
<template v-if="dataConfig.list && dataConfig.list.length">
|
||||
<div class="contentBodyList" v-for="(item, index) in dataConfig.list" :key="index">
|
||||
<template v-if="dataConfig.personnelType === 'staff'">
|
||||
<div>{{ item.rank }}</div>
|
||||
<div>{{ item.departName }}</div>
|
||||
<div class="staff-userName">{{ item.realName }}</div>
|
||||
<div class="staff-fraction">{{ item.value }}</div>
|
||||
</template>
|
||||
<template v-if="dataConfig.personnelType === 'department'">
|
||||
<div>{{ item.rank }}</div>
|
||||
<div>{{ item.orgName }}</div>
|
||||
<div class="department-avgFraction">{{ item.value }}</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="nullData">
|
||||
<div></div>
|
||||
<div>~ 暂无体重管理信息 ~</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
<div>公共事务中心 宣</div>
|
||||
<div>开始时间:{{ dataConfig.startDay }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { httpRequest } from "@/XMLHttpRequest";
|
||||
import { getCurrentDate } from "@/utils/times";
|
||||
|
||||
export default {
|
||||
name: "dietaryNutritionTips",
|
||||
data() {
|
||||
return {
|
||||
rankingConfig: {
|
||||
personnelType: "department", // 员工:staff / 部门:department
|
||||
requestConfig: {
|
||||
agreement: "https",
|
||||
url: "api.cqygjk.com",
|
||||
suffix: "",
|
||||
urlPrefix: "/health-intervene/api/anon",
|
||||
orgCode: "",
|
||||
pageSize: 0
|
||||
},
|
||||
},
|
||||
|
||||
dataConfig: {
|
||||
personnelType: "department", // 员工:staff / 部门:department
|
||||
currentDate: "",
|
||||
doingDay: "",
|
||||
list: [],
|
||||
startDay: "-",
|
||||
},
|
||||
|
||||
scrollConfig: {
|
||||
scrollAnimationFrameId: null, // 用于存储 requestAnimationFrame 的 ID
|
||||
scrollSpeed: 2, // 滚动速度,每帧移动的像素数
|
||||
// 这里的 scrollWaitTime 将在 startOneTimeScroll 中动态决定
|
||||
// 1秒用于有数据且能滚动,5秒用于无数据或数据不足以滚动
|
||||
dynamicScrollWaitTime: 1 // 动态等待时间,默认为1秒
|
||||
}
|
||||
};
|
||||
},
|
||||
created() {
|
||||
let url = this.$route.query.url;
|
||||
if (url) {
|
||||
this.rankingConfig.requestConfig.url = Array.isArray(url) ? url[0] : url;
|
||||
}
|
||||
let code = this.$route.query.orgCode;
|
||||
if (code) {
|
||||
this.rankingConfig.requestConfig.orgCode = Array.isArray(code) ? code[0] : code;
|
||||
}
|
||||
this.loadDataUrl();
|
||||
},
|
||||
beforeDestroy() {
|
||||
this.stopAllLoops();
|
||||
},
|
||||
methods: {
|
||||
stopAllLoops() {
|
||||
if (this.scrollConfig.scrollAnimationFrameId) {
|
||||
cancelAnimationFrame(this.scrollConfig.scrollAnimationFrameId);
|
||||
this.scrollConfig.scrollAnimationFrameId = null;
|
||||
}
|
||||
// 清除可能存在的 setTimeout,避免重复请求
|
||||
if (this.rankingConfig.setTimeOutFun) {
|
||||
clearTimeout(this.rankingConfig.setTimeOutFun);
|
||||
this.rankingConfig.setTimeOutFun = null;
|
||||
}
|
||||
},
|
||||
|
||||
orgCodeRequest(requestUrl) {
|
||||
return new Promise((resolve, reject) => {
|
||||
httpRequest("POST", requestUrl, {}, {}).then((res) => {
|
||||
resolve(res.result.rankList);
|
||||
}).catch(() => {
|
||||
reject();
|
||||
});
|
||||
})
|
||||
},
|
||||
|
||||
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");
|
||||
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),
|
||||
]).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);
|
||||
if (data && data.length) {
|
||||
_this.dataConfig.list = data;
|
||||
_this.$nextTick(() => {
|
||||
_this.startOneTimeScroll();
|
||||
});
|
||||
} else {
|
||||
_this.startBannerLoop();
|
||||
}
|
||||
}).catch((error) => {
|
||||
console.error("请求失败:", error);
|
||||
_this.dataConfig.list = [];
|
||||
_this.startBannerLoop();
|
||||
})
|
||||
},
|
||||
|
||||
daysSinceDate(targetDateString) {
|
||||
const targetDate = new Date(targetDateString);
|
||||
const currentDate = new Date(); // 当前日期
|
||||
|
||||
// 将日期部分归零,只比较天数差,避免时区和时间的影响
|
||||
targetDate.setHours(0, 0, 0, 0);
|
||||
currentDate.setHours(0, 0, 0, 0);
|
||||
|
||||
const differenceInTime = currentDate.getTime() - targetDate.getTime();
|
||||
const differenceInDays = differenceInTime / (1000 * 3600 * 24);
|
||||
|
||||
return Math.floor(differenceInDays); // 返回整数天数
|
||||
},
|
||||
|
||||
combineAndSortAndTakeTop50(arr1, arr2, personnelType) {
|
||||
const combinedArray = [...arr1, ...arr2];
|
||||
let processedArray = [];
|
||||
|
||||
if(personnelType === "department") {
|
||||
let filteredArray = combinedArray.filter(item => {
|
||||
const isExcluded = item.orgName === "" || item.orgName === null;
|
||||
return !isExcluded;
|
||||
});
|
||||
processedArray = filteredArray;
|
||||
}
|
||||
|
||||
if(personnelType === "staff") {
|
||||
const departmentsToReplace = [
|
||||
"综合管理部",
|
||||
"人力资源部",
|
||||
"计划财务部",
|
||||
"安全与设备管理部",
|
||||
"矿区建设中心",
|
||||
"物业后勤中心",
|
||||
"健康服务中心",
|
||||
"社会服务中心",
|
||||
"机关事务中心",
|
||||
"交通服务中心"
|
||||
];
|
||||
|
||||
let filteredArray = combinedArray.filter(item => {
|
||||
const isExcluded = item.departName === "部领导" || item.departName === "助理副总师";
|
||||
return !isExcluded;
|
||||
});
|
||||
|
||||
let filteredArrayMap = filteredArray.map(item => {
|
||||
if (departmentsToReplace.includes(item.departName)) {
|
||||
return { ...item, departName: "公共事务中心" };
|
||||
}
|
||||
return item;
|
||||
});
|
||||
|
||||
processedArray = filteredArrayMap;
|
||||
}
|
||||
|
||||
let processedArraySort = processedArray.sort((a, b) => {
|
||||
const valueA = parseFloat(a.value);
|
||||
const valueB = parseFloat(b.value);
|
||||
return valueB - valueA;
|
||||
});
|
||||
|
||||
let currentRank = 1;
|
||||
let previousValue = null;
|
||||
let processedArraySortMap = processedArraySort.map((item, index) => {
|
||||
const currentValue = parseFloat(item.value);
|
||||
if (index === 0) {
|
||||
previousValue = currentValue;
|
||||
return { ...item, rank: currentRank };
|
||||
} else {
|
||||
if (currentValue !== previousValue) {
|
||||
currentRank++;
|
||||
}
|
||||
previousValue = currentValue;
|
||||
return { ...item, rank: currentRank };
|
||||
}
|
||||
});
|
||||
|
||||
const top50Array = processedArraySortMap.slice(0, this.rankingConfig.requestConfig.pageSize);
|
||||
return top50Array;
|
||||
},
|
||||
|
||||
startOneTimeScroll() {
|
||||
const container = this.$refs.scrollContentBody;
|
||||
if (!container) return;
|
||||
|
||||
const maxScrollTop = container.scrollHeight - container.clientHeight;
|
||||
|
||||
// 根据是否可滚动来设置动态等待时间
|
||||
if (maxScrollTop <= 0) {
|
||||
console.log('内容不足以滚动,等待 5 秒并请求下一批数据');
|
||||
this.scrollConfig.dynamicScrollWaitTime = 5; // 设置为5秒
|
||||
} else {
|
||||
console.log('内容可滚动,等待 1 秒并请求下一批数据');
|
||||
this.scrollConfig.dynamicScrollWaitTime = 1; // 设置为1秒
|
||||
}
|
||||
|
||||
container.scrollTop = 0; // 确保每次开始都从顶部滚动
|
||||
let currentScrollTop = 0;
|
||||
|
||||
const animateScroll = () => {
|
||||
if (currentScrollTop < maxScrollTop) {
|
||||
currentScrollTop += this.scrollConfig.scrollSpeed;
|
||||
if (currentScrollTop > maxScrollTop) {
|
||||
currentScrollTop = maxScrollTop;
|
||||
}
|
||||
container.scrollTop = currentScrollTop;
|
||||
this.scrollConfig.scrollAnimationFrameId = requestAnimationFrame(animateScroll);
|
||||
} else {
|
||||
// 滚动完成后
|
||||
console.log(`列表滚动完成,等待 ${this.scrollConfig.dynamicScrollWaitTime} 秒并请求下一批数据`);
|
||||
this.scrollConfig.scrollAnimationFrameId = null;
|
||||
this.rankingConfig.setTimeOutFun = setTimeout(() => {
|
||||
this.loadDataUrl();
|
||||
}, this.scrollConfig.dynamicScrollWaitTime * 1000);
|
||||
}
|
||||
};
|
||||
|
||||
this.scrollConfig.scrollAnimationFrameId = requestAnimationFrame(animateScroll);
|
||||
},
|
||||
|
||||
startBannerLoop() {
|
||||
setTimeout(() => {
|
||||
this.stopAllLoops();
|
||||
this.loadDataUrl();
|
||||
}, 5000)
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
#dietaryNutritionTips {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 44px 40px 0;
|
||||
box-sizing: border-box;
|
||||
background-size: cover;
|
||||
background-repeat: no-repeat;
|
||||
background-position: center top;
|
||||
background-image: url("@/assets/images/dietaryNutritionTips/bg.png");
|
||||
|
||||
|
||||
.tips {
|
||||
width: 100%;
|
||||
height: 36px;
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 96px;
|
||||
|
||||
> div:nth-of-type(1) {
|
||||
width: 120px;
|
||||
height: 4px;
|
||||
background: linear-gradient(270deg, #ffc87c 0%, rgba(42, 199, 159, 0) 100%);
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
> div:nth-of-type(2) {
|
||||
color: #ffc87c;
|
||||
height: 36px;
|
||||
font-size: 36px;
|
||||
font-weight: bold;
|
||||
line-height: 36px;
|
||||
margin: 0 36px;
|
||||
}
|
||||
|
||||
> div:nth-of-type(3) {
|
||||
width: 120px;
|
||||
height: 4px;
|
||||
background: linear-gradient(90deg, #ffc87c 0%, rgba(42, 199, 159, 0) 100%);
|
||||
border-radius: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
.title {
|
||||
width: 100%;
|
||||
height: 182px;
|
||||
position: fixed;
|
||||
top: 85px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 3;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
> div:nth-of-type(1) {
|
||||
width: 86px;
|
||||
height: 182px;
|
||||
background-size: contain;
|
||||
background-repeat: no-repeat;
|
||||
background-position: center;
|
||||
background-image: url("@/assets/images/dietaryNutritionTips/l.png");
|
||||
}
|
||||
|
||||
> div:nth-of-type(2) {
|
||||
width: 720px;
|
||||
height: 136px;
|
||||
padding: 18px 30px 0;
|
||||
border-radius: 24px;
|
||||
box-sizing: border-box;
|
||||
background: linear-gradient(-90deg, #ffc77b 0%, #fff4e6 47%, #ffc879 100%);
|
||||
|
||||
> div:nth-of-type(1) {
|
||||
color: #8d0503;
|
||||
width: 100%;
|
||||
height: 48px;
|
||||
font-size: 48px;
|
||||
font-weight: bold;
|
||||
line-height: 48px;
|
||||
text-align: center;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
> div:nth-of-type(2) {
|
||||
width: 100%;
|
||||
height: 40px;
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
justify-content: space-between;
|
||||
align-items: flex-end;
|
||||
|
||||
> div:nth-of-type(1) {
|
||||
color: #8d0503;
|
||||
height: 32px;
|
||||
font-size: 30px;
|
||||
line-height: 32px;
|
||||
}
|
||||
|
||||
> div:nth-of-type(2) {
|
||||
color: #8d0503;
|
||||
height: 40px;
|
||||
font-size: 30px;
|
||||
line-height: 40px;
|
||||
|
||||
> span {
|
||||
margin: 0 6px;
|
||||
font-size: 40px;
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
> div:nth-of-type(3) {
|
||||
width: 86px;
|
||||
height: 182px;
|
||||
background-size: contain;
|
||||
background-repeat: no-repeat;
|
||||
background-position: center;
|
||||
background-image: url("@/assets/images/dietaryNutritionTips/r.png");
|
||||
}
|
||||
}
|
||||
|
||||
.content {
|
||||
width: 100%;
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
border-radius: 16px;
|
||||
padding: 105px 24px 0;
|
||||
box-sizing: border-box;
|
||||
border: 2px solid #ffc548;
|
||||
background: linear-gradient(
|
||||
180deg,
|
||||
rgba(225, 225, 225, 0) 0%,
|
||||
rgba(225, 225, 225, 0.3) 100%
|
||||
);
|
||||
|
||||
.contentHeader {
|
||||
width: 100%;
|
||||
height: 82px;
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
padding: 0 30px;
|
||||
box-sizing: border-box;
|
||||
margin-bottom: 40px;
|
||||
border-radius: 16px;
|
||||
background-color: #7e0b08;
|
||||
|
||||
> div {
|
||||
color: #ffc87c;
|
||||
height: 82px;
|
||||
font-size: 32px;
|
||||
font-weight: bold;
|
||||
line-height: 82px;
|
||||
text-align: center;
|
||||
|
||||
&:nth-of-type(1) {
|
||||
width: 85px;
|
||||
margin-right: 25px;
|
||||
}
|
||||
|
||||
&:nth-of-type(2) {
|
||||
flex: 1;
|
||||
width: 0;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
&.staff-userName {
|
||||
width: 120px;
|
||||
margin-right: 20px;
|
||||
}
|
||||
|
||||
&.staff-fraction {
|
||||
width: 250px;
|
||||
}
|
||||
|
||||
&.department-avgFraction {
|
||||
width: 350px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.contentBody {
|
||||
width: 100%;
|
||||
height: calc(100% - 152px); /* 减去 contentHeader 和其 margin-bottom 的高度 */
|
||||
overflow: hidden; /* 关键:隐藏溢出内容,实现滚动效果 */
|
||||
|
||||
.contentBodyList {
|
||||
width: 100%;
|
||||
height: 40px; /* 行高 */
|
||||
padding: 0 30px;
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
margin-bottom: 56px; /* 行间距 */
|
||||
|
||||
> div {
|
||||
color: #ffffff;
|
||||
height: 40px;
|
||||
font-size: 40px;
|
||||
line-height: 40px;
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
|
||||
&:nth-of-type(1) {
|
||||
width: 85px;
|
||||
margin-right: 25px;
|
||||
}
|
||||
|
||||
&:nth-of-type(2) {
|
||||
flex: 1;
|
||||
width: 0;
|
||||
text-align: left;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
&.staff-userName {
|
||||
width: 120px;
|
||||
margin-right: 20px;
|
||||
}
|
||||
|
||||
&.staff-fraction {
|
||||
width: 250px;
|
||||
}
|
||||
|
||||
&.department-avgFraction {
|
||||
width: 350px;
|
||||
}
|
||||
}
|
||||
|
||||
&:last-of-type {
|
||||
margin-bottom: 0 !important; /* 确保最后一行没有下边距,防止影响 totalHeight 计算 */
|
||||
}
|
||||
}
|
||||
|
||||
.nullData {
|
||||
width: 100%;
|
||||
padding-top: 350px;
|
||||
|
||||
> div:nth-of-type(1) {
|
||||
width: 280px;
|
||||
height: 232px;
|
||||
margin: 0 auto 40px;
|
||||
background-size: cover;
|
||||
background-repeat: no-repeat;
|
||||
background-position: center top;
|
||||
background-image: url("@/assets/images/dietaryNutritionTips/nullData.png");
|
||||
}
|
||||
|
||||
> div:nth-of-type(2) {
|
||||
color: #FFC87C;
|
||||
width: 100%;
|
||||
height: 40px;
|
||||
font-size: 40px;
|
||||
line-height: 40px;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.footer {
|
||||
width: 100%;
|
||||
height: 95px;
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
justify-content: space-between;
|
||||
|
||||
> div {
|
||||
color: #ffffff;
|
||||
height: 95px;
|
||||
font-size: 32px;
|
||||
font-weight: bold;
|
||||
line-height: 95px;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,541 @@
|
||||
<template>
|
||||
<div id="dietaryNutritionTips">
|
||||
<div class="tips">
|
||||
<div></div>
|
||||
<div>温馨提示</div>
|
||||
<div></div>
|
||||
</div>
|
||||
|
||||
<div class="title">
|
||||
<div></div>
|
||||
<div>
|
||||
<div>膳食营养行动({{dataConfig.personnelType === 'staff' ? '员工' : '部门'}})</div>
|
||||
<div>
|
||||
<div>{{ dataConfig.currentDate }}</div>
|
||||
<div>{{ dataConfig.dinnerType }}:{{ dataConfig.userNum }}人</div>
|
||||
</div>
|
||||
</div>
|
||||
<div></div>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<div class="contentHeader">
|
||||
<div>序号</div>
|
||||
<div>单位(部门)</div>
|
||||
<template v-if="dataConfig.personnelType === 'staff'">
|
||||
<div class="staff-userName">姓名</div>
|
||||
<div class="staff-fraction">膳食营养得分</div>
|
||||
</template>
|
||||
<template v-if="dataConfig.personnelType === 'department'">
|
||||
<div class="department-avgFraction">人均膳食营养得分</div>
|
||||
</template>
|
||||
</div>
|
||||
<div class="contentBody" ref="scrollContentBody">
|
||||
<template v-if="dataConfig.list && dataConfig.list.length">
|
||||
<div class="contentBodyList" v-for="(item, index) in dataConfig.list" :key="index">
|
||||
<template v-if="dataConfig.personnelType === 'staff'">
|
||||
<div>{{ index + 1 }}</div>
|
||||
<div>{{ item.departName }}</div>
|
||||
<div class="staff-userName">{{ maskUserName(item.userName) }}</div>
|
||||
<div class="staff-fraction">{{ item.fraction }}</div>
|
||||
</template>
|
||||
<template v-if="dataConfig.personnelType === 'department'">
|
||||
<div>{{ index + 1 }}</div>
|
||||
<div>{{ item.departName }}</div>
|
||||
<div class="department-avgFraction">{{ item.avgFraction }}</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="nullData">
|
||||
<div></div>
|
||||
<div>~ 暂无体重管理信息 ~</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
<div>公共事务中心 宣</div>
|
||||
<div>开始时间:{{ dataConfig.startDay }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { httpRequest } from "@/XMLHttpRequest";
|
||||
import { getCurrentDate } from "@/utils/times";
|
||||
import signMd5Utils from "@/utils/signMd5";
|
||||
|
||||
export default {
|
||||
name: "dietaryNutritionTips",
|
||||
data() {
|
||||
return {
|
||||
rankingConfig: {
|
||||
personnelType: "department", // 员工:staff / 部门:department
|
||||
requestConfig: {
|
||||
agreement: "https",
|
||||
url: "yyjk.cqygjk.com",
|
||||
suffix: "/gateway",
|
||||
urlPrefix: "/food/userRank",
|
||||
orgCode: "A01A86,A01A36",
|
||||
canteenId: "1599670511042785282,1746801170592919553",
|
||||
pageSize: 0
|
||||
},
|
||||
},
|
||||
|
||||
dataConfig: {
|
||||
personnelType: "department", // 员工:staff / 部门:department
|
||||
currentDate: "",
|
||||
dinnerType: "",
|
||||
userNum: "-",
|
||||
list: [],
|
||||
startDay: "-",
|
||||
},
|
||||
|
||||
scrollConfig: {
|
||||
scrollAnimationFrameId: null, // 用于存储 requestAnimationFrame 的 ID
|
||||
scrollSpeed: 2, // 滚动速度,每帧移动的像素数
|
||||
// 这里的 scrollWaitTime 将在 startOneTimeScroll 中动态决定
|
||||
// 1秒用于有数据且能滚动,5秒用于无数据或数据不足以滚动
|
||||
dynamicScrollWaitTime: 1 // 动态等待时间,默认为1秒
|
||||
}
|
||||
};
|
||||
},
|
||||
created() {
|
||||
let url = this.$route.query.url;
|
||||
if (url) {
|
||||
this.rankingConfig.requestConfig.url = Array.isArray(url) ? url[0] : url;
|
||||
}
|
||||
let code = this.$route.query.orgCode;
|
||||
if (code) {
|
||||
this.rankingConfig.requestConfig.orgCode = Array.isArray(code) ? code[0] : code;
|
||||
}
|
||||
let canteenId = this.$route.query.canteenId;
|
||||
if (canteenId) {
|
||||
this.rankingConfig.requestConfig.canteenId = Array.isArray(canteenId) ? canteenId[0] : canteenId;
|
||||
}
|
||||
this.loadDataUrl();
|
||||
},
|
||||
beforeDestroy() {
|
||||
this.stopAllLoops();
|
||||
},
|
||||
methods: {
|
||||
stopAllLoops() {
|
||||
if (this.scrollConfig.scrollAnimationFrameId) {
|
||||
cancelAnimationFrame(this.scrollConfig.scrollAnimationFrameId);
|
||||
this.scrollConfig.scrollAnimationFrameId = null;
|
||||
}
|
||||
// 清除可能存在的 setTimeout,避免重复请求
|
||||
if (this.rankingConfig.setTimeOutFun) {
|
||||
clearTimeout(this.rankingConfig.setTimeOutFun);
|
||||
this.rankingConfig.setTimeOutFun = null;
|
||||
}
|
||||
},
|
||||
|
||||
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 requestUrl = serve + _this.rankingConfig.requestConfig.suffix + _this.rankingConfig.requestConfig.urlPrefix + (_this.rankingConfig.personnelType === "staff" ? "/getNutritionRankings" : "/getDepartRankings");
|
||||
|
||||
let params = {
|
||||
orgCode: _this.rankingConfig.requestConfig.orgCode,
|
||||
canteenId: _this.rankingConfig.requestConfig.canteenId,
|
||||
no: _this.rankingConfig.requestConfig.pageSize,
|
||||
};
|
||||
|
||||
httpRequest("GET", requestUrl, params, {
|
||||
'X-Sign': signMd5Utils.getSign(requestUrl, params),
|
||||
'X-TIMESTAMP': signMd5Utils.getDateTimeToString(requestUrl, params),
|
||||
}).then((res) => {
|
||||
_this.dataConfig.list = [];
|
||||
if (res.success && res.result) {
|
||||
_this.dataConfig.dinnerType = res.result.dinnerType ? res.result.dinnerType : "-";
|
||||
_this.dataConfig.userNum = res.result.userNum ? res.result.userNum : "-";
|
||||
// _this.dataConfig.startDay = res.result.startDay ? _this.formatDateString(res.result.startDay) : "-";
|
||||
_this.dataConfig.startDay = "2025年5月7日";
|
||||
|
||||
_this.dataConfig.personnelType = _this.rankingConfig.personnelType;
|
||||
let dataKey = _this.dataConfig.personnelType === "staff" ? 'nutritionRankingsVos' : 'departRankingsVos';
|
||||
let list = res.result[dataKey];
|
||||
|
||||
if (list && list.length) {
|
||||
list.map(item => {
|
||||
if(item.departName === "行政事务管理处") {
|
||||
item.departName = "公共事务中心";
|
||||
}
|
||||
})
|
||||
_this.dataConfig.list = list;
|
||||
|
||||
_this.$nextTick(() => {
|
||||
_this.startOneTimeScroll();
|
||||
});
|
||||
} else {
|
||||
_this.startBannerLoop();
|
||||
}
|
||||
} else {
|
||||
_this.startBannerLoop();
|
||||
}
|
||||
}).catch((error) => {
|
||||
console.error("请求失败:", error);
|
||||
_this.dataConfig.list = [];
|
||||
_this.startBannerLoop();
|
||||
});
|
||||
},
|
||||
|
||||
startOneTimeScroll() {
|
||||
const container = this.$refs.scrollContentBody;
|
||||
if (!container) return;
|
||||
|
||||
const maxScrollTop = container.scrollHeight - container.clientHeight;
|
||||
|
||||
// 根据是否可滚动来设置动态等待时间
|
||||
if (maxScrollTop <= 0) {
|
||||
console.log('内容不足以滚动,等待 5 秒并请求下一批数据');
|
||||
this.scrollConfig.dynamicScrollWaitTime = 5; // 设置为5秒
|
||||
} else {
|
||||
console.log('内容可滚动,等待 1 秒并请求下一批数据');
|
||||
this.scrollConfig.dynamicScrollWaitTime = 1; // 设置为1秒
|
||||
}
|
||||
|
||||
container.scrollTop = 0; // 确保每次开始都从顶部滚动
|
||||
let currentScrollTop = 0;
|
||||
|
||||
const animateScroll = () => {
|
||||
if (currentScrollTop < maxScrollTop) {
|
||||
currentScrollTop += this.scrollConfig.scrollSpeed;
|
||||
if (currentScrollTop > maxScrollTop) {
|
||||
currentScrollTop = maxScrollTop;
|
||||
}
|
||||
container.scrollTop = currentScrollTop;
|
||||
this.scrollConfig.scrollAnimationFrameId = requestAnimationFrame(animateScroll);
|
||||
} else {
|
||||
// 滚动完成后
|
||||
console.log(`列表滚动完成,等待 ${this.scrollConfig.dynamicScrollWaitTime} 秒并请求下一批数据`);
|
||||
this.scrollConfig.scrollAnimationFrameId = null;
|
||||
this.rankingConfig.setTimeOutFun = setTimeout(() => {
|
||||
this.loadDataUrl();
|
||||
}, this.scrollConfig.dynamicScrollWaitTime * 1000);
|
||||
}
|
||||
};
|
||||
|
||||
this.scrollConfig.scrollAnimationFrameId = requestAnimationFrame(animateScroll);
|
||||
},
|
||||
|
||||
maskUserName(fullName) {
|
||||
if (!fullName || typeof fullName !== 'string' || fullName.length === 0) {
|
||||
return '';
|
||||
}
|
||||
let len = fullName.length;
|
||||
if (len === 1) {
|
||||
return fullName;
|
||||
} else if (len === 2) {
|
||||
return fullName.charAt(0) + '*';
|
||||
} else {
|
||||
let firstChar = fullName.charAt(0);
|
||||
let lastChar = fullName.charAt(len - 1);
|
||||
let maskedPart = '*'.repeat(len - 2);
|
||||
return firstChar + maskedPart + lastChar;
|
||||
}
|
||||
},
|
||||
|
||||
startBannerLoop() {
|
||||
setTimeout(() => {
|
||||
this.stopAllLoops();
|
||||
this.loadDataUrl();
|
||||
}, 5000)
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
#dietaryNutritionTips {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 44px 40px 0;
|
||||
box-sizing: border-box;
|
||||
background-size: cover;
|
||||
background-repeat: no-repeat;
|
||||
background-position: center top;
|
||||
background-image: url("@/assets/images/dietaryNutritionTips/bg.png");
|
||||
|
||||
.tips {
|
||||
width: 100%;
|
||||
height: 36px;
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 96px;
|
||||
|
||||
> div:nth-of-type(1) {
|
||||
width: 120px;
|
||||
height: 4px;
|
||||
background: linear-gradient(270deg, #ffc87c 0%, rgba(42, 199, 159, 0) 100%);
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
> div:nth-of-type(2) {
|
||||
color: #ffc87c;
|
||||
height: 36px;
|
||||
font-size: 36px;
|
||||
font-weight: bold;
|
||||
line-height: 36px;
|
||||
margin: 0 36px;
|
||||
}
|
||||
|
||||
> div:nth-of-type(3) {
|
||||
width: 120px;
|
||||
height: 4px;
|
||||
background: linear-gradient(90deg, #ffc87c 0%, rgba(42, 199, 159, 0) 100%);
|
||||
border-radius: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
.title {
|
||||
width: 100%;
|
||||
height: 182px;
|
||||
position: fixed;
|
||||
top: 85px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 3;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
> div:nth-of-type(1) {
|
||||
width: 86px;
|
||||
height: 182px;
|
||||
background-size: contain;
|
||||
background-repeat: no-repeat;
|
||||
background-position: center;
|
||||
background-image: url("@/assets/images/dietaryNutritionTips/l.png");
|
||||
}
|
||||
|
||||
> div:nth-of-type(2) {
|
||||
width: 720px;
|
||||
height: 136px;
|
||||
padding: 18px 30px 0;
|
||||
border-radius: 24px;
|
||||
box-sizing: border-box;
|
||||
background: linear-gradient(-90deg, #ffc77b 0%, #fff4e6 47%, #ffc879 100%);
|
||||
|
||||
> div:nth-of-type(1) {
|
||||
color: #8d0503;
|
||||
width: 100%;
|
||||
height: 48px;
|
||||
font-size: 48px;
|
||||
font-weight: bold;
|
||||
line-height: 48px;
|
||||
text-align: center;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
> div:nth-of-type(2) {
|
||||
width: 100%;
|
||||
height: 40px;
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
justify-content: space-between;
|
||||
align-items: flex-end;
|
||||
|
||||
> div:nth-of-type(1) {
|
||||
color: #8d0503;
|
||||
height: 32px;
|
||||
font-size: 30px;
|
||||
line-height: 32px;
|
||||
}
|
||||
|
||||
> div:nth-of-type(2) {
|
||||
color: #8d0503;
|
||||
height: 40px;
|
||||
font-size: 30px;
|
||||
line-height: 40px;
|
||||
|
||||
> span {
|
||||
margin: 0 6px;
|
||||
font-size: 40px;
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
> div:nth-of-type(3) {
|
||||
width: 86px;
|
||||
height: 182px;
|
||||
background-size: contain;
|
||||
background-repeat: no-repeat;
|
||||
background-position: center;
|
||||
background-image: url("@/assets/images/dietaryNutritionTips/r.png");
|
||||
}
|
||||
}
|
||||
|
||||
.content {
|
||||
width: 100%;
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
border-radius: 16px;
|
||||
padding: 105px 24px 0;
|
||||
box-sizing: border-box;
|
||||
border: 2px solid #ffc548;
|
||||
background: linear-gradient(
|
||||
180deg,
|
||||
rgba(225, 225, 225, 0) 0%,
|
||||
rgba(225, 225, 225, 0.3) 100%
|
||||
);
|
||||
|
||||
.contentHeader {
|
||||
width: 100%;
|
||||
height: 82px;
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
padding: 0 30px;
|
||||
box-sizing: border-box;
|
||||
margin-bottom: 40px;
|
||||
border-radius: 16px;
|
||||
background-color: #7e0b08;
|
||||
|
||||
> div {
|
||||
color: #ffc87c;
|
||||
height: 82px;
|
||||
font-size: 32px;
|
||||
font-weight: bold;
|
||||
line-height: 82px;
|
||||
text-align: center;
|
||||
|
||||
&:nth-of-type(1) {
|
||||
width: 85px;
|
||||
margin-right: 25px;
|
||||
}
|
||||
|
||||
&:nth-of-type(2) {
|
||||
flex: 1;
|
||||
width: 0;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
&.staff-userName {
|
||||
width: 120px;
|
||||
margin-right: 20px;
|
||||
}
|
||||
|
||||
&.staff-fraction {
|
||||
width: 250px;
|
||||
}
|
||||
|
||||
&.department-avgFraction {
|
||||
width: 350px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.contentBody {
|
||||
width: 100%;
|
||||
height: calc(100% - 152px); /* 减去 contentHeader 和其 margin-bottom 的高度 */
|
||||
overflow: hidden; /* 关键:隐藏溢出内容,实现滚动效果 */
|
||||
|
||||
.contentBodyList {
|
||||
width: 100%;
|
||||
height: 40px; /* 行高 */
|
||||
padding: 0 30px;
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
margin-bottom: 56px; /* 行间距 */
|
||||
|
||||
> div {
|
||||
color: #ffffff;
|
||||
height: 40px;
|
||||
font-size: 40px;
|
||||
line-height: 40px;
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
|
||||
&:nth-of-type(1) {
|
||||
width: 85px;
|
||||
margin-right: 25px;
|
||||
}
|
||||
|
||||
&:nth-of-type(2) {
|
||||
flex: 1;
|
||||
width: 0;
|
||||
text-align: left;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
&.staff-userName {
|
||||
width: 120px;
|
||||
margin-right: 20px;
|
||||
}
|
||||
|
||||
&.staff-fraction {
|
||||
width: 250px;
|
||||
}
|
||||
|
||||
&.department-avgFraction {
|
||||
width: 350px;
|
||||
}
|
||||
}
|
||||
|
||||
&:last-of-type {
|
||||
margin-bottom: 0 !important; /* 确保最后一行没有下边距,防止影响 totalHeight 计算 */
|
||||
}
|
||||
}
|
||||
|
||||
.nullData {
|
||||
width: 100%;
|
||||
padding-top: 350px;
|
||||
|
||||
> div:nth-of-type(1) {
|
||||
width: 280px;
|
||||
height: 232px;
|
||||
margin: 0 auto 40px;
|
||||
background-size: cover;
|
||||
background-repeat: no-repeat;
|
||||
background-position: center top;
|
||||
background-image: url("@/assets/images/dietaryNutritionTips/nullData.png");
|
||||
}
|
||||
|
||||
> div:nth-of-type(2) {
|
||||
color: #FFC87C;
|
||||
width: 100%;
|
||||
height: 40px;
|
||||
font-size: 40px;
|
||||
line-height: 40px;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.footer {
|
||||
width: 100%;
|
||||
height: 95px;
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
justify-content: space-between;
|
||||
|
||||
> div {
|
||||
color: #ffffff;
|
||||
height: 95px;
|
||||
font-size: 32px;
|
||||
font-weight: bold;
|
||||
line-height: 95px;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user