Compare commits

..

3 Commits

3 changed files with 60 additions and 13 deletions

View File

@@ -291,16 +291,25 @@
addEveningRow(item.mistake || '', item.improvement || '');
}
// 勤学 — 渲染预设项目并回填状态
// 勤学 — 渲染已保存习惯 + 未渲染预设
var studyMap = {};
for (var si=0; si<study.length; si++) {
studyMap[study[si].name] = study[si];
}
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] || { count: 0 };
renderStudyCard(sName, saved.count || 0, saved.last_checkin_date || '');
if (!rendered[sName]) {
renderStudyCard(sName, 0, '');
}
}
}
@@ -355,6 +364,7 @@
div.className = 'study-card' + (checked ? ' checked' : '');
div.setAttribute('data-last-date', lastDate || '');
div.innerHTML =
'<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>' +
@@ -363,6 +373,29 @@
container.appendChild(div);
}
window.toggleStudyEdit = function() {
var panel = document.getElementById('panel-daily');
var btn = document.getElementById('study-edit-toggle');
if (!panel || !btn) return;
var editing = panel.classList.toggle('editing-study');
btn.classList.toggle('active', editing);
};
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());

View File

@@ -833,7 +833,7 @@ body {
/* 编辑模式下才显示的元素 */
.edit-only { display: flex; }
.btn-edit-toggle { display: none; }
.btn-edit-toggle:not(#study-edit-toggle) { display: none; }
/* 默认隐藏删除按钮 */
.btn-del { display: none; }
@@ -1783,14 +1783,20 @@ body {
.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-cards { display: flex; flex-direction: column; gap: 8px; }
.study-card { position:relative; display:flex; align-items:center; gap:12px; padding:10px 14px; border:1px solid var(--border); border-radius:var(--radius-sm); background:var(--card); transition:all 0.15s; }
.study-card:hover { border-color:var(--primary); box-shadow:var(--shadow); }
.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-info { display:flex; align-items:center; gap:8px; flex:1; }
.study-card-name { font-size:13px; color:var(--text); font-weight:500; }
.study-card-count { font-size:12px; color:var(--text-muted); font-weight:600; background:var(--bg); border-radius:50%; width:24px; height:24px; display:flex; align-items:center; justify-content:center; flex-shrink:0; }
.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 { 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; white-space:nowrap; }
.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 { display:none; }
#panel-daily.editing-study .study-card-del { display:flex; align-items:center; justify-content:center; position:absolute; top:50%; transform:translateY(-50%); right:54px; border:none; background:var(--danger-light); color:var(--danger); cursor:pointer; font-size:14px; width:22px; height:22px; border-radius:50%; line-height:1; }
#panel-daily.editing-study .study-card-del:hover { background:var(--danger); color:#FFF; }
.edit-only-study { display: none; }
#panel-daily.editing-study .edit-only-study { display: flex; }

View File

@@ -176,11 +176,19 @@
</div>
<div class="card card-study daily-card" data-card="study">
<div class="card-head">
<svg class="icon-h2"><use href="#icon-book-open"/></svg>
<h3>勤学打卡</h3>
<div class="card-head-left">
<svg class="icon-h2"><use href="#icon-book-open"/></svg>
<h3>勤学打卡</h3>
</div>
<button class="btn-edit-toggle" id="study-edit-toggle" onclick="toggleStudyEdit()" title="编辑">
<svg class="icon-sm"><use href="#icon-pencil"/></svg>
</button>
</div>
<p class="card-desc">本周修行清单</p>
<div id="study-cards"></div>
<button class="btn-add edit-only-study" onclick="addStudyItem()" style="margin-top:10px">
<svg class="icon-sm"><use href="#icon-plus"/></svg> 增加习惯
</button>
</div>
</div>
</div><!-- /daily-main -->