|
|
|
|
@@ -644,10 +644,19 @@
|
|
|
|
|
var wishesLoaded = false;
|
|
|
|
|
var QUADRANTS = ['重要紧急', '重要不紧急', '紧急不重要', '不紧急不重要'];
|
|
|
|
|
|
|
|
|
|
function normalizeQuadrant(w) {
|
|
|
|
|
if (QUADRANTS.indexOf(w.quadrant) >= 0) return w.quadrant;
|
|
|
|
|
// 老数据回退: priority → quadrant
|
|
|
|
|
var map = {'高': '重要紧急', '中': '重要不紧急', '低': '不紧急不重要'};
|
|
|
|
|
return map[w.priority] || '重要不紧急';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadWishes() {
|
|
|
|
|
if (wishesLoaded) { renderWishes(); return; }
|
|
|
|
|
if (window.__INITIAL_WISHES__) {
|
|
|
|
|
wishes = window.__INITIAL_WISHES__;
|
|
|
|
|
// 规范化 quadrant
|
|
|
|
|
wishes.forEach(function(w){ w.quadrant = normalizeQuadrant(w); });
|
|
|
|
|
wishesLoaded = true;
|
|
|
|
|
renderWishes();
|
|
|
|
|
return;
|
|
|
|
|
@@ -670,7 +679,7 @@
|
|
|
|
|
QUADRANTS.forEach(function(quadrant) {
|
|
|
|
|
var list = document.getElementById('quad-list-' + quadrant);
|
|
|
|
|
if (!list) return;
|
|
|
|
|
var items = wishes.filter(function(w){ return (w.quadrant || w.priority || '重要不紧急') === quadrant; });
|
|
|
|
|
var items = wishes.filter(function(w){ return normalizeQuadrant(w) === quadrant; });
|
|
|
|
|
var html = '';
|
|
|
|
|
for (var i = 0; i < items.length; i++) {
|
|
|
|
|
var w = items[i];
|
|
|
|
|
@@ -688,8 +697,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 '<option value="' + q + '"' + (q === normalizeQuadrant(w) ? ' selected' : '') + '>' + q + '</option>';
|
|
|
|
|
}).join('');
|
|
|
|
|
el.innerHTML =
|
|
|
|
|
'<div class="wish-edit-form">' +
|
|
|
|
|
'<input type="text" class="wish-edit-name" value="' + esc(w.name) + '" maxlength="50">' +
|
|
|
|
|
'<div class="wish-edit-row">' +
|
|
|
|
|
'<select class="wish-edit-quadrant">' + quadOpts + '</select>' +
|
|
|
|
|
'<input type="date" class="wish-edit-deadline" value="' + esc(deadline) + '">' +
|
|
|
|
|
'</div>' +
|
|
|
|
|
'<div class="wish-edit-actions">' +
|
|
|
|
|
'<button class="btn-wish-save" onclick="event.stopPropagation();saveEditWish(' + w.id + ', this)">保存</button>' +
|
|
|
|
|
'<button class="btn-wish-cancel" onclick="event.stopPropagation();window.renderWishes()">取消</button>' +
|
|
|
|
|
'</div>' +
|
|
|
|
|
'</div>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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() {
|
|
|
|
|
@@ -738,7 +803,7 @@
|
|
|
|
|
method: 'PUT',
|
|
|
|
|
headers: {'Content-Type': 'application/json'},
|
|
|
|
|
body: JSON.stringify({quadrant: targetQuadrant})
|
|
|
|
|
});
|
|
|
|
|
}).catch(function(){ showToast('保存失败', 'error'); });
|
|
|
|
|
}
|
|
|
|
|
renderWishes();
|
|
|
|
|
saveWishOrder();
|
|
|
|
|
@@ -766,7 +831,7 @@
|
|
|
|
|
method: 'PUT',
|
|
|
|
|
headers: {'Content-Type': 'application/json'},
|
|
|
|
|
body: JSON.stringify({quadrant: q})
|
|
|
|
|
});
|
|
|
|
|
}).catch(function(){ showToast('保存失败', 'error'); });
|
|
|
|
|
renderWishes();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
@@ -840,6 +905,8 @@
|
|
|
|
|
btn.classList.toggle('active', editing);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
window.renderWishes = renderWishes;
|
|
|
|
|
|
|
|
|
|
/* ================================================================
|
|
|
|
|
Init
|
|
|
|
|
================================================================ */
|
|
|
|
|
|