v1.3.2 — 日历同步批量查询+弹窗结果展示
- /api/calendar-sync-all 批量查询过去15天~未来15天 - 弹窗展示:加载动画 → 统计摘要 → 按日期分组日程列表 - 自动填充今日日程到早间立志 - 批量查询约需10秒,首次查询后同步写入缓存
This commit is contained in:
100
static/app.js
100
static/app.js
@@ -365,42 +365,94 @@
|
||||
/* ── 日历同步 ── */
|
||||
|
||||
window.syncCalendar = function() {
|
||||
var date = document.getElementById('check-date').value;
|
||||
var overlay = document.getElementById('sync-modal-overlay');
|
||||
var loading = document.getElementById('sync-loading');
|
||||
var resultsEl = document.getElementById('sync-results');
|
||||
var summary = document.getElementById('sync-summary');
|
||||
var list = document.getElementById('sync-list');
|
||||
var btn = document.querySelector('.btn-cal-sync');
|
||||
if (!overlay) return;
|
||||
|
||||
// 打开弹窗,显示加载中
|
||||
overlay.style.display = 'flex';
|
||||
loading.style.display = 'block';
|
||||
resultsEl.style.display = 'none';
|
||||
if (btn) { btn.style.opacity = '0.5'; btn.disabled = true; }
|
||||
fetch('/api/calendar-sync?date=' + encodeURIComponent(date))
|
||||
|
||||
fetch('/api/calendar-sync-all')
|
||||
.then(function(r){ return r.json(); })
|
||||
.then(function(res){
|
||||
loading.style.display = 'none';
|
||||
resultsEl.style.display = 'block';
|
||||
if (btn) { btn.style.opacity = '1'; btn.disabled = false; }
|
||||
if (!res.ok) { showToast(res.error || '同步失败', 'error'); return; }
|
||||
var events = res.data || [];
|
||||
if (events.length === 0) { showToast('今日无日程', 'info'); return; }
|
||||
var added = 0;
|
||||
events.forEach(function(e) {
|
||||
var text = '【' + e.time + '】' + e.summary;
|
||||
if (e.location) text += ' @' + e.location;
|
||||
var existing = document.querySelectorAll('#morning-list input[type="text"]');
|
||||
var already = false;
|
||||
existing.forEach(function(inp){ if (inp.value.indexOf(e.summary) >= 0) already = true; });
|
||||
if (already) return;
|
||||
var count = document.querySelectorAll('#morning-list .item-row').length;
|
||||
if (count >= 3) return;
|
||||
addMorningRow(text);
|
||||
added++;
|
||||
});
|
||||
if (added > 0) {
|
||||
showToast('已同步 ' + added + ' 条日程', 'info');
|
||||
triggerAutoSave();
|
||||
} else {
|
||||
showToast('日程已存在或已满', 'info');
|
||||
if (!res.ok) { summary.innerHTML = '<span style="color:var(--danger)">同步失败: ' + (res.error || '未知错误') + '</span>'; return; }
|
||||
var data = res.data || [];
|
||||
if (data.length === 0) {
|
||||
summary.innerHTML = '未查询到任何日程';
|
||||
return;
|
||||
}
|
||||
// 统计
|
||||
var totalDays = data.length;
|
||||
var totalEvents = 0;
|
||||
data.forEach(function(d){ totalEvents += d.events.length; });
|
||||
summary.innerHTML = '同步完成!共 <b>' + totalDays + '</b> 天有日程,合计 <b>' + totalEvents + '</b> 个会议';
|
||||
|
||||
// 渲染结果列表
|
||||
var html = '';
|
||||
data.forEach(function(day) {
|
||||
html += '<div class="sync-day">';
|
||||
html += '<div class="sync-day-header"><span>' + day.date + '</span></div>';
|
||||
day.events.forEach(function(e) {
|
||||
var timeStr = e.time ? ' (' + e.time + ')' : '';
|
||||
html += '<div class="sync-event">' +
|
||||
'<span class="sync-event-icon">📌</span>' +
|
||||
'<span class="sync-event-text">' + esc(e.summary) + '<span class="sync-event-time">' + esc(timeStr) + '</span></span>' +
|
||||
'</div>';
|
||||
});
|
||||
html += '</div>';
|
||||
});
|
||||
list.innerHTML = html;
|
||||
|
||||
// 自动填充今天到选中日期的日程
|
||||
autoFillTodayEvents(data);
|
||||
})
|
||||
.catch(function(){
|
||||
loading.style.display = 'none';
|
||||
resultsEl.style.display = 'block';
|
||||
summary.innerHTML = '<span style="color:var(--danger)">网络错误,请重试</span>';
|
||||
if (btn) { btn.style.opacity = '1'; btn.disabled = false; }
|
||||
showToast('同步失败', 'error');
|
||||
});
|
||||
};
|
||||
|
||||
function autoFillTodayEvents(data) {
|
||||
var todayDate = document.getElementById('check-date').value;
|
||||
var added = 0;
|
||||
data.forEach(function(day) {
|
||||
if (day.date !== todayDate) return;
|
||||
day.events.forEach(function(e) {
|
||||
var text = e.time ? '【' + e.time + '】' + e.summary : e.summary;
|
||||
if (e.location) text += ' @' + e.location;
|
||||
var existing = document.querySelectorAll('#morning-list input[type="text"]');
|
||||
var already = false;
|
||||
existing.forEach(function(inp){ if (inp.value.indexOf(e.summary) >= 0) already = true; });
|
||||
if (already) return;
|
||||
var count = document.querySelectorAll('#morning-list .item-row').length;
|
||||
if (count >= 3) return;
|
||||
addMorningRow(text);
|
||||
added++;
|
||||
});
|
||||
});
|
||||
if (added > 0) {
|
||||
showToast('已自动填充 ' + added + ' 条今日日程', 'info');
|
||||
triggerAutoSave();
|
||||
}
|
||||
}
|
||||
|
||||
window.closeSyncModal = function() {
|
||||
var overlay = document.getElementById('sync-modal-overlay');
|
||||
if (overlay) overlay.style.display = 'none';
|
||||
};
|
||||
|
||||
window.addMorning = function() {
|
||||
var count = document.querySelectorAll('#morning-list .item-row').length;
|
||||
if (count >= 3) { showToast('最多 3 条立志', 'error'); return; }
|
||||
|
||||
Reference in New Issue
Block a user