fix: 修复节假日显示和编辑问题
- 修复内置节假日倒计时显示错误(设置is_lunar为false,因为日期已是公历) - 修复内置节假日点击行为:显示只读详情弹窗 - 添加内置节假日标识,支持查看详情 - 启用纪念日编辑时的农历开关 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
eb7aeb586b
commit
183c88a6ac
@ -139,7 +139,9 @@ export function AnniversaryList({ events, onEventClick, onAddClick }: Anniversar
|
|||||||
title: h.name,
|
title: h.name,
|
||||||
date: h.date.toISOString(),
|
date: h.date.toISOString(),
|
||||||
is_holiday: true,
|
is_holiday: true,
|
||||||
is_lunar: h.isLunar,
|
// 注意:内置节假日的日期已经是计算后的公历日期,
|
||||||
|
// 不需要再按农历处理,直接使用公历即可
|
||||||
|
is_lunar: false,
|
||||||
repeat_type: 'yearly',
|
repeat_type: 'yearly',
|
||||||
type: 'anniversary',
|
type: 'anniversary',
|
||||||
is_builtin: true,
|
is_builtin: true,
|
||||||
|
|||||||
@ -46,6 +46,7 @@ export function HomePage() {
|
|||||||
const [opened, { open, close }] = useDisclosure(false);
|
const [opened, { open, close }] = useDisclosure(false);
|
||||||
const [selectedEvent, setSelectedEvent] = useState<Event | null>(null);
|
const [selectedEvent, setSelectedEvent] = useState<Event | null>(null);
|
||||||
const [isEdit, setIsEdit] = useState(false);
|
const [isEdit, setIsEdit] = useState(false);
|
||||||
|
const [isBuiltinHoliday, setIsBuiltinHoliday] = useState(false); // 内置节假日只读模式
|
||||||
|
|
||||||
// Form state
|
// Form state
|
||||||
const [formType, setFormType] = useState<EventType>('anniversary');
|
const [formType, setFormType] = useState<EventType>('anniversary');
|
||||||
@ -71,7 +72,33 @@ export function HomePage() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleEventClick = (event: Event) => {
|
const handleEventClick = (event: Event) => {
|
||||||
|
// 检查是否是内置节假日(id 以 builtin- 开头)
|
||||||
|
if (event.id && event.id.startsWith('builtin-')) {
|
||||||
|
// 内置节假日:显示详情(只读模式)
|
||||||
|
setSelectedEvent(event);
|
||||||
|
setIsEdit(false);
|
||||||
|
setIsBuiltinHoliday(true);
|
||||||
|
setFormType(event.type);
|
||||||
|
setFormTitle(event.title);
|
||||||
|
setFormContent(event.content || '');
|
||||||
|
setFormDate(new Date(event.date));
|
||||||
|
setFormIsLunar(event.is_lunar);
|
||||||
|
setFormRepeatType(event.repeat_type);
|
||||||
|
setFormIsHoliday(event.is_holiday || false);
|
||||||
|
setFormPriority(event.priority || 'none');
|
||||||
|
const eventDate = new Date(event.date);
|
||||||
|
const hours = eventDate.getHours();
|
||||||
|
const minutes = eventDate.getMinutes();
|
||||||
|
const hasTime = hours !== 0 || minutes !== 0;
|
||||||
|
setFormTime(hasTime ? `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}` : '');
|
||||||
|
setFormReminderValue('0');
|
||||||
|
open();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 用户创建的纪念日/提醒:编辑模式
|
||||||
setSelectedEvent(event);
|
setSelectedEvent(event);
|
||||||
|
setIsBuiltinHoliday(false);
|
||||||
setIsEdit(true);
|
setIsEdit(true);
|
||||||
setFormType(event.type);
|
setFormType(event.type);
|
||||||
setFormTitle(event.title);
|
setFormTitle(event.title);
|
||||||
@ -95,6 +122,7 @@ export function HomePage() {
|
|||||||
const handleAddClick = (type: EventType) => {
|
const handleAddClick = (type: EventType) => {
|
||||||
setSelectedEvent(null);
|
setSelectedEvent(null);
|
||||||
setIsEdit(false);
|
setIsEdit(false);
|
||||||
|
setIsBuiltinHoliday(false);
|
||||||
setFormType(type);
|
setFormType(type);
|
||||||
setFormTitle('');
|
setFormTitle('');
|
||||||
setFormContent('');
|
setFormContent('');
|
||||||
@ -418,7 +446,7 @@ export function HomePage() {
|
|||||||
fontSize: '1rem',
|
fontSize: '1rem',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{isEdit ? '编辑事件' : '添加事件'}
|
{isBuiltinHoliday ? '节假日详情' : (isEdit ? '编辑事件' : '添加事件')}
|
||||||
</Text>
|
</Text>
|
||||||
}
|
}
|
||||||
size="md"
|
size="md"
|
||||||
@ -576,20 +604,19 @@ export function HomePage() {
|
|||||||
</Group>
|
</Group>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
{/* Lunar switch (only for anniversaries, disabled in edit mode) */}
|
{/* Lunar switch (only for anniversaries) */}
|
||||||
{formType === 'anniversary' && (
|
{formType === 'anniversary' && (
|
||||||
<Switch
|
<Switch
|
||||||
label={
|
label={
|
||||||
<Text size="xs" c={isEdit ? '#ccc' : '#666'} style={{ letterSpacing: '0.05em' }}>
|
<Text size="xs" c="#666" style={{ letterSpacing: '0.05em' }}>
|
||||||
农历日期
|
农历日期
|
||||||
</Text>
|
</Text>
|
||||||
}
|
}
|
||||||
checked={formIsLunar}
|
checked={formIsLunar}
|
||||||
onChange={(e) => setFormIsLunar(e.currentTarget.checked)}
|
onChange={(e) => setFormIsLunar(e.currentTarget.checked)}
|
||||||
disabled={isEdit}
|
|
||||||
styles={{
|
styles={{
|
||||||
track: {
|
track: {
|
||||||
opacity: isEdit ? 0.5 : 1,
|
opacity: 1,
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@ -701,7 +728,7 @@ export function HomePage() {
|
|||||||
|
|
||||||
{/* Actions */}
|
{/* Actions */}
|
||||||
<Group justify="space-between" mt="md">
|
<Group justify="space-between" mt="md">
|
||||||
{isEdit && (
|
{isEdit && !isBuiltinHoliday && (
|
||||||
<Button
|
<Button
|
||||||
color="dark"
|
color="dark"
|
||||||
variant="light"
|
variant="light"
|
||||||
@ -713,28 +740,44 @@ export function HomePage() {
|
|||||||
删除
|
删除
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
{isBuiltinHoliday && <div />}
|
||||||
<Group ml="auto">
|
<Group ml="auto">
|
||||||
<Button
|
{isBuiltinHoliday ? (
|
||||||
variant="subtle"
|
<Button
|
||||||
onClick={close}
|
onClick={close}
|
||||||
style={{
|
style={{
|
||||||
borderRadius: 2,
|
background: '#1a1a1a',
|
||||||
color: '#666',
|
border: '1px solid #1a1a1a',
|
||||||
}}
|
borderRadius: 2,
|
||||||
>
|
}}
|
||||||
取消
|
>
|
||||||
</Button>
|
关闭
|
||||||
<Button
|
</Button>
|
||||||
onClick={handleSubmit}
|
) : (
|
||||||
disabled={!formTitle.trim() || !formDate}
|
<>
|
||||||
style={{
|
<Button
|
||||||
background: '#1a1a1a',
|
variant="subtle"
|
||||||
border: '1px solid #1a1a1a',
|
onClick={close}
|
||||||
borderRadius: 2,
|
style={{
|
||||||
}}
|
borderRadius: 2,
|
||||||
>
|
color: '#666',
|
||||||
{isEdit ? '保存' : '添加'}
|
}}
|
||||||
</Button>
|
>
|
||||||
|
取消
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={handleSubmit}
|
||||||
|
disabled={!formTitle.trim() || !formDate}
|
||||||
|
style={{
|
||||||
|
background: '#1a1a1a',
|
||||||
|
border: '1px solid #1a1a1a',
|
||||||
|
borderRadius: 2,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{isEdit ? '保存' : '添加'}
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</Group>
|
</Group>
|
||||||
</Group>
|
</Group>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user