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,
|
||||
date: h.date.toISOString(),
|
||||
is_holiday: true,
|
||||
is_lunar: h.isLunar,
|
||||
// 注意:内置节假日的日期已经是计算后的公历日期,
|
||||
// 不需要再按农历处理,直接使用公历即可
|
||||
is_lunar: false,
|
||||
repeat_type: 'yearly',
|
||||
type: 'anniversary',
|
||||
is_builtin: true,
|
||||
|
||||
@ -46,6 +46,7 @@ export function HomePage() {
|
||||
const [opened, { open, close }] = useDisclosure(false);
|
||||
const [selectedEvent, setSelectedEvent] = useState<Event | null>(null);
|
||||
const [isEdit, setIsEdit] = useState(false);
|
||||
const [isBuiltinHoliday, setIsBuiltinHoliday] = useState(false); // 内置节假日只读模式
|
||||
|
||||
// Form state
|
||||
const [formType, setFormType] = useState<EventType>('anniversary');
|
||||
@ -71,7 +72,33 @@ export function HomePage() {
|
||||
};
|
||||
|
||||
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);
|
||||
setIsBuiltinHoliday(false);
|
||||
setIsEdit(true);
|
||||
setFormType(event.type);
|
||||
setFormTitle(event.title);
|
||||
@ -95,6 +122,7 @@ export function HomePage() {
|
||||
const handleAddClick = (type: EventType) => {
|
||||
setSelectedEvent(null);
|
||||
setIsEdit(false);
|
||||
setIsBuiltinHoliday(false);
|
||||
setFormType(type);
|
||||
setFormTitle('');
|
||||
setFormContent('');
|
||||
@ -418,7 +446,7 @@ export function HomePage() {
|
||||
fontSize: '1rem',
|
||||
}}
|
||||
>
|
||||
{isEdit ? '编辑事件' : '添加事件'}
|
||||
{isBuiltinHoliday ? '节假日详情' : (isEdit ? '编辑事件' : '添加事件')}
|
||||
</Text>
|
||||
}
|
||||
size="md"
|
||||
@ -576,20 +604,19 @@ export function HomePage() {
|
||||
</Group>
|
||||
</Box>
|
||||
|
||||
{/* Lunar switch (only for anniversaries, disabled in edit mode) */}
|
||||
{/* Lunar switch (only for anniversaries) */}
|
||||
{formType === 'anniversary' && (
|
||||
<Switch
|
||||
label={
|
||||
<Text size="xs" c={isEdit ? '#ccc' : '#666'} style={{ letterSpacing: '0.05em' }}>
|
||||
<Text size="xs" c="#666" style={{ letterSpacing: '0.05em' }}>
|
||||
农历日期
|
||||
</Text>
|
||||
}
|
||||
checked={formIsLunar}
|
||||
onChange={(e) => setFormIsLunar(e.currentTarget.checked)}
|
||||
disabled={isEdit}
|
||||
styles={{
|
||||
track: {
|
||||
opacity: isEdit ? 0.5 : 1,
|
||||
opacity: 1,
|
||||
},
|
||||
}}
|
||||
/>
|
||||
@ -701,7 +728,7 @@ export function HomePage() {
|
||||
|
||||
{/* Actions */}
|
||||
<Group justify="space-between" mt="md">
|
||||
{isEdit && (
|
||||
{isEdit && !isBuiltinHoliday && (
|
||||
<Button
|
||||
color="dark"
|
||||
variant="light"
|
||||
@ -713,28 +740,44 @@ export function HomePage() {
|
||||
删除
|
||||
</Button>
|
||||
)}
|
||||
{isBuiltinHoliday && <div />}
|
||||
<Group ml="auto">
|
||||
<Button
|
||||
variant="subtle"
|
||||
onClick={close}
|
||||
style={{
|
||||
borderRadius: 2,
|
||||
color: '#666',
|
||||
}}
|
||||
>
|
||||
取消
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleSubmit}
|
||||
disabled={!formTitle.trim() || !formDate}
|
||||
style={{
|
||||
background: '#1a1a1a',
|
||||
border: '1px solid #1a1a1a',
|
||||
borderRadius: 2,
|
||||
}}
|
||||
>
|
||||
{isEdit ? '保存' : '添加'}
|
||||
</Button>
|
||||
{isBuiltinHoliday ? (
|
||||
<Button
|
||||
onClick={close}
|
||||
style={{
|
||||
background: '#1a1a1a',
|
||||
border: '1px solid #1a1a1a',
|
||||
borderRadius: 2,
|
||||
}}
|
||||
>
|
||||
关闭
|
||||
</Button>
|
||||
) : (
|
||||
<>
|
||||
<Button
|
||||
variant="subtle"
|
||||
onClick={close}
|
||||
style={{
|
||||
borderRadius: 2,
|
||||
color: '#666',
|
||||
}}
|
||||
>
|
||||
取消
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleSubmit}
|
||||
disabled={!formTitle.trim() || !formDate}
|
||||
style={{
|
||||
background: '#1a1a1a',
|
||||
border: '1px solid #1a1a1a',
|
||||
borderRadius: 2,
|
||||
}}
|
||||
>
|
||||
{isEdit ? '保存' : '添加'}
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
</Group>
|
||||
</Group>
|
||||
</Stack>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user