feat: 新增视图切换状态管理及颜色/日期工具
- date.js: 新增 startOfWeek, startOfMonth, hhmmToMinutes 辅助函数 - colors.js (新增): 基于 uid 哈希的事件颜色分配, 12 色调色板 - useCalendar.js: 新增 viewMode (edit/month/week) 和 previewDate 状态, 以及 setViewMode/prevMonth/nextMonth/prevWeek/nextWeek 操作
This commit is contained in:
@@ -56,3 +56,36 @@ export function nowCompactTimestamp() {
|
||||
export function toHHMM(date) {
|
||||
return `${pad2(date.getHours())}:${pad2(date.getMinutes())}`
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回 isoDate 所在周的周一 (ISO 周, 周一为首日)。
|
||||
* @param {string} isoDate - 'YYYY-MM-DD'
|
||||
* @returns {string} 周一的 'YYYY-MM-DD'
|
||||
*/
|
||||
export function startOfWeek(isoDate) {
|
||||
const d = toDate(isoDate)
|
||||
const dow = d.getDay() // 0=周日 .. 6=周六
|
||||
const diff = dow === 0 ? -6 : 1 - dow // 回退到周一
|
||||
d.setDate(d.getDate() + diff)
|
||||
return toISODate(d)
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回 isoDate 所在月的第一天。
|
||||
* @param {string} isoDate - 'YYYY-MM-DD'
|
||||
* @returns {string} 当月 1 号的 'YYYY-MM-DD'
|
||||
*/
|
||||
export function startOfMonth(isoDate) {
|
||||
const { year, month } = parseISODate(isoDate)
|
||||
return `${year}-${pad2(month)}-01`
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 'HH:MM' 转换为当天分钟数 (0~1439)。
|
||||
* @param {string} hhmm - 'HH:MM'
|
||||
* @returns {number}
|
||||
*/
|
||||
export function hhmmToMinutes(hhmm) {
|
||||
const [h, m] = hhmm.split(':').map(Number)
|
||||
return h * 60 + m
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user