v4.2 科目管理优化与多项修复清理
1. 科目管理:代码长度放宽至50(含数据库升级v4.2)、编辑可清空代码、重命名查重、新增 ↑↓ 快捷排序(批量重排接口)、空代码不再显示占位 2. 修复单人加减分提交空名单:showSinglePointsModal 三处重复定义收口到 points-mgmt 并共享选中状态 3. SMTP:SMTP_FROM 默认取 SMTP_USER、SMTP_ENABLED 兼容 1/yes/on、启动日志打印邮件状态、新增邮件测试接口与按钮(返回真实 SMTP 错误) 4. 密码:加密改为 bcrypt 库直连(修复 passlib 兼容问题)、重置密码不再依赖影响行数、前端统一展示422校验错误 5. 冗余清理:删除未用导入/Schema/函数、死文件 admin.js 与 sanitize.py、重复 escapeHtml、重复CSS、重复脚本加载 6. 修复11个文件被写入的 UTF-8 BOM 7. 文档与版本同步至4.2
This commit is contained in:
1 parent
990f44bf22
commit
1068bc6def
58 files changed
+366
-533
No files matched your search
@@ -56,14 +56,6 @@ async function loadStudents() {
|
||||
}
|
||||
}
|
||||
|
||||
function showSinglePointsModal(studentId, studentName) {
|
||||
window.selectedStudentIds = [studentId];
|
||||
document.getElementById('selectedStudentsCount').innerHTML = `${studentName} (1人)`;
|
||||
document.getElementById('pointsChange').value = '';
|
||||
document.getElementById('pointsReason').value = '';
|
||||
document.getElementById('batchPointsModal').style.display = 'flex';
|
||||
}
|
||||
|
||||
function handleSubmitPoints() {
|
||||
const pointsChange = parseInt(document.getElementById('pointsChange').value);
|
||||
const limitError = validateScoreChange(pointsChange);
|
||||
@@ -116,37 +108,68 @@ function toggleSubjectPanel() {
|
||||
}
|
||||
}
|
||||
|
||||
let subjectsCache = [];
|
||||
|
||||
async function loadSubjectList() {
|
||||
const res = await apiGet('/api/subject/list');
|
||||
if (res && res.success && res.data) {
|
||||
subjectsCache = res.data.subjects || [];
|
||||
let html = '';
|
||||
const subjects = res.data.subjects || [];
|
||||
subjects.forEach(sub => {
|
||||
subjectsCache.forEach((sub, index) => {
|
||||
const safeName = escapeHtml(sub.subject_name || '');
|
||||
const safeCode = escapeHtml(sub.subject_code || '');
|
||||
const sortOrder = sub.sort_order || 0;
|
||||
const codeHtml = safeCode ? `<span class="subject-code">${safeCode}</span>` : '';
|
||||
const upBtn = index > 0
|
||||
? `<button class="btn btn-sm btn-ghost" title="上移" onclick="moveSubject(${sub.subject_id}, -1)">↑</button>`
|
||||
: '';
|
||||
const downBtn = index < subjectsCache.length - 1
|
||||
? `<button class="btn btn-sm btn-ghost" title="下移" onclick="moveSubject(${sub.subject_id}, 1)">↓</button>`
|
||||
: '';
|
||||
html += `
|
||||
<div class="subject-item">
|
||||
<span class="subject-name">${safeName}</span>
|
||||
<span class="subject-code">${safeCode}</span>
|
||||
${codeHtml}
|
||||
<span class="subject-status ${sub.is_active ? 'subject-status-active' : 'subject-status-inactive'}">
|
||||
${sub.is_active ? '启用' : '禁用'}
|
||||
</span>
|
||||
<button class="btn btn-sm btn-outline" onclick="showEditSubjectModal(${sub.subject_id}, '${safeName.replace(/'/g, "\\'")}', '${safeCode.replace(/'/g, "\\'")}', ${sortOrder})">编辑</button>
|
||||
<button class="btn btn-sm btn-ghost" onclick="toggleSubjectStatus(${sub.subject_id}, ${sub.is_active ? 'false' : 'true'})">
|
||||
${sub.is_active ? '禁用' : '启用'}
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-danger" onclick="deleteSubject(${sub.subject_id})">删除</button>
|
||||
<span class="subject-order">排序 ${sortOrder}</span>
|
||||
<span class="subject-actions">
|
||||
${upBtn}
|
||||
${downBtn}
|
||||
<button class="btn btn-sm btn-outline" onclick="showEditSubjectModal(${sub.subject_id}, '${safeName.replace(/'/g, "\\'")}', '${safeCode.replace(/'/g, "\\'")}', ${sortOrder})">编辑</button>
|
||||
<button class="btn btn-sm btn-ghost" onclick="toggleSubjectStatus(${sub.subject_id}, ${sub.is_active ? 'false' : 'true'})">
|
||||
${sub.is_active ? '禁用' : '启用'}
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-danger" onclick="deleteSubject(${sub.subject_id})">删除</button>
|
||||
</span>
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
if (subjects.length === 0) {
|
||||
if (subjectsCache.length === 0) {
|
||||
html = '<p style="text-align:center;padding:40px;">暂无科目,请点击"添加科目"</p>';
|
||||
}
|
||||
document.getElementById('subjectList').innerHTML = html;
|
||||
}
|
||||
}
|
||||
|
||||
async function moveSubject(subjectId, direction) {
|
||||
const index = subjectsCache.findIndex(s => s.subject_id === subjectId);
|
||||
if (index < 0) return;
|
||||
const targetIndex = index + direction;
|
||||
if (targetIndex < 0 || targetIndex >= subjectsCache.length) return;
|
||||
const ids = subjectsCache.map(s => s.subject_id);
|
||||
ids[index] = subjectsCache[targetIndex].subject_id;
|
||||
ids[targetIndex] = subjectId;
|
||||
const res = await apiPut('/api/subject/reorder', { subject_ids: ids });
|
||||
if (res && res.success) {
|
||||
loadSubjectList();
|
||||
loadSubjectsForHomework();
|
||||
} else {
|
||||
showToast(res?.message || '排序失败', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
function showAddSubjectModal() {
|
||||
const form = document.getElementById('addSubjectFormInHw');
|
||||
if (form) form.reset();
|
||||
@@ -219,8 +242,10 @@ async function submitEditSubject() {
|
||||
return;
|
||||
}
|
||||
|
||||
const data = { subject_name: subjectName };
|
||||
if (subjectCode) data.subject_code = subjectCode;
|
||||
const data = {
|
||||
subject_name: subjectName,
|
||||
subject_code: subjectCode
|
||||
};
|
||||
if (sortOrder !== '') data.sort_order = parseInt(sortOrder);
|
||||
|
||||
const res = await apiPut(`/api/subject/update/${subjectId}`, data);
|
||||
@@ -244,7 +269,6 @@ loadStudents();
|
||||
loadSubjectsForHomework();
|
||||
|
||||
window.loadStudents = loadStudents;
|
||||
window.showSinglePointsModal = showSinglePointsModal;
|
||||
window.handleSubmitPoints = handleSubmitPoints;
|
||||
window.toggleSubjectPanel = toggleSubjectPanel;
|
||||
window.showAddSubjectModal = showAddSubjectModal;
|
||||
@@ -253,5 +277,6 @@ window.toggleSubjectStatus = toggleSubjectStatus;
|
||||
window.deleteSubject = deleteSubject;
|
||||
window.showEditSubjectModal = showEditSubjectModal;
|
||||
window.submitEditSubject = submitEditSubject;
|
||||
window.moveSubject = moveSubject;
|
||||
|
||||
})();
|
||||
Reference in new issue
Block a user