Commit 8978b967 by chenwq

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

- 将每日考勤信息存储于模块级变量,供日历格式化函数访问
- 修正日历日期样式逻辑:仅当某天无考勤记录时显示为周末样式
- 修复模拟数据中的姓名长度和日期错误
- 优化日期字符串的构建方式,保持代码一致性
1 parent c9f649d6
// packageWorkspace/pages/attendanceStatis/attendanceDetail/attendanceDetail.js // packageWorkspace/pages/attendanceStatis/attendanceDetail/attendanceDetail.js
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/miniprogram/regional-assistant/' 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({ Page({
/** /**
* 页面的初始数据 * 页面的初始数据
*/ */
...@@ -14,21 +19,33 @@ Page({ ...@@ -14,21 +19,33 @@ Page({
totalWorkHours: 0.0, totalWorkHours: 0.0,
lateEarlyHours: 0.0, lateEarlyHours: 0.0,
missingPunchCount: 0, missingPunchCount: 0,
attendanceDailyInfoDTOs: [], attendanceDailyInfoDTOs: []
}, },
formattedMonth: "", formattedMonth: "",
minDate: new Date().getTime(), minDate: new Date().getTime(),
maxDate: new Date().getTime(), maxDate: new Date().getTime(),
selectedDate: "", // YYYY-MM-DD selectedDate: '', // YYYY-MM-DD
currentDayInfo: null, // { workTime, offWorkTime } currentDayInfo: null, // { workTime, offWorkTime }
formatter(day) { formatter(day) {
const date = new Date(day.date); const date = new Date(day.date);
const dayOfWeek = date.getDay(); const year = date.getFullYear();
if (dayOfWeek === 0 || dayOfWeek === 6) { const month = (date.getMonth() + 1).toString().padStart(2, '0');
day.className = "weekend-day"; 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; return day;
}, }
}, },
/** /**
...@@ -45,7 +62,7 @@ Page({ ...@@ -45,7 +62,7 @@ Page({
// 模拟接口返回数据 // 模拟接口返回数据
const mockData = { const mockData = {
mobilePhone: "13800138000", mobilePhone: "13800138000",
name: "董天天22222222222222222222222222222222222222222222222222222222", name: "董天天",
positionName: "延保驻店销售", positionName: "延保驻店销售",
attendanceMonth: "2026-01", attendanceMonth: "2026-01",
totalWorkHours: 7.2, totalWorkHours: 7.2,
...@@ -53,20 +70,23 @@ Page({ ...@@ -53,20 +70,23 @@ Page({
missingPunchCount: 0, missingPunchCount: 0,
attendanceDailyInfoDTOs: [ attendanceDailyInfoDTOs: [
{ date: "2026-01-01", workTime: "09:00", offWorkTime: "18:00" }, { 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-05", workTime: "", offWorkTime: "18:00" }, // 缺卡示例
{ date: "2026-01-06", workTime: "09:00", offWorkTime: "" }, // 缺卡示例 { 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 // Calculate min and max date based on attendanceMonth
let minDate = new Date().getTime(); let minDate = new Date().getTime();
let maxDate = new Date().getTime(); let maxDate = new Date().getTime();
let defaultDate = new Date().getTime(); let defaultDate = new Date().getTime();
if (mockData.attendanceMonth) { if (mockData.attendanceMonth) {
const parts = mockData.attendanceMonth.split("-"); const parts = mockData.attendanceMonth.split('-');
if (parts.length === 2) { if (parts.length === 2) {
const year = parseInt(parts[0]); const year = parseInt(parts[0]);
const month = parseInt(parts[1]); const month = parseInt(parts[1]);
...@@ -88,7 +108,7 @@ Page({ ...@@ -88,7 +108,7 @@ Page({
formattedMonth: this.formatMonth(mockData.attendanceMonth), formattedMonth: this.formatMonth(mockData.attendanceMonth),
minDate, minDate,
maxDate, maxDate,
defaultDate, defaultDate
}); });
// Initialize selection (simulate selecting the default date) // Initialize selection (simulate selecting the default date)
...@@ -99,7 +119,7 @@ Page({ ...@@ -99,7 +119,7 @@ Page({
formatMonth(monthStr) { formatMonth(monthStr) {
if (!monthStr) return ""; if (!monthStr) return "";
// 假设 monthStr 格式为 "YYYY-MM" // 假设 monthStr 格式为 "YYYY-MM"
const parts = monthStr.split("-"); const parts = monthStr.split('-');
if (parts.length === 2) { if (parts.length === 2) {
return `${parts[0]}年${parseInt(parts[1])}月`; // parseInt 去掉月份前导0 return `${parts[0]}年${parseInt(parts[1])}月`; // parseInt 去掉月份前导0
} }
...@@ -112,18 +132,16 @@ Page({ ...@@ -112,18 +132,16 @@ Page({
handleDateSelect(date) { handleDateSelect(date) {
const year = date.getFullYear(); const year = date.getFullYear();
const month = (date.getMonth() + 1).toString().padStart(2, "0"); const month = (date.getMonth() + 1).toString().padStart(2, '0');
const day = date.getDate().toString().padStart(2, "0"); const day = date.getDate().toString().padStart(2, '0');
const dateStr = `${year}-${month}-${day}`; const dateStr = `${year}-${month}-${day}`;
// Find info for this date // Find info for this date
const dayInfo = this.data.detail.attendanceDailyInfoDTOs.find( const dayInfo = this.data.detail.attendanceDailyInfoDTOs.find(item => item.date === dateStr);
(item) => item.date === dateStr,
);
this.setData({ this.setData({
selectedDate: dateStr, 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!