liu
昨天 c62517daefcc52624f6eece28a2693fa8f4b9b41
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/** 排班网格的日期工具 */
 
const WEEK_LABELS = ['日', '一', '二', '三', '四', '五', '六'];
 
/** 返回某月天数数组,如 2026-08 → [1..31] */
export function getDaysOfMonth(yearMonth: string): number[] {
  const [yearStr, monthStr] = yearMonth.split('-');
  const days = new Date(Number(yearStr), Number(monthStr), 0).getDate();
  return Array.from({ length: days }, (_, i) => i + 1);
}
 
/** 返回某日的星期中文标签(日/一/二…) */
export function getWeekLabel(yearMonth: string, day: number): string {
  const date = new Date(`${yearMonth}-${String(day).padStart(2, '0')}`);
  return WEEK_LABELS[date.getDay()] ?? '';
}
 
/** 判断某日是否为周末 */
export function isWeekend(yearMonth: string, day: number): boolean {
  const date = new Date(`${yearMonth}-${String(day).padStart(2, '0')}`);
  const week = date.getDay();
  return week === 0 || week === 6;
}
 
/** 生成某月某日的日期字符串 yyyy-MM-dd */
export function formatDate(yearMonth: string, day: number): string {
  return `${yearMonth}-${String(day).padStart(2, '0')}`;
}
 
/** 自动排班休息模式 */
export const REST_MODE = {
  /** 双休:周六、周日休息 */
  DOUBLE: 'double',
  /** 单休:周日休息 */
  SINGLE: 'single',
  /** 不休息:每天排班 */
  NONE: 'none',
} as const;
 
export type RestMode = (typeof REST_MODE)[keyof typeof REST_MODE];
 
export const REST_MODE_OPTIONS: { label: string; value: RestMode }[] = [
  { label: '双休(六日休)', value: REST_MODE.DOUBLE },
  { label: '单休(周日休)', value: REST_MODE.SINGLE },
  { label: '不休息', value: REST_MODE.NONE },
];