Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8188364813 | ||
|
|
b50d8e17e2 | ||
|
|
c70aeff2ed | ||
|
|
f63ab8b8ea | ||
|
|
b48e95c800 |
5
app.py
5
app.py
@@ -136,8 +136,7 @@ def compute_stats():
|
||||
pillar = classify_auto(name)
|
||||
all_study_items.append({
|
||||
'name': name.strip(),
|
||||
'done': si.get('done', False) if isinstance(si, dict) else False,
|
||||
'note': si.get('note', '') if isinstance(si, dict) else '',
|
||||
'count': si.get('count', 0) if isinstance(si, dict) else 0,
|
||||
'pillar': pillar
|
||||
})
|
||||
|
||||
@@ -149,7 +148,7 @@ def compute_stats():
|
||||
isinstance(x, str) and x.strip() or
|
||||
isinstance(x, dict) and (x.get('mistake', '') or '').strip()
|
||||
))
|
||||
study_count = sum(1 for x in study if x.get('done'))
|
||||
study_count = sum(1 for x in study if x.get('count', 0) > 0)
|
||||
|
||||
total_morning += morning_count
|
||||
total_evening += evening_count
|
||||
|
||||
104
static/app.js
104
static/app.js
@@ -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, last_checkin_date: sCards[k].dataset.lastDate || '' });
|
||||
}
|
||||
|
||||
return { morning: morningItems, evening: eveningItems, study: studyItems };
|
||||
@@ -295,16 +291,25 @@
|
||||
addEveningRow(item.mistake || '', item.improvement || '');
|
||||
}
|
||||
|
||||
// 勤学 — 渲染预设项目并回填状态
|
||||
// 勤学 — 渲染已保存习惯 + 未渲染预设
|
||||
var studyMap = {};
|
||||
for (var si=0; si<study.length; si++) {
|
||||
studyMap[study[si].name] = study[si];
|
||||
}
|
||||
document.getElementById('study-list').innerHTML = '';
|
||||
var rendered = {};
|
||||
document.getElementById('study-cards').innerHTML = '';
|
||||
for (var sk=0; sk<study.length; sk++) {
|
||||
var item = study[sk];
|
||||
if (item.name) {
|
||||
renderStudyCard(item.name, item.count || 0, item.last_checkin_date || '');
|
||||
rendered[item.name] = true;
|
||||
}
|
||||
}
|
||||
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 || '');
|
||||
if (!rendered[sName]) {
|
||||
renderStudyCard(sName, 0, '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,35 +352,60 @@
|
||||
container.appendChild(div);
|
||||
}
|
||||
|
||||
/* ── 勤学预设项目 ── */
|
||||
/* ── 勤学打卡卡片 ── */
|
||||
|
||||
function addPresetItem(name, done, note) {
|
||||
var container = document.getElementById('study-list');
|
||||
function renderStudyCard(name, count, lastDate) {
|
||||
var container = document.getElementById('study-cards');
|
||||
var today = fmtDate(new Date());
|
||||
var checked = count > 0;
|
||||
var checkedToday = lastDate === today;
|
||||
var btnText = checkedToday ? '已打卡' : '打卡';
|
||||
var div = document.createElement('div');
|
||||
div.className = 'preset-item' + (done ? ' active' : '');
|
||||
var noteEsc = esc(note || '');
|
||||
div.className = 'study-card' + (checked ? ' checked' : '');
|
||||
div.setAttribute('data-last-date', lastDate || '');
|
||||
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>';
|
||||
'<button class="study-card-del" onclick="deleteStudyItem(this)" title="删除">×</button>' +
|
||||
'<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' + (checkedToday ? ' done' : '') + '" onclick="checkinStudy(this)">' + btnText + '</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.addStudyItem = function() {
|
||||
var name = prompt('请输入新习惯名称:');
|
||||
if (!name || !name.trim()) return;
|
||||
renderStudyCard(name.trim(), 0, '');
|
||||
triggerAutoSave();
|
||||
};
|
||||
|
||||
window.deleteStudyItem = function(btn) {
|
||||
var card = btn.closest('.study-card');
|
||||
var nameEl = card.querySelector('.study-card-name');
|
||||
if (nameEl && !confirm('确定删除「' + nameEl.textContent + '」?')) return;
|
||||
card.remove();
|
||||
triggerAutoSave();
|
||||
};
|
||||
|
||||
window.checkinStudy = function(btn) {
|
||||
var card = btn.closest('.study-card');
|
||||
var today = fmtDate(new Date());
|
||||
if (card.dataset.lastDate === today) { showToast('今天已打卡', 'info'); return; }
|
||||
var countEl = card.querySelector('.study-card-count');
|
||||
var count = parseInt(countEl.textContent) + 1;
|
||||
countEl.textContent = count;
|
||||
card.dataset.lastDate = today;
|
||||
card.classList.add('checked');
|
||||
btn.classList.add('done');
|
||||
btn.textContent = '已打卡';
|
||||
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 +477,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 +527,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 +1047,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 +1065,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 +
|
||||
|
||||
@@ -832,9 +832,8 @@ body {
|
||||
}
|
||||
|
||||
/* 编辑模式下才显示的元素 */
|
||||
.edit-only { display: none; }
|
||||
.card.editing .edit-only { display: flex; }
|
||||
.card.editing .btn-del { display: inline-flex; }
|
||||
.edit-only { display: flex; }
|
||||
.btn-edit-toggle { display: none; }
|
||||
|
||||
/* 默认隐藏删除按钮 */
|
||||
.btn-del { display: none; }
|
||||
@@ -1783,3 +1782,18 @@ body {
|
||||
@media (max-width: 900px) {
|
||||
.quad-grid { grid-template-columns: 1fr; grid-template-rows: auto; }
|
||||
}
|
||||
|
||||
/* 勤学打卡卡片 - 3×3网格 */
|
||||
#study-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
|
||||
.study-card { display:flex; flex-direction:column; align-items:center; gap:8px; padding:14px 10px; border:1px solid var(--border); border-radius:var(--radius-sm); background:var(--card); transition:all 0.15s; text-align:center; }
|
||||
.study-card.checked { border-color:var(--success); background:var(--success-light); }
|
||||
.study-card-info { display:flex; flex-direction:column; align-items:center; gap:4px; }
|
||||
.study-card-name { font-size:12px; color:var(--text); font-weight:500; line-height:1.3; }
|
||||
.study-card-count { font-size:18px; color:var(--text-muted); font-weight:700; background:var(--bg); border-radius:50%; width:32px; height:32px; display:flex; align-items:center; justify-content:center; }
|
||||
.study-card.checked .study-card-count { background:var(--success); color:#FFF; }
|
||||
.study-card-btn { padding:5px 12px; border:1px solid var(--primary); border-radius:var(--radius-sm); background:transparent; color:var(--primary); font-size:12px; font-weight:500; cursor:pointer; transition:all 0.15s; font-family:inherit; }
|
||||
.study-card-btn:hover { background:var(--primary); color:#FFF; }
|
||||
.study-card-btn.done { background:var(--success-light); color:var(--success); border-color:var(--success); cursor:default; }
|
||||
.study-card-del { position:absolute; top:4px; right:4px; border:none; background:none; color:var(--text-muted); cursor:pointer; font-size:14px; padding:2px 6px; border-radius:4px; line-height:1; }
|
||||
.study-card-del:hover { background:var(--danger-light); color:var(--danger); }
|
||||
.study-card { position:relative; }
|
||||
|
||||
@@ -152,7 +152,7 @@
|
||||
<svg class="icon-sm"><use href="#icon-pencil"/></svg>
|
||||
</button>
|
||||
</div>
|
||||
<p class="card-desc">本周最重要的 1~3 件事</p>
|
||||
<p class="card-desc">本周最重要的事</p>
|
||||
<div id="morning-list"></div>
|
||||
<button class="btn-add edit-only" onclick="addMorning()">
|
||||
<svg class="icon-sm"><use href="#icon-plus"/></svg> 增加一条
|
||||
@@ -180,7 +180,10 @@
|
||||
<h3>勤学打卡</h3>
|
||||
</div>
|
||||
<p class="card-desc">本周修行清单</p>
|
||||
<div id="study-list"></div>
|
||||
<div id="study-cards"></div>
|
||||
<button class="btn-add" onclick="addStudyItem()" style="margin-top:10px">
|
||||
<svg class="icon-sm"><use href="#icon-plus"/></svg> 增加习惯
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div><!-- /daily-main -->
|
||||
|
||||
Reference in New Issue
Block a user