Commit 8978b967 by chenwq

fix(attendanceDetail): 修正考勤日历样式逻辑并优化数据存储

- 将每日考勤信息存储于模块级变量,供日历格式化函数访问
- 修正日历日期样式逻辑:仅当某天无考勤记录时显示为周末样式
- 修复模拟数据中的姓名长度和日期错误
- 优化日期字符串的构建方式,保持代码一致性
1 parent c9f649d6
// packageWorkspace/pages/attendanceStatis/attendanceDetail/attendanceDetail.js
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/miniprogram/regional-assistant/'
// Store daily info at module level to be accessible by formatter
let dailyInfos = [];
Page({
/**
* 页面的初始数据
*/
......@@ -14,21 +19,33 @@ Page({
totalWorkHours: 0.0,
lateEarlyHours: 0.0,
missingPunchCount: 0,
attendanceDailyInfoDTOs: [],
attendanceDailyInfoDTOs: []
},
formattedMonth: "",
minDate: new Date().getTime(),
maxDate: new Date().getTime(),
selectedDate: "", // YYYY-MM-DD
selectedDate: '', // YYYY-MM-DD
currentDayInfo: null, // { workTime, offWorkTime }
formatter(day) {
const date = new Date(day.date);
const dayOfWeek = date.getDay();
if (dayOfWeek === 0 || dayOfWeek === 6) {
day.className = "weekend-day";
const year = date.getFullYear();
const month = (date.getMonth() + 1).toString().padStart(2, '0');
const d = date.getDate().toString().padStart(2, '0');
const dateStr = `${year}-${month}-${d}`;
// Find info for this date
const info = dailyInfos.find(item => item.date === dateStr);
// Workday style (Has record): workTime OR offWorkTime is present
// Weekend style (No record): Both are missing/empty
const hasRecord = info && (info.workTime || info.offWorkTime);
if (!hasRecord) {
day.className = 'weekend-day';
}
return day;
},
}
},
/**
......@@ -45,7 +62,7 @@ Page({
// 模拟接口返回数据
const mockData = {
mobilePhone: "13800138000",
name: "董天天22222222222222222222222222222222222222222222222222222222",
name: "董天天",
positionName: "延保驻店销售",
attendanceMonth: "2026-01",
totalWorkHours: 7.2,
......@@ -53,20 +70,23 @@ Page({
missingPunchCount: 0,
attendanceDailyInfoDTOs: [
{ date: "2026-01-01", workTime: "09:00", offWorkTime: "18:00" },
{ date: "2026-01-02", workTime: "08:55", offWorkTime: "18:05" },
{ date: "2026-01-03", workTime: "08:55", offWorkTime: "18:05" },
{ date: "2026-01-05", workTime: "", offWorkTime: "18:00" }, // 缺卡示例
{ date: "2026-01-06", workTime: "09:00", offWorkTime: "" }, // 缺卡示例
{ date: "2026-01-07", workTime: "", offWorkTime: "" }, // 缺卡示例
],
{ date: "2026-01-07", workTime: "", offWorkTime: "" } // 缺卡示例
]
};
// Update module-level variable
dailyInfos = mockData.attendanceDailyInfoDTOs || [];
// Calculate min and max date based on attendanceMonth
let minDate = new Date().getTime();
let maxDate = new Date().getTime();
let defaultDate = new Date().getTime();
if (mockData.attendanceMonth) {
const parts = mockData.attendanceMonth.split("-");
const parts = mockData.attendanceMonth.split('-');
if (parts.length === 2) {
const year = parseInt(parts[0]);
const month = parseInt(parts[1]);
......@@ -74,7 +94,7 @@ Page({
minDate = new Date(year, month - 1, 1).getTime();
// maxDate: Last day of the month
maxDate = new Date(year, month, 0).getTime();
// Default to the 5th for demo purposes as per screenshot, or minDate
defaultDate = new Date(year, month - 1, 5).getTime();
// Ensure defaultDate is within range
......@@ -88,7 +108,7 @@ Page({
formattedMonth: this.formatMonth(mockData.attendanceMonth),
minDate,
maxDate,
defaultDate,
defaultDate
});
// Initialize selection (simulate selecting the default date)
......@@ -99,7 +119,7 @@ Page({
formatMonth(monthStr) {
if (!monthStr) return "";
// 假设 monthStr 格式为 "YYYY-MM"
const parts = monthStr.split("-");
const parts = monthStr.split('-');
if (parts.length === 2) {
return `${parts[0]}年${parseInt(parts[1])}月`; // parseInt 去掉月份前导0
}
......@@ -112,18 +132,16 @@ Page({
handleDateSelect(date) {
const year = date.getFullYear();
const month = (date.getMonth() + 1).toString().padStart(2, "0");
const day = date.getDate().toString().padStart(2, "0");
const month = (date.getMonth() + 1).toString().padStart(2, '0');
const day = date.getDate().toString().padStart(2, '0');
const dateStr = `${year}-${month}-${day}`;
// Find info for this date
const dayInfo = this.data.detail.attendanceDailyInfoDTOs.find(
(item) => item.date === dateStr,
);
const dayInfo = this.data.detail.attendanceDailyInfoDTOs.find(item => item.date === dateStr);
this.setData({
selectedDate: dateStr,
currentDayInfo: dayInfo || null,
currentDayInfo: dayInfo || null
});
},
});
}
})
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!