iter(g115): 新增月历组件 calendar

This commit is contained in:
HIsheR
2026-10-26 14:08:58 +08:00
parent b4ab92ed98
commit c2900a4852
15 changed files with 378 additions and 26 deletions
+21
View File
@@ -18,6 +18,7 @@ import {
badge,
breadcrumb,
button,
calendar,
card,
cascader,
checkbox,
@@ -132,6 +133,15 @@ const users = [
'Quinn', 'Rose', 'Sam', 'Tina', 'Uma', 'Victor', 'Wendy', 'Xavier',
].map((name, i) => ({ id: i + 1, name, age: 22 + ((i * 7) % 20), city: cities[i % cities.length] }));
// —— 月历标记:以今天为基准前后几天,避免把日期写死 ——
const dayKey = (n: number): string => {
const d = new Date();
d.setDate(d.getDate() + n);
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
};
const calendarMarks: Record<string, string> = { [dayKey(0)]: '2 项', [dayKey(2)]: '1 项', [dayKey(-3)]: '5 项' };
const calDay = signal(dayKey(0));
// —— 响应式状态演示 ——
const count = signal(0);
@@ -1218,6 +1228,17 @@ const content = h(
}, button({ label: '删除记录', variant: 'danger' })),
popconfirm({ title: '发布到生产?', description: '发布后 1 分钟内全量生效。', confirmText: '发布', onConfirm: () => toast.success('已发布') }, button({ label: '发布', variant: 'ghost' })),
),
section(
'sec-calendar',
'月历',
'calendar 把整月网格内嵌进页面(排期 / 值班 / 日程):每日可带标记文案,标记同时写进 aria-label 让读屏也听得到;←→ 逐日、↑↓ 逐周、Enter 选中,跨月自动翻页并交接焦点。',
calendar({
value: calDay,
marker: (date) => calendarMarks[date] ?? null,
onSelect: (date) => toast.info(`选中 ${date}`),
}),
h('span', { class: 'out' }, () => `当前选中:${calDay() || '无'}`),
),
);
// 引导漫游实例:根节点需挂到 body(fixed 定位,不参与布局)