v2.2.0 — 删除评分+心愿模块(HTML/JS/CSS/Python)
This commit is contained in:
364
static/app.js
364
static/app.js
@@ -9,7 +9,6 @@
|
||||
var calYear;
|
||||
var calMonth = new Date().getMonth(); // 月份索引 0-11
|
||||
var activePanel = 'daily';
|
||||
var weekOffset = 0;
|
||||
var lastSavedData = null;
|
||||
var lastSavedWeek = null;
|
||||
var selectedWeek = null;
|
||||
@@ -114,9 +113,7 @@
|
||||
if (nav) nav.classList.add('active');
|
||||
if (panel) panel.classList.add('active');
|
||||
|
||||
if (name === 'weekly') loadWeekly();
|
||||
if (name === 'history') loadHistory();
|
||||
if (name === 'wishes') loadWishes();
|
||||
if (name === 'blueprint') loadBlueprint();
|
||||
};
|
||||
|
||||
@@ -712,95 +709,6 @@
|
||||
});
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
Weekly Score
|
||||
================================================================ */
|
||||
var WEEKDAYS_CN = ['日','一','二','三','四','五','六'];
|
||||
|
||||
function getMonday(d) {
|
||||
var day = d.getDay();
|
||||
var diff = d.getDate() - day + (day === 0 ? -6 : 1);
|
||||
var m = new Date(d);
|
||||
m.setDate(diff);
|
||||
return m;
|
||||
}
|
||||
|
||||
window.changeWeek = function(dir) {
|
||||
weekOffset += dir;
|
||||
loadWeekly();
|
||||
};
|
||||
|
||||
function loadWeekly() {
|
||||
var today = new Date();
|
||||
today.setDate(today.getDate() + weekOffset * 7);
|
||||
var wk = fmtWeek(today);
|
||||
document.getElementById('week-label').textContent = wk;
|
||||
|
||||
apiGetCheckin(wk, function(err, row){
|
||||
if (err) { showToast('加载失败', 'error'); return; }
|
||||
var dd = row ? row.data : null;
|
||||
if (!dd) {
|
||||
document.getElementById('weekly-score').textContent = '--';
|
||||
document.getElementById('score-text').textContent = '本周暂无记录';
|
||||
document.getElementById('score-stats').textContent = '';
|
||||
document.getElementById('week-days-grid').innerHTML = '';
|
||||
return;
|
||||
}
|
||||
|
||||
var morning = dd.morning || [];
|
||||
var evening = dd.evening || [];
|
||||
var study = dd.study || [];
|
||||
|
||||
var morningCount = morning.filter(function(x){ return x && typeof x === 'string' && x.trim(); }).length;
|
||||
if (!morningCount) {
|
||||
morningCount = morning.filter(function(x){
|
||||
return x && typeof x === 'object' && (x.text || '').trim();
|
||||
}).length;
|
||||
}
|
||||
var eveningCount = evening.filter(function(x){
|
||||
var mst = typeof x === 'string' ? x : (x.mistake || '');
|
||||
return mst && typeof mst === 'string' && mst.trim();
|
||||
}).length;
|
||||
var studyCount = study.filter(function(x){ return x.done; }).length;
|
||||
|
||||
var allThree = morningCount > 0 && eveningCount > 0 && studyCount > 0;
|
||||
var score, status;
|
||||
if (allThree) {
|
||||
score = 60 + (morningCount - 1) * 5 + (eveningCount - 1) * 3 + studyCount * 3;
|
||||
status = 'pass';
|
||||
} else {
|
||||
score = 0;
|
||||
status = 'fail';
|
||||
}
|
||||
|
||||
var grade = score >= 90 ? '优秀' : score >= 75 ? '良好' : score >= 60 ? '达标' : '未达标';
|
||||
|
||||
document.getElementById('weekly-score').textContent = score;
|
||||
|
||||
var ring = document.querySelector('.score-ring');
|
||||
if (ring) {
|
||||
var R = 50, C = 2 * Math.PI * R;
|
||||
ring.setAttribute('stroke-dasharray', C);
|
||||
var ratio = Math.min(score / 100, 1);
|
||||
ring.setAttribute('stroke-dashoffset', C - (C * ratio));
|
||||
}
|
||||
|
||||
var txt = grade + ' · ' + score + ' 分';
|
||||
document.getElementById('score-text').textContent = txt;
|
||||
document.getElementById('score-stats').textContent =
|
||||
'立志 ' + morningCount + ' · 责善 ' + eveningCount + ' · 勤学 ' + studyCount + '/8';
|
||||
|
||||
// 渲染周统计网格(简化版)
|
||||
var gridHtml = '<div class="day-cell ' + status + '">' +
|
||||
'<div class="day-label">' + wk + '</div>' +
|
||||
'<div class="day-date">' + grade + '</div>' +
|
||||
'<div class="day-score">' + score + '<span style="font-size:11px;font-weight:400">分</span></div>' +
|
||||
'<div class="day-badge">' + (status === 'pass' ? '达标' : '未达标') + '</div>' +
|
||||
'</div>';
|
||||
document.getElementById('week-days-grid').innerHTML = gridHtml;
|
||||
});
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
History
|
||||
================================================================ */
|
||||
@@ -855,278 +763,6 @@
|
||||
});
|
||||
};
|
||||
|
||||
/* ================================================================
|
||||
Wishes — 心愿清单(四象限)
|
||||
================================================================ */
|
||||
var wishes = [];
|
||||
var dragSourceId = null;
|
||||
var dragSourceQuadrant = null;
|
||||
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;
|
||||
}
|
||||
fetch('/api/wishes')
|
||||
.then(function(r){ return r.json(); })
|
||||
.then(function(res){ if (res.ok) { wishes = res.data; wishesLoaded = true; renderWishes(); } });
|
||||
}
|
||||
|
||||
function renderWishes() {
|
||||
var emptyEl = document.getElementById('wishes-empty');
|
||||
if (!wishes.length) {
|
||||
QUADRANTS.forEach(function(q){ document.getElementById('quad-list-' + q).innerHTML = ''; });
|
||||
if (emptyEl) emptyEl.style.display = 'block';
|
||||
return;
|
||||
}
|
||||
if (emptyEl) emptyEl.style.display = 'none';
|
||||
|
||||
// 按象限分组渲染
|
||||
QUADRANTS.forEach(function(quadrant) {
|
||||
var list = document.getElementById('quad-list-' + quadrant);
|
||||
if (!list) return;
|
||||
var items = wishes.filter(function(w){ return normalizeQuadrant(w) === quadrant; });
|
||||
var html = '';
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
var w = items[i];
|
||||
var doneCls = w.done ? ' done' : '';
|
||||
var deadline = w.deadline ? w.deadline : '';
|
||||
html += '<div class="wish-item' + doneCls + '" draggable="true" data-id="' + w.id + '" data-quadrant="' + quadrant + '">' +
|
||||
'<span class="wish-drag-handle"><svg class="icon-xs"><use href="#icon-list-bullet"/></svg></span>' +
|
||||
'<input type="checkbox" class="wish-check" ' + (w.done ? 'checked' : '') + ' onchange="toggleWish(' + w.id + ', this.checked)">' +
|
||||
'<span class="wish-name" title="' + esc(w.name) + '">' + esc(w.name) + '</span>' +
|
||||
(deadline ? '<span class="wish-deadline">' + esc(deadline) + '</span>' : '') +
|
||||
'<button class="btn-del wish-del" onclick="deleteWishItem(' + w.id + ')"><svg class="icon-xs"><use href="#icon-x"/></svg></button>' +
|
||||
'</div>';
|
||||
}
|
||||
list.innerHTML = html;
|
||||
});
|
||||
|
||||
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() {
|
||||
var items = document.querySelectorAll('#panel-wishes .wish-item');
|
||||
items.forEach(function(item) {
|
||||
item.addEventListener('dragstart', function(e) {
|
||||
dragSourceId = parseInt(this.dataset.id);
|
||||
dragSourceQuadrant = this.dataset.quadrant;
|
||||
this.classList.add('dragging');
|
||||
e.dataTransfer.effectAllowed = 'move';
|
||||
});
|
||||
item.addEventListener('dragend', function() {
|
||||
this.classList.remove('dragging');
|
||||
dragSourceId = null;
|
||||
dragSourceQuadrant = null;
|
||||
document.querySelectorAll('.quad-cell, .wish-item').forEach(function(el){ el.classList.remove('drag-over'); });
|
||||
});
|
||||
item.addEventListener('dragover', function(e) {
|
||||
e.preventDefault();
|
||||
e.dataTransfer.dropEffect = 'move';
|
||||
this.classList.add('drag-over');
|
||||
});
|
||||
item.addEventListener('dragleave', function() {
|
||||
this.classList.remove('drag-over');
|
||||
});
|
||||
item.addEventListener('drop', function(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
this.classList.remove('drag-over');
|
||||
var targetId = parseInt(this.dataset.id);
|
||||
var targetQuadrant = this.dataset.quadrant;
|
||||
if (dragSourceId === targetId) return;
|
||||
|
||||
var fromIdx = -1, toIdx = -1;
|
||||
for (var j = 0; j < wishes.length; j++) {
|
||||
if (wishes[j].id === dragSourceId) fromIdx = j;
|
||||
if (wishes[j].id === targetId) toIdx = j;
|
||||
}
|
||||
if (fromIdx >= 0 && toIdx >= 0) {
|
||||
var moved = wishes.splice(fromIdx, 1)[0];
|
||||
wishes.splice(toIdx, 0, moved);
|
||||
// 更新象限
|
||||
if (dragSourceQuadrant !== targetQuadrant) {
|
||||
moved.quadrant = targetQuadrant;
|
||||
fetch('/api/wishes/' + moved.id, {
|
||||
method: 'PUT',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({quadrant: targetQuadrant})
|
||||
}).catch(function(){ showToast('保存失败', 'error'); });
|
||||
}
|
||||
renderWishes();
|
||||
saveWishOrder();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 象限空区域接受 drop
|
||||
document.querySelectorAll('.quad-cell').forEach(function(cell) {
|
||||
cell.addEventListener('dragover', function(e) {
|
||||
if (this.querySelector('.wish-item')) return; // 有内容时让 item 处理
|
||||
e.preventDefault();
|
||||
this.classList.add('drag-over');
|
||||
});
|
||||
cell.addEventListener('dragleave', function() { this.classList.remove('drag-over'); });
|
||||
cell.addEventListener('drop', function(e) {
|
||||
this.classList.remove('drag-over');
|
||||
if (this.querySelector('.wish-item')) return; // 已由 item 处理
|
||||
e.preventDefault();
|
||||
var q = this.dataset.quadrant;
|
||||
var moved = wishes.find(function(w){ return w.id === dragSourceId; });
|
||||
if (moved) {
|
||||
moved.quadrant = q;
|
||||
fetch('/api/wishes/' + moved.id, {
|
||||
method: 'PUT',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({quadrant: q})
|
||||
}).catch(function(){ showToast('保存失败', 'error'); });
|
||||
renderWishes();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function saveWishOrder() {
|
||||
var order = wishes.map(function(w){ return w.id; });
|
||||
fetch('/api/wishes/reorder', {
|
||||
method: 'PUT',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({order: order})
|
||||
});
|
||||
}
|
||||
|
||||
/* ── CRUD ── */
|
||||
|
||||
window.showWishForm = function() {
|
||||
var form = document.getElementById('wish-form');
|
||||
if (form) form.style.display = 'block';
|
||||
};
|
||||
|
||||
window.hideWishForm = function() {
|
||||
var form = document.getElementById('wish-form');
|
||||
if (form) form.style.display = 'none';
|
||||
document.getElementById('wish-name').value = '';
|
||||
document.getElementById('wish-deadline').value = '';
|
||||
var sel = document.getElementById('wish-quadrant');
|
||||
if (sel) sel.value = '重要不紧急';
|
||||
};
|
||||
|
||||
window.addWish = function() {
|
||||
var name = document.getElementById('wish-name').value.trim();
|
||||
if (!name) { showToast('请输入心愿名称', 'error'); return; }
|
||||
var quadrant = document.getElementById('wish-quadrant').value;
|
||||
var deadline = document.getElementById('wish-deadline').value;
|
||||
fetch('/api/wishes', {
|
||||
method: 'POST',
|
||||
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; }
|
||||
hideWishForm();
|
||||
wishes.push({id: res.id, name: name, quadrant: quadrant, deadline: deadline, done: 0});
|
||||
renderWishes();
|
||||
});
|
||||
};
|
||||
|
||||
window.toggleWish = function(id, done) {
|
||||
fetch('/api/wishes/' + id, {
|
||||
method: 'PUT',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({done: done ? 1 : 0})
|
||||
});
|
||||
var w = wishes.find(function(x){ return x.id === id; });
|
||||
if (w) w.done = done ? 1 : 0;
|
||||
renderWishes();
|
||||
};
|
||||
|
||||
window.deleteWishItem = function(id) {
|
||||
fetch('/api/wishes/' + id, {method: 'DELETE'});
|
||||
wishes = wishes.filter(function(w){ return w.id !== id; });
|
||||
renderWishes();
|
||||
};
|
||||
|
||||
window.toggleWishesEdit = function(btn) {
|
||||
var panel = document.getElementById('panel-wishes');
|
||||
if (!panel) return;
|
||||
var editing = panel.classList.toggle('editing');
|
||||
btn.classList.toggle('active', editing);
|
||||
};
|
||||
|
||||
window.renderWishes = renderWishes;
|
||||
|
||||
/* ================================================================
|
||||
Blueprint — 蓝图六板块
|
||||
================================================================ */
|
||||
|
||||
Reference in New Issue
Block a user