v2.1.11 — 本周重点去3条限制 + 勤学改为卡片打卡按钮

This commit is contained in:
mac
2026-07-27 08:53:48 +08:00
parent bf1be1aa9f
commit b48e95c800
4 changed files with 44 additions and 42 deletions
+30 -37
View File
@@ -257,17 +257,13 @@
}
var studyItems = [];
var pItems = document.querySelectorAll('#study-list .preset-item');
for (var k=0; k<pItems.length; k++) {
var cb = pItems[k].querySelector('input[type="checkbox"]');
var noteEl = pItems[k].querySelector('.preset-note');
var nameEl = pItems[k].querySelector('.preset-name');
var name = nameEl ? nameEl.textContent : '';
if (cb && cb.checked) {
studyItems.push({ name: name, done: true, note: noteEl ? noteEl.value.trim() : '' });
} else {
studyItems.push({ name: name, done: false, note: '' });
}
var sCards = document.querySelectorAll('#study-cards .study-card');
for (var k=0; k<sCards.length; k++) {
var nameEl = sCards[k].querySelector('.study-card-name');
var countEl = sCards[k].querySelector('.study-card-count');
var name = nameEl ? nameEl.textContent.trim() : '';
var count = parseInt(countEl ? countEl.textContent : '0') || 0;
studyItems.push({ name: name, count: count });
}
return { morning: morningItems, evening: eveningItems, study: studyItems };
@@ -300,11 +296,11 @@
for (var si=0; si<study.length; si++) {
studyMap[study[si].name] = study[si];
}
document.getElementById('study-list').innerHTML = '';
document.getElementById('study-cards').innerHTML = '';
for (var sp=0; sp<PRESET_STUDY_ITEMS.length; sp++) {
var sName = PRESET_STUDY_ITEMS[sp];
var saved = studyMap[sName] || { done: false, note: '' };
addPresetItem(sName, saved.done, saved.note || '');
var saved = studyMap[sName] || { count: 0 };
renderStudyCard(sName, saved.count || 0);
}
}
@@ -347,35 +343,34 @@
container.appendChild(div);
}
/* ── 勤学预设项目 ── */
/* ── 勤学打卡卡片 ── */
function addPresetItem(name, done, note) {
var container = document.getElementById('study-list');
function renderStudyCard(name, count) {
var container = document.getElementById('study-cards');
var div = document.createElement('div');
div.className = 'preset-item' + (done ? ' active' : '');
var noteEsc = esc(note || '');
div.className = 'study-card' + (count > 0 ? ' checked' : '');
div.innerHTML =
'<label class="preset-check">' +
'<input type="checkbox"' + (done ? ' checked' : '') + ' onchange="togglePresetNote(this)">' +
'<span class="preset-name">' + esc(name) + '</span>' +
'</label>' +
'<textarea class="preset-note" placeholder="一句话备注…">' + noteEsc + '</textarea>';
'<div class="study-card-info">' +
'<span class="study-card-name">' + esc(name) + '</span>' +
'<span class="study-card-count">' + count + '</span>' +
'</div>' +
'<button class="study-card-btn" onclick="checkinStudy(this)">打卡</button>';
container.appendChild(div);
}
window.togglePresetNote = function(cb) {
var item = cb.closest('.preset-item');
if (item) {
if (cb.checked) item.classList.add('active');
else { item.classList.remove('active'); item.querySelector('.preset-note').value = ''; }
}
window.checkinStudy = function(btn) {
var card = btn.closest('.study-card');
var countEl = card.querySelector('.study-card-count');
var count = parseInt(countEl.textContent) + 1;
countEl.textContent = count;
if (count > 0) card.classList.add('checked');
triggerAutoSave();
};
function initStudyPresets() {
document.getElementById('study-list').innerHTML = '';
document.getElementById('study-cards').innerHTML = '';
for (var i=0; i<PRESET_STUDY_ITEMS.length; i++) {
addPresetItem(PRESET_STUDY_ITEMS[i], false, '');
renderStudyCard(PRESET_STUDY_ITEMS[i], 0);
}
}
@@ -447,8 +442,6 @@
};
window.addMorning = function() {
var count = document.querySelectorAll('#morning-list .item-row').length;
if (count >= 3) { showToast('最多 3 条立志', 'error'); return; }
addMorningRow('');
};
window.addEvening = function() {
@@ -499,7 +492,7 @@
if (lastSavedWeek && lastSavedData !== null && currentStr !== lastSavedData) {
var hasContent = currentData.morning.some(function(x){return x && x.trim();}) ||
currentData.evening.some(function(x){return (x.mistake||'').trim() || (x.improvement||'').trim();}) ||
currentData.study.some(function(x){return x.done;});
currentData.study.some(function(x){return x.count > 0;});
if (hasContent) {
apiSaveCheckin(lastSavedWeek, currentData, function(){});
}
@@ -1019,7 +1012,7 @@
(info.evening_items || []).forEach(function(ei){ items.push({pillar: p, text: ei.mistake || ei.improvement, improvement: ei.improvement, type: 'evening'}); });
}
if (blueprintFilter === 'all' || blueprintFilter === 'study') {
(info.study_items || []).forEach(function(si){ items.push({pillar: p, text: si.name, type: 'study', done: si.done, note: si.note}); });
(info.study_items || []).forEach(function(si){ items.push({pillar: p, text: si.name, type: 'study', count: si.count}); });
}
});
if (items.length === 0) {
@@ -1037,7 +1030,7 @@
items.forEach(function(item){
var dot = '<span class="bp-pillar-dot" style="background:' + (pillarColors[item.pillar.name] || '#94A3B8') + '"></span>';
var extra = '';
if (item.type === 'study' && item.note) extra = '<span class="bp-item-note">' + esc(item.note) + '</span>';
if (item.type === 'study' && item.count > 0) extra = '<span class="bp-item-note">打卡 ' + item.count + '</span>';
if (item.type === 'evening' && item.improvement) extra = '<span class="bp-item-note evening">→ ' + esc(item.improvement) + '</span>';
html += '<div class="bp-list-item">' +
dot +