From 1ea81b308607172f9dcf4caff246db295a2ddf87 Mon Sep 17 00:00:00 2001 From: mac Date: Wed, 3 Jun 2026 14:48:18 +0800 Subject: [PATCH] =?UTF-8?q?v1.2.1=20=E2=80=94=20=E5=BF=83=E6=84=BF?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E5=86=85=E8=81=94=E7=BC=96=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 点击心愿名称/日期区域展开内联编辑表单 - 可修改名称、象限、截止时间 - 保存/取消,不干扰勾选和拖拽 --- static/app.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ static/style.css | 41 +++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/static/app.js b/static/app.js index 1c76612..1f333f9 100644 --- a/static/app.js +++ b/static/app.js @@ -688,8 +688,64 @@ }); bindDragEvents(); + bindEditClicks(); } + /* ── 点击编辑 ── */ + + function bindEditClicks() { + document.querySelectorAll('#panel-wishes .wish-item').forEach(function(item) { + // 只在点击名称或日期区域时触发编辑(排除 checkbox / 拖拽手柄 / 删除按钮) + item.addEventListener('click', function(e) { + if (e.target.closest('.wish-check') || e.target.closest('.wish-drag-handle') || + e.target.closest('.wish-del') || e.target.closest('.wish-edit-form')) return; + var id = parseInt(this.dataset.id); + var w = wishes.find(function(x){ return x.id === id; }); + if (w) startEditWish(this, w); + }); + }); + } + + function startEditWish(el, w) { + if (el.querySelector('.wish-edit-form')) return; // 已在编辑中 + el.classList.add('editing'); + var deadline = w.deadline || ''; + var quadOpts = QUADRANTS.map(function(q){ + return ''; + }).join(''); + el.innerHTML = + '
' + + '' + + '
' + + '' + + '' + + '
' + + '
' + + '' + + '' + + '
' + + '
'; + } + + window.saveEditWish = function(id, btn) { + var form = btn.closest('.wish-edit-form'); + var name = form.querySelector('.wish-edit-name').value.trim(); + if (!name) { showToast('名称不能为空', 'error'); return; } + var quadrant = form.querySelector('.wish-edit-quadrant').value; + var deadline = form.querySelector('.wish-edit-deadline').value; + fetch('/api/wishes/' + id, { + method: 'PUT', + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify({name: name, quadrant: quadrant, deadline: deadline}) + }).then(function(r){ return r.json(); }) + .then(function(res) { + if (!res.ok) { showToast(res.error, 'error'); return; } + var w = wishes.find(function(x){ return x.id === id; }); + if (w) { w.name = name; w.quadrant = quadrant; w.deadline = deadline; } + renderWishes(); + }); + }; + /* ── Drag & Drop (跨象限) ── */ function bindDragEvents() { diff --git a/static/style.css b/static/style.css index d8d6d89..432525a 100644 --- a/static/style.css +++ b/static/style.css @@ -1211,6 +1211,47 @@ body { .wish-del { display: none; } .wish-del .icon-xs { width: 13px; height: 13px; } +/* 内联编辑 */ +.wish-item.editing { + background: var(--card); + padding: 8px 10px; + flex-wrap: wrap; +} +.wish-edit-form { + width: 100%; + display: flex; + flex-direction: column; + gap: 6px; +} +.wish-edit-form input[type="text"], +.wish-edit-form input[type="date"], +.wish-edit-form select { + width: 100%; + padding: 6px 8px; + border: 1.5px solid var(--border); + border-radius: var(--radius-sm); + font-size: 12px; + font-family: inherit; + color: var(--text); + background: var(--card); + box-sizing: border-box; +} +.wish-edit-form input:focus, +.wish-edit-form select:focus { + outline: none; + border-color: var(--primary); + box-shadow: 0 0 0 2px rgba(74,108,247,0.08); +} +.wish-edit-name { font-weight: 500; } +.wish-edit-row { display: flex; gap: 6px; } +.wish-edit-row select, +.wish-edit-row input { flex: 1; } +.wish-edit-actions { display: flex; gap: 6px; } +.wish-edit-actions .btn-wish-save, +.wish-edit-actions .btn-wish-cancel { + flex: 1; padding: 6px; font-size: 12px; +} + .wishes-empty { font-size: 13px; color: var(--text-muted); text-align: center; padding: 32px 0; }