feat: 初始提交(仅核心代码,已排除大文件)
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
// 数据模型与工具
|
||||
const Models = (function () {
|
||||
function uuid() {
|
||||
return (crypto && crypto.randomUUID) ? crypto.randomUUID() : (
|
||||
Date.now() + '-' + Math.random().toString(36).slice(2)
|
||||
);
|
||||
}
|
||||
|
||||
function nowISO() { return new Date().toISOString(); }
|
||||
|
||||
function ensureEnd(startISO, endISO, allDay) {
|
||||
if (endISO) return endISO;
|
||||
const s = new Date(startISO);
|
||||
const e = new Date(s.getTime() + (allDay ? 24 * 3600_000 : 60 * 60_000));
|
||||
return e.toISOString();
|
||||
}
|
||||
|
||||
function createEvent({ title, content, start, end, allDay, remindAt, recurrence, completed }) {
|
||||
const createdAt = nowISO();
|
||||
const ev = {
|
||||
id: uuid(),
|
||||
title: (title || '').trim(),
|
||||
content: (content || '').trim(),
|
||||
start,
|
||||
end: ensureEnd(start, end, !!allDay),
|
||||
allDay: !!allDay,
|
||||
remindAt: remindAt || '',
|
||||
recurrence: recurrence || '',
|
||||
completed: !!completed,
|
||||
createdAt,
|
||||
updatedAt: createdAt,
|
||||
deleted: false,
|
||||
};
|
||||
return ev;
|
||||
}
|
||||
|
||||
function normalizeForUpdate(ev) {
|
||||
ev.updatedAt = nowISO();
|
||||
if (!ev.end) ev.end = ensureEnd(ev.start, ev.end, ev.allDay);
|
||||
ev.title = (ev.title || '').trim();
|
||||
ev.content = (ev.content || '').trim();
|
||||
ev.completed = !!ev.completed;
|
||||
return ev;
|
||||
}
|
||||
|
||||
function isSameDay(isoA, isoB) {
|
||||
const a = new Date(isoA), b = new Date(isoB);
|
||||
return a.getUTCFullYear() === b.getUTCFullYear() &&
|
||||
a.getUTCMonth() === b.getUTCMonth() &&
|
||||
a.getUTCDate() === b.getUTCDate();
|
||||
}
|
||||
|
||||
return { createEvent, normalizeForUpdate, isSameDay };
|
||||
})();
|
||||
|
||||
window.Models = Models;
|
||||
Reference in New Issue
Block a user