Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d2f64f98a1 | |||
| 161b93f368 | |||
| 31f2d8b428 | |||
| 5d6dd10dfa | |||
| d0f7b07260 | |||
| 0be768ca8e | |||
| 68ecb16303 | |||
| 82d928f497 | |||
| c99eca35f0 | |||
| 47b195ed1c | |||
| 1f1528979c | |||
| bcb24e474d |
25
README.md
25
README.md
@@ -141,6 +141,31 @@ xian-favor/
|
|||||||
|
|
||||||
## 版本历史
|
## 版本历史
|
||||||
|
|
||||||
|
- **v2.3.2** (2026-04-16): 搜索功能修复
|
||||||
|
- 修复 debounce 函数定义顺序问题
|
||||||
|
- 搜索框输入后可正常过滤列表
|
||||||
|
- **v2.3.1** (2026-04-16): 日期放到标题后面,不增加卡片高度
|
||||||
|
- 日期紧跟标题,同一行显示
|
||||||
|
- 格式紧凑:`04-16 11:09→04-16 12:00`
|
||||||
|
- **v2.3.0** (2026-04-16): 卡片显示创建和更新日期
|
||||||
|
- 每个收藏卡片底部显示日期
|
||||||
|
- 格式:04-16 11:09(月-日 时:分)
|
||||||
|
- 有更新时显示:创建 → 更新
|
||||||
|
- 字体更小更淡,不影响卡片高度
|
||||||
|
- **v2.2.0** (2026-04-16): 快捷添加按钮,一键选择类型
|
||||||
|
- 顶部按钮栏分离为4个快捷添加按钮(文本、链接、待办、专栏)
|
||||||
|
- 点击直接进入对应类型的添加弹窗
|
||||||
|
- 弹窗标题显示类型图标和名称
|
||||||
|
- 不再需要下拉选择类型,操作更快捷
|
||||||
|
- **v2.1.0** (2026-04-16): 待办截止时间支持日期+时间
|
||||||
|
- 截止日期改为日期时间选择器
|
||||||
|
- 列表显示友好格式:今天 18:30、明天 09:00 等
|
||||||
|
- 详情页显示完整格式:2026年4月16日 18:30
|
||||||
|
- 后端支持多种日期格式解析
|
||||||
|
- 只有日期的待办视为当天 23:59 到期
|
||||||
|
- **v2.0.1** (2026-04-16): 转换弹窗优化
|
||||||
|
- 内容预览保留换行格式,提高可读性
|
||||||
|
- 转换方式默认改为复制创建
|
||||||
- **v2.0.0** (2026-04-16): 收藏转待办功能(大版本更新)
|
- **v2.0.0** (2026-04-16): 收藏转待办功能(大版本更新)
|
||||||
- 新增 `/api/items/<id>/convert` API
|
- 新增 `/api/items/<id>/convert` API
|
||||||
- **直接转换**:原收藏变为待办,数据合并
|
- **直接转换**:原收藏变为待办,数据合并
|
||||||
|
|||||||
@@ -539,11 +539,11 @@ INDEX_TEMPLATE = '''
|
|||||||
.content { padding: 20px; }
|
.content { padding: 20px; }
|
||||||
.card { margin-bottom: 8px; transition: transform 0.2s; }
|
.card { margin-bottom: 8px; transition: transform 0.2s; }
|
||||||
.card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
|
.card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
|
||||||
.card-body { padding: 10px 15px; }
|
.card-body { padding: 8px 12px; }
|
||||||
.tag { margin-right: 5px; }
|
.tag { margin-right: 5px; }
|
||||||
.item-card { font-size: 14px; }
|
.item-card { font-size: 14px; }
|
||||||
.item-card h6 { font-size: 14px; margin-bottom: 4px; }
|
.item-card h6 { font-size: 14px; margin-bottom: 2px; }
|
||||||
.item-card p { margin-bottom: 4px; }
|
.item-card p { margin-bottom: 2px; }
|
||||||
.item-card .text-muted.small { font-size: 12px; }
|
.item-card .text-muted.small { font-size: 12px; }
|
||||||
.type-text { border-left: 4px solid #17a2b8; }
|
.type-text { border-left: 4px solid #17a2b8; }
|
||||||
.type-link { border-left: 4px solid #28a745; }
|
.type-link { border-left: 4px solid #28a745; }
|
||||||
@@ -609,12 +609,21 @@ INDEX_TEMPLATE = '''
|
|||||||
<button class="btn btn-outline-info me-2" onclick="showAIAddModal()" title="AI自动添加">
|
<button class="btn btn-outline-info me-2" onclick="showAIAddModal()" title="AI自动添加">
|
||||||
<i class="bi bi-robot"></i> AI添加
|
<i class="bi bi-robot"></i> AI添加
|
||||||
</button>
|
</button>
|
||||||
|
<button class="btn btn-outline-secondary me-1" onclick="showAddModal('text')" title="添加文本">
|
||||||
|
<i class="bi bi-file-text"></i>
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-outline-success me-1" onclick="showAddModal('link')" title="添加链接">
|
||||||
|
<i class="bi bi-link-45deg"></i>
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-outline-warning me-1" onclick="showAddModal('todo')" title="添加待办">
|
||||||
|
<i class="bi bi-check2-square"></i>
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-outline-primary me-1" onclick="showAddModal('column')" title="添加专栏">
|
||||||
|
<i class="bi bi-newspaper"></i>
|
||||||
|
</button>
|
||||||
<button class="btn btn-outline-success me-2" onclick="exportData()" title="导出JSON">
|
<button class="btn btn-outline-success me-2" onclick="exportData()" title="导出JSON">
|
||||||
<i class="bi bi-download"></i> 导出
|
<i class="bi bi-download"></i> 导出
|
||||||
</button>
|
</button>
|
||||||
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addModal">
|
|
||||||
<i class="bi bi-plus-lg"></i> 添加
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 统计卡片 -->
|
<!-- 统计卡片 -->
|
||||||
@@ -667,20 +676,15 @@ INDEX_TEMPLATE = '''
|
|||||||
<div class="modal-dialog modal-lg">
|
<div class="modal-dialog modal-lg">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h5 class="modal-title">添加条目</h5>
|
<h5 class="modal-title">
|
||||||
|
<span id="addModalIcon"></span>
|
||||||
|
<span id="addModalTitle">添加条目</span>
|
||||||
|
</h5>
|
||||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<form id="addForm">
|
<form id="addForm">
|
||||||
<div class="mb-3">
|
<input type="hidden" id="addType" value="text">
|
||||||
<label class="form-label">类型</label>
|
|
||||||
<select id="addType" class="form-select">
|
|
||||||
<option value="text">📝 文本</option>
|
|
||||||
<option value="link">🔗 链接</option>
|
|
||||||
<option value="column">📰 专栏</option>
|
|
||||||
<option value="todo">✅ 待办</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">标题</label>
|
<label class="form-label">标题</label>
|
||||||
<input type="text" id="addTitle" class="form-control" placeholder="可选">
|
<input type="text" id="addTitle" class="form-control" placeholder="可选">
|
||||||
@@ -691,11 +695,11 @@ INDEX_TEMPLATE = '''
|
|||||||
</div>
|
</div>
|
||||||
<div class="mb-3" id="urlGroup" style="display:none;">
|
<div class="mb-3" id="urlGroup" style="display:none;">
|
||||||
<label class="form-label">URL</label>
|
<label class="form-label">URL</label>
|
||||||
<input type="url" id="addUrl" class="form-control">
|
<input type="url" id="addUrl" class="form-control" placeholder="https://...">
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3" id="sourceGroup" style="display:none;">
|
<div class="mb-3" id="sourceGroup" style="display:none;">
|
||||||
<label class="form-label">来源</label>
|
<label class="form-label">来源</label>
|
||||||
<input type="text" id="addSource" class="form-control">
|
<input type="text" id="addSource" class="form-control" placeholder="专栏来源">
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3" id="todoFields" style="display:none;">
|
<div class="mb-3" id="todoFields" style="display:none;">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@@ -718,8 +722,8 @@ INDEX_TEMPLATE = '''
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
<label class="form-label">截止日期</label>
|
<label class="form-label">截止时间</label>
|
||||||
<input type="date" id="addDueDate" class="form-control">
|
<input type="datetime-local" id="addDueDate" class="form-control">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
@@ -825,8 +829,8 @@ INDEX_TEMPLATE = '''
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
<label class="form-label">截止日期</label>
|
<label class="form-label">截止时间</label>
|
||||||
<input type="date" id="editDueDate" class="form-control">
|
<input type="datetime-local" id="editDueDate" class="form-control">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
@@ -1060,8 +1064,8 @@ INDEX_TEMPLATE = '''
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<label class="form-label">截止日期</label>
|
<label class="form-label">截止时间</label>
|
||||||
<input type="date" id="convertDueDate" class="form-control">
|
<input type="datetime-local" id="convertDueDate" class="form-control">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -1086,9 +1090,23 @@ INDEX_TEMPLATE = '''
|
|||||||
<script>
|
<script>
|
||||||
const API_BASE = '/api';
|
const API_BASE = '/api';
|
||||||
let currentFilter = { type: '', status: '' };
|
let currentFilter = { type: '', status: '' };
|
||||||
|
let currentPage = 1;
|
||||||
|
const pageSize = 20;
|
||||||
|
function debounce(fn, delay) {
|
||||||
|
let timer;
|
||||||
|
return function(...args) {
|
||||||
|
clearTimeout(timer);
|
||||||
|
timer = setTimeout(() => fn.apply(this, args), delay);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// 初始化
|
// 初始化
|
||||||
document.addEventListener('DOMContentLoaded', async () => {
|
document.addEventListener('DOMContentLoaded', async () => {
|
||||||
|
// 确保初始状态清空
|
||||||
|
document.getElementById('searchInput').value = '';
|
||||||
|
document.getElementById('typeFilter').value = '';
|
||||||
|
currentFilter = { type: '', status: '' };
|
||||||
|
|
||||||
await loadStats(); // 先加载统计,确保总数可用
|
await loadStats(); // 先加载统计,确保总数可用
|
||||||
loadItems();
|
loadItems();
|
||||||
loadTags();
|
loadTags();
|
||||||
@@ -1104,15 +1122,6 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||||||
// 标签搜索实时过滤
|
// 标签搜索实时过滤
|
||||||
document.getElementById('tagSearch')?.addEventListener('input', debounce(loadTagManagerList, 300));
|
document.getElementById('tagSearch')?.addEventListener('input', debounce(loadTagManagerList, 300));
|
||||||
|
|
||||||
// 类型切换时显示/隐藏字段
|
|
||||||
document.getElementById('addType').addEventListener('change', (e) => {
|
|
||||||
const type = e.target.value;
|
|
||||||
document.getElementById('contentGroup').style.display = type === 'text' ? 'block' : 'none';
|
|
||||||
document.getElementById('urlGroup').style.display = ['link', 'column'].includes(type) ? 'block' : 'none';
|
|
||||||
document.getElementById('sourceGroup').style.display = type === 'column' ? 'block' : 'none';
|
|
||||||
document.getElementById('todoFields').style.display = type === 'todo' ? 'block' : 'none';
|
|
||||||
});
|
|
||||||
|
|
||||||
// 编辑时类型切换
|
// 编辑时类型切换
|
||||||
document.getElementById('editType').addEventListener('change', (e) => {
|
document.getElementById('editType').addEventListener('change', (e) => {
|
||||||
updateEditFieldsByType(e.target.value);
|
updateEditFieldsByType(e.target.value);
|
||||||
@@ -1148,9 +1157,6 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 加载列表
|
// 加载列表
|
||||||
let currentPage = 1;
|
|
||||||
const pageSize = 20;
|
|
||||||
|
|
||||||
async function loadItems(page = 1) {
|
async function loadItems(page = 1) {
|
||||||
currentPage = page;
|
currentPage = page;
|
||||||
const keyword = document.getElementById('searchInput').value;
|
const keyword = document.getElementById('searchInput').value;
|
||||||
@@ -1184,10 +1190,13 @@ function renderItems(items) {
|
|||||||
<h6 class="card-title text-truncate mb-1 ${item.type === 'todo' && item.status === 'completed' ? 'text-muted' : ''}">
|
<h6 class="card-title text-truncate mb-1 ${item.type === 'todo' && item.status === 'completed' ? 'text-muted' : ''}">
|
||||||
${getTypeIcon(item.type)} ${item.title || truncate(item.content || item.url, 30)}
|
${getTypeIcon(item.type)} ${item.title || truncate(item.content || item.url, 30)}
|
||||||
${item.type === 'todo' && item.status === 'completed' ? ' ✓' : ''}
|
${item.type === 'todo' && item.status === 'completed' ? ' ✓' : ''}
|
||||||
|
<span style="font-size:10px; opacity:0.5; margin-left:8px;">
|
||||||
|
${formatShortDate(item.created_at)}${item.updated_at && item.updated_at !== item.created_at ? '→' + formatShortDate(item.updated_at) : ''}
|
||||||
|
</span>
|
||||||
</h6>
|
</h6>
|
||||||
<p class="card-text text-muted small mb-0 text-truncate" style="font-size:12px;">
|
<p class="card-text text-muted small mb-0 text-truncate" style="font-size:12px;">
|
||||||
${item.url ? truncate(item.url, 50) : item.content ? truncate(item.content, 50) : item.note ? truncate(item.note, 50) : ''}
|
${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) : ''}` : ''}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="d-flex align-items-center gap-1 flex-wrap ms-2" onclick="event.stopPropagation();">
|
<div class="d-flex align-items-center gap-1 flex-wrap ms-2" onclick="event.stopPropagation();">
|
||||||
@@ -1270,6 +1279,37 @@ async function refreshData() {
|
|||||||
loadItems(currentPage);
|
loadItems(currentPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============ 添加功能 ============
|
||||||
|
|
||||||
|
// 快捷添加按钮
|
||||||
|
function showAddModal(type) {
|
||||||
|
// 设置类型
|
||||||
|
document.getElementById('addType').value = type;
|
||||||
|
|
||||||
|
// 设置弹窗标题和图标
|
||||||
|
const typeInfo = {
|
||||||
|
text: { icon: '📝', title: '添加文本' },
|
||||||
|
link: { icon: '🔗', title: '添加链接' },
|
||||||
|
column: { icon: '📰', title: '添加专栏' },
|
||||||
|
todo: { icon: '✅', title: '添加待办' }
|
||||||
|
};
|
||||||
|
|
||||||
|
document.getElementById('addModalIcon').textContent = typeInfo[type].icon;
|
||||||
|
document.getElementById('addModalTitle').textContent = typeInfo[type].title;
|
||||||
|
|
||||||
|
// 显示/隐藏对应字段
|
||||||
|
document.getElementById('contentGroup').style.display = type === 'text' ? 'block' : 'none';
|
||||||
|
document.getElementById('urlGroup').style.display = ['link', 'column'].includes(type) ? 'block' : 'none';
|
||||||
|
document.getElementById('sourceGroup').style.display = type === 'column' ? 'block' : 'none';
|
||||||
|
document.getElementById('todoFields').style.display = type === 'todo' ? 'block' : 'none';
|
||||||
|
|
||||||
|
// 清空表单
|
||||||
|
document.getElementById('addForm').reset();
|
||||||
|
|
||||||
|
// 打开弹窗
|
||||||
|
new bootstrap.Modal(document.getElementById('addModal')).show();
|
||||||
|
}
|
||||||
|
|
||||||
// 添加条目
|
// 添加条目
|
||||||
async function addItem() {
|
async function addItem() {
|
||||||
const type = document.getElementById('addType').value;
|
const type = document.getElementById('addType').value;
|
||||||
@@ -1437,7 +1477,7 @@ async function showDetail(id) {
|
|||||||
html += `<div class="mb-3"><strong>状态:</strong> ${getStatusLabel(item.status)}</div>`;
|
html += `<div class="mb-3"><strong>状态:</strong> ${getStatusLabel(item.status)}</div>`;
|
||||||
html += `<div class="mb-3"><strong>优先级:</strong> ${getPriorityLabel(item.priority)}</div>`;
|
html += `<div class="mb-3"><strong>优先级:</strong> ${getPriorityLabel(item.priority)}</div>`;
|
||||||
if (item.due_date) {
|
if (item.due_date) {
|
||||||
html += `<div class="mb-3"><strong>截止日期:</strong> ${item.due_date}</div>`;
|
html += `<div class="mb-3"><strong>截止时间:</strong> ${formatDueDateFull(item.due_date)}</div>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1509,7 +1549,21 @@ async function openEditModal(id) {
|
|||||||
if (type === 'todo') {
|
if (type === 'todo') {
|
||||||
document.getElementById('editStatus').value = item.status;
|
document.getElementById('editStatus').value = item.status;
|
||||||
document.getElementById('editPriority').value = item.priority;
|
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();
|
new bootstrap.Modal(document.getElementById('editModal')).show();
|
||||||
@@ -1588,10 +1642,79 @@ function truncate(str, len) {
|
|||||||
return str && str.length > len ? str.substring(0, len) + '...' : str || '';
|
return str && str.length > len ? str.substring(0, len) + '...' : str || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 简短日期格式(用于卡片显示)
|
||||||
|
function formatShortDate(dateStr) {
|
||||||
|
if (!dateStr) return '';
|
||||||
|
const date = new Date(dateStr);
|
||||||
|
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||||
|
const day = String(date.getDate()).padStart(2, '0');
|
||||||
|
const hour = String(date.getHours()).padStart(2, '0');
|
||||||
|
const min = String(date.getMinutes()).padStart(2, '0');
|
||||||
|
return `${month}-${day} ${hour}:${min}`;
|
||||||
|
}
|
||||||
|
|
||||||
function formatDate(dateStr) {
|
function formatDate(dateStr) {
|
||||||
return new Date(dateStr).toLocaleString('zh-CN');
|
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) {
|
function escapeHtml(str) {
|
||||||
if (!str) return '';
|
if (!str) return '';
|
||||||
return str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
return str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
||||||
@@ -2084,14 +2207,6 @@ async function sendItemEmail() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function debounce(fn, delay) {
|
|
||||||
let timer;
|
|
||||||
return function(...args) {
|
|
||||||
clearTimeout(timer);
|
|
||||||
timer = setTimeout(() => fn.apply(this, args), delay);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// ============ 提醒功能 ============
|
// ============ 提醒功能 ============
|
||||||
|
|
||||||
let reminderData = null;
|
let reminderData = null;
|
||||||
@@ -2162,7 +2277,7 @@ function showRemindersModal() {
|
|||||||
html += `<div class="list-group-item list-group-item-danger d-flex justify-content-between align-items-center">
|
html += `<div class="list-group-item list-group-item-danger d-flex justify-content-between align-items-center">
|
||||||
<div>
|
<div>
|
||||||
<strong>${item.title || '(无标题)'}</strong>
|
<strong>${item.title || '(无标题)'}</strong>
|
||||||
<br><small class="text-muted">截止: ${item.due_date} | 已过期 ${item.days_overdue} 天</small>
|
<br><small class="text-muted">截止: ${formatDueDateFull(item.due_date)} | 已过期 ${item.days_overdue} 天</small>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<button class="btn btn-sm btn-success" onclick="completeReminder(${item.id})" title="完成">
|
<button class="btn btn-sm btn-success" onclick="completeReminder(${item.id})" title="完成">
|
||||||
@@ -2185,7 +2300,7 @@ function showRemindersModal() {
|
|||||||
html += `<div class="list-group-item list-group-item-warning d-flex justify-content-between align-items-center">
|
html += `<div class="list-group-item list-group-item-warning d-flex justify-content-between align-items-center">
|
||||||
<div>
|
<div>
|
||||||
<strong>${item.title || '(无标题)'}</strong>
|
<strong>${item.title || '(无标题)'}</strong>
|
||||||
<br><small class="text-muted">截止: ${item.due_date}</small>
|
<br><small class="text-muted">截止: ${formatDueDateFull(item.due_date)}</small>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<button class="btn btn-sm btn-success" onclick="completeReminder(${item.id})" title="完成">
|
<button class="btn btn-sm btn-success" onclick="completeReminder(${item.id})" title="完成">
|
||||||
@@ -2208,7 +2323,7 @@ function showRemindersModal() {
|
|||||||
html += `<div class="list-group-item list-group-item-info d-flex justify-content-between align-items-center">
|
html += `<div class="list-group-item list-group-item-info d-flex justify-content-between align-items-center">
|
||||||
<div>
|
<div>
|
||||||
<strong>${item.title || '(无标题)'}</strong>
|
<strong>${item.title || '(无标题)'}</strong>
|
||||||
<br><small class="text-muted">截止: ${item.due_date}</small>
|
<br><small class="text-muted">截止: ${formatDueDateFull(item.due_date)}</small>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<button class="btn btn-sm btn-success" onclick="completeReminder(${item.id})" title="完成">
|
<button class="btn btn-sm btn-success" onclick="completeReminder(${item.id})" title="完成">
|
||||||
|
|||||||
@@ -464,21 +464,36 @@ class Database:
|
|||||||
item['tags'] = self._get_item_tags(conn, item['id'])
|
item['tags'] = self._get_item_tags(conn, item['id'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
due_date = datetime.strptime(item['due_date'], '%Y-%m-%d')
|
due_date_str = item['due_date']
|
||||||
# 计算距离到期的时间
|
# 支持多种日期格式
|
||||||
days_left = (due_date.date() - now.date()).days
|
if 'T' in due_date_str:
|
||||||
|
# ISO 格式:2026-04-16T14:30
|
||||||
|
due_date = datetime.strptime(due_date_str[:16], '%Y-%m-%dT%H:%M')
|
||||||
|
elif len(due_date_str) == 10:
|
||||||
|
# 只有日期:2026-04-16,视为当天 23:59:59
|
||||||
|
due_date = datetime.strptime(due_date_str, '%Y-%m-%d').replace(hour=23, minute=59, second=59)
|
||||||
|
else:
|
||||||
|
# 其他格式,尝试解析
|
||||||
|
due_date = datetime.strptime(due_date_str.split('.')[0], '%Y-%m-%dT%H:%M:%S')
|
||||||
|
|
||||||
if days_left < 0:
|
# 计算距离到期的时间
|
||||||
|
time_left = due_date - now
|
||||||
|
|
||||||
|
if time_left.total_seconds() < 0:
|
||||||
# 已过期
|
# 已过期
|
||||||
item['days_overdue'] = abs(days_left)
|
days_overdue = abs(int(time_left.total_seconds() / 86400))
|
||||||
|
item['days_overdue'] = days_overdue
|
||||||
reminders['overdue'].append(item)
|
reminders['overdue'].append(item)
|
||||||
elif days_left == 0:
|
elif time_left.total_seconds() < 86400: # 24小时内
|
||||||
# 今天到期
|
# 判断是今天还是明天
|
||||||
|
if due_date.date() == now.date():
|
||||||
|
reminders['due_today'].append(item)
|
||||||
|
else:
|
||||||
|
reminders['due_soon'].append(item)
|
||||||
|
elif due_date.date() == now.date():
|
||||||
|
# 今天到期(超过24小时的情况,比如现在凌晨,截止时间是晚上)
|
||||||
reminders['due_today'].append(item)
|
reminders['due_today'].append(item)
|
||||||
elif days_left == 1:
|
except (ValueError, AttributeError) as e:
|
||||||
# 明天到期(24小时内)
|
|
||||||
reminders['due_soon'].append(item)
|
|
||||||
except ValueError:
|
|
||||||
# 日期格式错误,跳过
|
# 日期格式错误,跳过
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user