From 1f1528979ca810eb982ccfac7a834aa787b856a0 Mon Sep 17 00:00:00 2001
From: hubian <908234780@qq.com>
Date: Thu, 16 Apr 2026 11:37:04 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BE=85=E5=8A=9E=E6=88=AA=E6=AD=A2?=
=?UTF-8?q?=E6=97=B6=E9=97=B4=E6=94=AF=E6=8C=81=E6=97=A5=E6=9C=9F+?=
=?UTF-8?q?=E6=97=B6=E9=97=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 截止日期改为日期时间选择器(datetime-local)
- 新增友好显示函数:今天/明天/昨天 + 时间
- 详情页显示完整日期时间格式
- 提醒弹窗显示友好格式
- 后端支持多种日期格式解析
- 只有日期的待办视为当天23:59到期
---
xian_favor/api.py | 96 +++++++++++++++++++++++++++++++++++++++++------
xian_favor/db.py | 37 ++++++++++++------
2 files changed, 110 insertions(+), 23 deletions(-)
diff --git a/xian_favor/api.py b/xian_favor/api.py
index 189d07f..4907fb2 100644
--- a/xian_favor/api.py
+++ b/xian_favor/api.py
@@ -718,8 +718,8 @@ INDEX_TEMPLATE = '''
-
-
+
+
@@ -825,8 +825,8 @@ INDEX_TEMPLATE = '''
-
-
+
+
@@ -1060,8 +1060,8 @@ INDEX_TEMPLATE = '''
-
-
+
+
@@ -1187,7 +1187,7 @@ function renderItems(items) {
${item.url ? truncate(item.url, 50) : item.content ? truncate(item.content, 50) : item.note ? truncate(item.note, 50) : ''}
- ${item.type === 'todo' ? `${getStatusLabelShort(item.status)} ${getPriorityLabelShort(item.priority)} ${item.due_date ? '📅' + item.due_date : ''}` : ''}
+ ${item.type === 'todo' ? `${getStatusLabelShort(item.status)} ${getPriorityLabelShort(item.priority)} ${item.due_date ? '📅' + formatDueDate(item.due_date) : ''}` : ''}
@@ -1437,7 +1437,7 @@ async function showDetail(id) {
html += `
状态: ${getStatusLabel(item.status)}
`;
html += `
优先级: ${getPriorityLabel(item.priority)}
`;
if (item.due_date) {
- html += `
截止日期: ${item.due_date}
`;
+ html += `
截止时间: ${formatDueDateFull(item.due_date)}
`;
}
}
@@ -1509,7 +1509,21 @@ async function openEditModal(id) {
if (type === 'todo') {
document.getElementById('editStatus').value = item.status;
document.getElementById('editPriority').value = item.priority;
- document.getElementById('editDueDate').value = item.due_date || '';
+ // 处理 datetime-local 格式
+ if (item.due_date) {
+ // 尝试解析日期时间格式
+ let dueDate = item.due_date;
+ if (dueDate.includes('T')) {
+ // ISO 格式,截取到分钟
+ dueDate = dueDate.substring(0, 16);
+ } else if (dueDate.length === 10) {
+ // 只有日期,添加默认时间 00:00
+ dueDate = dueDate + 'T00:00';
+ }
+ document.getElementById('editDueDate').value = dueDate;
+ } else {
+ document.getElementById('editDueDate').value = '';
+ }
}
new bootstrap.Modal(document.getElementById('editModal')).show();
@@ -1592,6 +1606,64 @@ function formatDate(dateStr) {
return new Date(dateStr).toLocaleString('zh-CN');
}
+// 格式化截止时间(友好显示)
+function formatDueDate(dueDate) {
+ if (!dueDate) return '';
+
+ let date;
+ if (dueDate.includes('T')) {
+ date = new Date(dueDate);
+ } else if (dueDate.length === 10) {
+ // 只有日期
+ date = new Date(dueDate + 'T00:00:00');
+ } else {
+ date = new Date(dueDate);
+ }
+
+ // 格式化为友好格式
+ const now = new Date();
+ const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
+ const targetDay = new Date(date.getFullYear(), date.getMonth(), date.getDate());
+ const daysDiff = Math.floor((targetDay - today) / (1000 * 60 * 60 * 24));
+
+ let datePart;
+ if (daysDiff === 0) {
+ datePart = '今天';
+ } else if (daysDiff === 1) {
+ datePart = '明天';
+ } else if (daysDiff === -1) {
+ datePart = '昨天';
+ } else {
+ datePart = date.toLocaleDateString('zh-CN', {month: 'short', day: 'numeric'});
+ }
+
+ const timePart = date.toLocaleTimeString('zh-CN', {hour: '2-digit', minute: '2-digit'});
+
+ return `${datePart} ${timePart}`;
+}
+
+// 格式化截止时间(完整显示)
+function formatDueDateFull(dueDate) {
+ if (!dueDate) return '';
+
+ let date;
+ if (dueDate.includes('T')) {
+ date = new Date(dueDate);
+ } else if (dueDate.length === 10) {
+ date = new Date(dueDate + 'T00:00:00');
+ } else {
+ date = new Date(dueDate);
+ }
+
+ return date.toLocaleString('zh-CN', {
+ year: 'numeric',
+ month: 'long',
+ day: 'numeric',
+ hour: '2-digit',
+ minute: '2-digit'
+ });
+}
+
function escapeHtml(str) {
if (!str) return '';
return str.replace(/&/g, '&').replace(//g, '>');
@@ -2162,7 +2234,7 @@ function showRemindersModal() {
html += `
${item.title || '(无标题)'}
-
截止: ${item.due_date} | 已过期 ${item.days_overdue} 天
+
截止: ${formatDueDateFull(item.due_date)} | 已过期 ${item.days_overdue} 天