历史记录/操作日志与作业按次登记改进

1. 历史记录:批次合并视图新增"批量反撤销"(需反撤销权限);单条/批量撤销与反撤销提示更明确(说明记录去向,不会删除);操作列权限门控补充 restore_records
2. 操作日志:批量撤销/反撤销写入日志;单条撤销/反撤销/加减分日志详情补充学生姓名(学号)、分值变动、原因;新增"详情关键词"筛选(学生姓名/原因等)
3. 节假日接口:证书校验失败自动回退重试,提高服务器兼容性
4. 作业按次登记:默认列出全部学生、缺交次数默认0(0=已交),支持全员已交登记;后端允许空缺交名单
This commit is contained in:
canglan committed 2026-10-15 20:04:41 +08:00
1 parent dbf70f602e
commit d0cdb5b928
13 files changed
+192 -52

No files matched your search

+65 -9
View File
@@ -15,6 +15,7 @@ const canRevokeAny = hasPermission('revoke_any');
const canRevokeOwn = hasPermission('revoke_own');
const canRestore = hasPermission('restore_records');
const canRevoke = canRevokeAny || canRevokeOwn;
const canAct = canRevoke || canRestore;
let currentHistoryPage = 1;
let totalHistoryPages = 1;
@@ -126,12 +127,12 @@ async function loadHistory(page) {
var headHtml = '';
if (isGrouped) {
headHtml = '<th>类型</th><th>分值</th><th>原因</th><th>学生名单</th><th' + nowrapStyle + '>操作人</th><th>时间</th>';
if (canRevoke) {
if (canAct) {
headHtml += '<th>操作</th>';
}
} else {
headHtml = '<th>类型</th><th>分值</th><th>原因</th><th>学生</th><th' + nowrapStyle + '>操作人</th><th>时间</th>';
if (canRevoke) {
if (canAct) {
headHtml += '<th>操作</th>';
}
}
@@ -152,9 +153,13 @@ async function loadHistory(page) {
'<td class="history-students">' + escapeHtml(names) + '</td>' +
'<td>' + escapeHtml(record.recorder_name || '') + '</td>' +
'<td class="history-time">' + formatDateTime(record.created_at) + '</td>';
if (canRevoke) {
if (canAct) {
if (allRevoked) {
html += '<td><span class="text-muted">已撤销</span></td>';
if (canRestore) {
html += '<td><button class="btn btn-sm btn-outline" onclick="batchRestoreGrouped(\'' + escapeHtml(record.reason).replace(/'/g, "\\'") + '\',' + record.points_change + ',\'' + escapeHtml(record.recorder_name || '').replace(/'/g, "\\'") + '\')">批量反撤销</button></td>';
} else {
html += '<td><span class="text-muted">已撤销</span></td>';
}
} else if (canRevokeAny) {
html += '<td><button class="btn btn-sm btn-outline" onclick="batchRevokeGrouped(\'' + escapeHtml(record.reason).replace(/'/g, "\\'") + '\',' + record.points_change + ',\'' + escapeHtml(record.recorder_name || '').replace(/'/g, "\\'") + '\',\'' + formatDateTime(record.created_at) + '\')">批量撤销</button></td>';
} else {
@@ -164,7 +169,7 @@ async function loadHistory(page) {
html += '</tr>';
});
if (res.data.records.length === 0) {
var colSpan = canRevoke ? 7 : 6;
var colSpan = canAct ? 7 : 6;
html = '<tr><td colspan="' + colSpan + '" style="text-align:center;">暂无记录</td></tr>';
}
} else {
@@ -179,7 +184,7 @@ async function loadHistory(page) {
'<td>' + escapeHtml(record.student_name) + '</td>' +
'<td>' + escapeHtml(record.recorder_name) + '</td>' +
'<td class="history-time">' + formatDateTime(record.created_at) + '</td>';
if (canRevoke) {
if (canAct) {
if (record.is_revoked == 1) {
var revokerInfo = record.revoker_name ? '由 ' + escapeHtml(record.revoker_name) + ' 撤销' : '已撤销';
if (canRestore) {
@@ -197,7 +202,7 @@ async function loadHistory(page) {
});
if (res.data.records.length === 0) {
var colSpan = canRevoke ? 7 : 6;
var colSpan = canAct ? 7 : 6;
html = '<tr><td colspan="' + colSpan + '" style="text-align:center;">暂无记录</td></tr>';
}
}
@@ -358,7 +363,8 @@ async function batchRevokeGrouped(reason, pointsChange, recorderName, createdAt)
var matchedIds = [];
res.data.records.forEach(function(r) {
if (r.reason === reason && r.points_change === pointsChange && r.is_revoked == 0) {
if (r.reason === reason && r.points_change === pointsChange && r.is_revoked == 0
&& (!recorderName || r.recorder_name === recorderName)) {
matchedIds.push(r.record_id);
}
});
@@ -370,7 +376,7 @@ async function batchRevokeGrouped(reason, pointsChange, recorderName, createdAt)
var revokeRes = await apiPost('/api/admin/conduct/batch-revoke', { record_ids: matchedIds });
if (revokeRes && revokeRes.success) {
showToast('批量撤销完成: ' + (revokeRes.data ? revokeRes.data.success_count : 0) + '条成功');
showToast('批量撤销完成: ' + (revokeRes.data ? revokeRes.data.success_count : 0) + '条(已移入“已撤销”,可筛选查看/批量反撤销)');
loadHistory(currentHistoryPage);
} else {
showToast(revokeRes && revokeRes.message || '批量撤销失败', 'error');
@@ -380,6 +386,55 @@ async function batchRevokeGrouped(reason, pointsChange, recorderName, createdAt)
}
}
// 批量反撤销合并记录(按条件查找并恢复)
async function batchRestoreGrouped(reason, pointsChange, recorderName) {
if (!confirm('确定要反撤销所有"' + reason + '"(' + (pointsChange > 0 ? '+' : '') + pointsChange + '分)的记录吗?')) return;
showToast('正在批量反撤销...', 'info');
try {
var params = {
page: 1, page_size: 1000,
start_date: document.getElementById('historyStartDate').value,
end_date: document.getElementById('historyEndDate').value,
reason_prefix: reason.substring(0, 4),
grouped: false,
is_revoked: 1
};
var semesterSelect = document.getElementById('historySemesterFilter');
if (semesterSelect && semesterSelect.value) params.semester_id = semesterSelect.value;
var res = await apiGet('/api/admin/conduct/history', params);
if (!res || !res.success || !res.data.records) {
showToast('查询记录失败', 'error');
return;
}
var matchedIds = [];
res.data.records.forEach(function(r) {
if (r.reason === reason && r.points_change === pointsChange && r.is_revoked == 1
&& (!recorderName || r.recorder_name === recorderName)) {
matchedIds.push(r.record_id);
}
});
if (matchedIds.length === 0) {
showToast('没有找到可反撤销的记录', 'warning');
return;
}
var restoreRes = await apiPost('/api/admin/conduct/batch-restore', { record_ids: matchedIds });
if (restoreRes && restoreRes.success) {
showToast('批量反撤销完成: ' + (restoreRes.data ? restoreRes.data.success_count : 0) + '条成功(记录已恢复正常)');
loadHistory(currentHistoryPage);
} else {
showToast((restoreRes && restoreRes.message) || '批量反撤销失败', 'error');
}
} catch (err) {
showToast('批量反撤销失败: ' + err.message, 'error');
}
}
// 初始化:并行加载学生、科目、学期列表,然后加载历史记录
Promise.all([loadStudentsForSelect(), loadSubjectsForFilter(), loadSemestersForFilter()]).then(function() {
var urlParams = new URLSearchParams(window.location.search);
@@ -396,6 +451,7 @@ window.loadStudentsForSelect = loadStudentsForSelect;
window.showExportHistoryModal = showExportHistoryModal;
window.exportHistoryRecords = exportHistoryRecords;
window.batchRevokeGrouped = batchRevokeGrouped;
window.batchRestoreGrouped = batchRestoreGrouped;
window.onStudentFilterChange = onStudentFilterChange;
window.onSubjectFilterChange = onSubjectFilterChange;
window.toggleFilterPanel = toggleFilterPanel;
+15 -19
View File
@@ -13,6 +13,8 @@
const hwNotSubmit = window.DEDUCTION_HOMEWORK_NOT_SUBMIT || 2;
const hwLate = window.DEDUCTION_HOMEWORK_LATE || 1;
let studentsData = [];
// 更新页面中的配置值显示(加减分上限来自权限组动态配置)
document.querySelectorAll('.hw-not-submit').forEach(el => el.textContent = hwNotSubmit);
document.querySelectorAll('.hw-late').forEach(el => el.textContent = hwLate);
@@ -43,6 +45,7 @@ async function loadSubjectsForHomework() {
async function loadStudents() {
const res = await apiGet('/api/admin/students', {page_size: 1000});
if (res && res.success) {
studentsData = res.data.students || [];
let html = '';
res.data.students.forEach(student => {
html += `<tr>
@@ -266,9 +269,8 @@ async function submitEditSubject() {
// ========== 作业按次登记 ==========
async function showHomeworkRegisterModal() {
const checked = Array.from(document.querySelectorAll('.student-checkbox:checked'));
if (checked.length === 0) {
showToast('请先在学生列表中勾选缺交学生', 'warning');
if (!studentsData || studentsData.length === 0) {
showToast('学生列表尚未加载,请稍后重试', 'warning');
return;
}
@@ -283,16 +285,13 @@ async function showHomeworkRegisterModal() {
}
subjectSelect.innerHTML = options;
// 缺交学生列表(每人可填缺交次数)
// 默认列出全部学生,缺交次数默认 0(0 = 已交)
let html = '';
checked.forEach(cb => {
const row = cb.closest('tr');
const no = row ? row.children[1].textContent.trim() : '';
const name = row ? row.children[2].textContent.trim() : '';
studentsData.forEach(student => {
html += `<div class="hw-reg-item">
<span class="hw-reg-name">${escapeHtml(name)} <small>${escapeHtml(no)}</small></span>
<span class="hw-reg-name">${escapeHtml(student.name)} <small>${escapeHtml(student.student_no)}</small></span>
<span class="hw-reg-miss-label" style="margin-left:auto;">缺交</span>
<input type="number" class="hw-reg-miss" data-id="${cb.dataset.id}" min="1" value="1" style="width:64px;">
<input type="number" class="hw-reg-miss" data-id="${student.student_id}" min="0" value="0" style="width:64px;">
<span class="hw-reg-miss-label">次</span>
</div>`;
});
@@ -325,19 +324,16 @@ async function submitHomeworkRegister() {
}
const inputs = Array.from(document.querySelectorAll('.hw-reg-miss'));
if (inputs.length === 0) {
showToast('请先在学生列表中勾选缺交学生', 'warning');
return;
}
const records = [];
for (const input of inputs) {
const miss = parseInt(input.value);
if (!miss || miss < 1 || miss > totalTimes) {
showToast('缺交次数需在1~总提交次数之间', 'warning');
const miss = parseInt(input.value) || 0;
if (miss < 0 || miss > totalTimes) {
showToast('缺交次数需在0~总提交次数之间', 'warning');
return;
}
records.push({ student_id: parseInt(input.dataset.id), miss_count: miss });
if (miss > 0) {
records.push({ student_id: parseInt(input.dataset.id), miss_count: miss });
}
}
const payload = {
+3
View File
@@ -24,6 +24,8 @@ const OPERATION_TYPES = {
add_calendar_day: '添加校历设置',
remove_calendar_day: '删除校历设置',
homework_register: '作业按次登记',
batch_revoke: '批量撤销记录',
batch_restore: '批量反撤销记录',
add_admin: '添加管理员',
reactivate_admin: '重新激活管理员',
update_admin: '编辑管理员',
@@ -84,6 +86,7 @@ async function loadLogs(page) {
page_size: 20,
operation_type: document.getElementById('logTypeFilter').value,
operator: document.getElementById('logOperatorFilter').value.trim(),
keyword: document.getElementById('logKeywordFilter') ? document.getElementById('logKeywordFilter').value.trim() : '',
start_date: document.getElementById('logStartDate').value,
end_date: document.getElementById('logEndDate').value
};
+2 -2
View File
@@ -95,7 +95,7 @@
const res = await apiPost('/api/admin/conduct/revoke', { record_id: recordId });
if (res && res.success) {
showToast('撤销成功');
showToast('撤销成功,该记录已移入“已撤销”(可筛选查看/反撤销)');
loadHistory(currentHistoryPage);
} else {
showToast(res?.message || '撤销失败', 'error');
@@ -108,7 +108,7 @@
const res = await apiPost('/api/admin/conduct/restore', { record_id: recordId });
if (res && res.success) {
showToast('反撤销成功');
showToast('反撤销成功,该记录已恢复正常');
loadHistory(currentHistoryPage);
} else {
showToast(res?.message || '反撤销失败', 'error');