新增数据,开始安全巡检模块
This commit is contained in:
@@ -64,3 +64,54 @@ export function formatTimeDiff(startTime: string | number | Date, endTime: strin
|
||||
|
||||
return res.join('');
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成指定日期所在周的日期数组(周一到周日)
|
||||
* @param date 基准日期,默认今天
|
||||
* @param format 返回格式
|
||||
* @returns 一周日期数组
|
||||
*/
|
||||
export function generateWeekDays(date: Date | string | number = new Date(), format: 'name' | 'date' | 'full' = 'name'): string[] {
|
||||
const weekNames = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'];
|
||||
const baseDate = new Date(date);
|
||||
|
||||
// 计算本周一的日期(getDay() 0=周日,1=周一)
|
||||
const day = baseDate.getDay();
|
||||
const monday = new Date(baseDate);
|
||||
monday.setDate(baseDate.getDate() - (day === 0 ? 6 : day - 1));
|
||||
|
||||
// 生成周一到周日7天
|
||||
const week = [];
|
||||
for (let i = 0; i < 7; i++) {
|
||||
const current = new Date(monday);
|
||||
current.setDate(monday.getDate() + i);
|
||||
|
||||
if (format === 'name') {
|
||||
week.push(weekNames[i]);
|
||||
} else if (format === 'date') {
|
||||
// YYYY-MM-DD 格式
|
||||
const year = current.getFullYear();
|
||||
const month = String(current.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(current.getDate()).padStart(2, '0');
|
||||
week.push(`${year}-${month}-${day}`);
|
||||
} else {
|
||||
// 完整格式:周一 (2026-04-20)
|
||||
const year = current.getFullYear();
|
||||
const month = String(current.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(current.getDate()).padStart(2, '0');
|
||||
week.push(`${weekNames[i]} (${year}-${month}-${day})`);
|
||||
}
|
||||
}
|
||||
|
||||
return week;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据数字 1-7 生成对应星期
|
||||
* @param num 1=周一,2=周二...7=周日
|
||||
* @returns 周一 / 周二 ... / 周日
|
||||
*/
|
||||
export function numToWeek(num: number): string {
|
||||
const weekMap = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'];
|
||||
return weekMap[num - 1] || '';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user