v1.3.0 — 钉钉日历同步
- 早间立志卡片新增日历同步按钮 - /api/calendar-sync 从缓存读取当日钉钉会议 - 自动填入立志:去重防重复,保留时间+地点格式 - 日历缓存: ~/.workbuddy/data/ziwei-power/calendar_cache.json
This commit is contained in:
@@ -362,6 +362,45 @@
|
||||
}
|
||||
}
|
||||
|
||||
/* ── 日历同步 ── */
|
||||
|
||||
window.syncCalendar = function() {
|
||||
var date = document.getElementById('check-date').value;
|
||||
var btn = document.querySelector('.btn-cal-sync');
|
||||
if (btn) { btn.style.opacity = '0.5'; btn.disabled = true; }
|
||||
fetch('/api/calendar-sync?date=' + encodeURIComponent(date))
|
||||
.then(function(r){ return r.json(); })
|
||||
.then(function(res){
|
||||
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');
|
||||
}
|
||||
})
|
||||
.catch(function(){
|
||||
if (btn) { btn.style.opacity = '1'; btn.disabled = false; }
|
||||
showToast('同步失败', 'error');
|
||||
});
|
||||
};
|
||||
|
||||
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