feat: 网页端待办到期提醒功能

- 新增 /api/reminders API 接口
- 获取已过期、今天到期、即将到期的待办
- 前端显示提醒栏和弹窗详情
- 每5分钟自动刷新提醒
- 支持快速完成待办
This commit is contained in:
2026-04-16 10:59:26 +08:00
parent d874577458
commit 2eccc11369
2 changed files with 253 additions and 0 deletions

View File

@@ -433,6 +433,59 @@ class Database:
stats['tags'] = cursor.fetchone()['count']
return stats
# ============ 提醒相关 ============
def get_reminders(self) -> Dict[str, Any]:
"""获取提醒信息:即将到期和已过期的待办"""
self._ensure_init()
with self.get_conn() as conn:
cursor = conn.cursor()
now = datetime.now()
reminders = {
'overdue': [], # 已过期
'due_today': [], # 今天到期
'due_soon': [] # 24小时内到期不含今天
}
# 查询未完成的待办(有截止日期的)
cursor.execute("""
SELECT * FROM items
WHERE type = 'todo'
AND status != 'completed'
AND due_date IS NOT NULL
AND due_date != ''
ORDER BY due_date ASC
""")
for row in cursor.fetchall():
item = dict(row)
item['tags'] = self._get_item_tags(conn, item['id'])
try:
due_date = datetime.strptime(item['due_date'], '%Y-%m-%d')
# 计算距离到期的时间
days_left = (due_date.date() - now.date()).days
if days_left < 0:
# 已过期
item['days_overdue'] = abs(days_left)
reminders['overdue'].append(item)
elif days_left == 0:
# 今天到期
reminders['due_today'].append(item)
elif days_left == 1:
# 明天到期24小时内
reminders['due_soon'].append(item)
except ValueError:
# 日期格式错误,跳过
continue
# 统计总数
reminders['total'] = len(reminders['overdue']) + len(reminders['due_today']) + len(reminders['due_soon'])
return reminders
# 全局数据库实例