技术栈:Go (Gin + GORM) + PHP + MySQL 5.7 + Redis 主要功能: - 多班级完全隔离(class_id 贯穿全系统) - 后端 Go Gin(端口 56789),Nginx 反代 - 超级管理员独立登录(env 配置,默认账密 admin/Admin123) - bcrypt 密码加密(无 PASSWORD_SALT) - 科任老师/课代表新角色 - 课代表作业管理页面 - 排行榜分项排行(操行分/考勤/作业) - 角色加减分上下限由班主任配置 - 家长改密功能(可开关) - 班级角色按需开关 - 宿舍号格式:南0-000 - 周度/月度重置功能 - MySQL 5.7 兼容 - 43 轮代码审查 + 全部修复 开发者: Canglan 版权归属: Sea Network Technology Studio 许可证: Apache License 2.0
346 lines
15 KiB
JavaScript
346 lines
15 KiB
JavaScript
/**
|
|
* 多班级版班级管理系统 - 历史记录页JS
|
|
*
|
|
* 开发者: Canglan
|
|
* 版权归属: Sea Network Technology Studio
|
|
*
|
|
* 版权所有 © Sea Network Technology Studio
|
|
*/
|
|
|
|
(function() {
|
|
'use strict';
|
|
|
|
const role = window.PAGE_CONFIG.role;
|
|
const currentUserId = window.PAGE_CONFIG.userId;
|
|
let currentHistoryPage = 1;
|
|
let totalHistoryPages = 1;
|
|
|
|
function getTypeLabel(relatedType) {
|
|
if (!relatedType) return '操行';
|
|
switch (relatedType) {
|
|
case 'conduct': return '操行';
|
|
case 'homework': return '作业';
|
|
case 'attendance': return '考勤';
|
|
default: return relatedType;
|
|
}
|
|
}
|
|
|
|
async function loadStudentsForSelect() {
|
|
const res = await apiGet('/api/admin/students', {page_size: 1000});
|
|
if (res && res.success) {
|
|
let html = '<option value="">全部</option>';
|
|
res.data.students.forEach(s => {
|
|
html += '<option value="' + s.student_id + '">' + escapeHtml(s.student_no) + ' - ' + escapeHtml(s.name) + '</option>';
|
|
});
|
|
document.getElementById('historyStudentId').innerHTML = html;
|
|
}
|
|
}
|
|
|
|
// 加载科目下拉列表
|
|
async function loadSubjectsForFilter() {
|
|
let subjectSelect = document.getElementById('historySubjectFilter');
|
|
if (!subjectSelect) return;
|
|
let res = await apiGet('/api/subject/list', { is_active: true });
|
|
if (res && res.success && res.data && res.data.subjects) {
|
|
let html = '<option value="">全部科目</option>';
|
|
res.data.subjects.forEach(s => {
|
|
html += '<option value="' + escapeHtml(s.subject_name) + '">' + escapeHtml(s.subject_name) + '</option>';
|
|
});
|
|
subjectSelect.innerHTML = html;
|
|
}
|
|
}
|
|
|
|
// 筛选学生时自动取消合并记录
|
|
function onStudentFilterChange() {
|
|
let studentId = document.getElementById('historyStudentId').value;
|
|
if (studentId) {
|
|
let grouped = document.getElementById('historyGrouped');
|
|
if (grouped) grouped.checked = false;
|
|
}
|
|
}
|
|
|
|
// 科目筛选变化时,取消扣分类型筛选(互斥)
|
|
function onSubjectFilterChange() {
|
|
let subjectVal = document.getElementById('historySubjectFilter').value;
|
|
if (subjectVal) {
|
|
document.getElementById('historyReasonFilter').value = '';
|
|
}
|
|
}
|
|
|
|
// 折叠/展开筛选面板
|
|
function toggleFilterPanel() {
|
|
let panel = document.getElementById('advancedFilters');
|
|
let btn = document.getElementById('filterToggleBtn');
|
|
if (!panel || !btn) return;
|
|
if (panel.style.display === 'none') {
|
|
panel.style.display = 'block';
|
|
btn.textContent = '收起筛选 ▲';
|
|
} else {
|
|
panel.style.display = 'none';
|
|
btn.textContent = '展开筛选 ▼';
|
|
}
|
|
}
|
|
|
|
async function loadHistory(page) {
|
|
page = page || 1;
|
|
currentHistoryPage = page;
|
|
let startDate = document.getElementById('historyStartDate').value;
|
|
let endDate = document.getElementById('historyEndDate').value;
|
|
let studentId = document.getElementById('historyStudentId').value;
|
|
let reasonFilter = document.getElementById('historyReasonFilter').value;
|
|
let subjectFilter = document.getElementById('historySubjectFilter').value;
|
|
let reasonSearch = document.getElementById('historyReasonSearch').value.trim();
|
|
let isGrouped = document.getElementById('historyGrouped').checked;
|
|
let statusFilter = document.getElementById('historyStatusFilter') ? document.getElementById('historyStatusFilter').value : '';
|
|
|
|
// 筛选学生时强制取消合并
|
|
if (studentId) isGrouped = false;
|
|
|
|
let params = {
|
|
page: page, page_size: 20,
|
|
start_date: startDate,
|
|
end_date: endDate
|
|
};
|
|
if (studentId) params.student_id = studentId;
|
|
|
|
// 科目筛选优先于扣分类型筛选
|
|
if (subjectFilter) {
|
|
params.reason_prefix = '[' + subjectFilter + ']';
|
|
} else if (reasonFilter) {
|
|
params.reason_prefix = reasonFilter;
|
|
}
|
|
|
|
if (reasonSearch) params.reason_search = reasonSearch;
|
|
if (isGrouped) params.grouped = true;
|
|
if (statusFilter !== '') params.is_revoked = parseInt(statusFilter);
|
|
|
|
let res = await apiGet('/api/admin/conduct/history', params);
|
|
|
|
if (res && res.success) {
|
|
let nowrapStyle = ' style="white-space:nowrap;min-width:80px;"';
|
|
let headHtml = '';
|
|
if (isGrouped) {
|
|
headHtml = '<th>类型</th><th>分值</th><th>原因</th><th>学生名单</th><th' + nowrapStyle + '>操作人</th><th>时间</th>';
|
|
if (role === '班主任' || role === '班长') {
|
|
headHtml += '<th>操作</th>';
|
|
}
|
|
} else {
|
|
headHtml = '<th>类型</th><th>分值</th><th>原因</th><th>学生</th><th' + nowrapStyle + '>操作人</th><th>时间</th>';
|
|
if (role === '班主任' || role === '班长' || role === '考勤委员') {
|
|
headHtml += '<th>操作</th>';
|
|
}
|
|
}
|
|
document.getElementById('historyTableHead').innerHTML = headHtml;
|
|
|
|
let html = '';
|
|
if (isGrouped) {
|
|
res.data.records.forEach(function(record) {
|
|
let pointsClass = record.points_change > 0 ? 'plus' : 'minus';
|
|
let names = record.student_names || '';
|
|
let allRevoked = record.all_revoked;
|
|
let revokedStyle = allRevoked ? ' style="opacity:0.5;text-decoration:line-through;"' : '';
|
|
html += '<tr' + revokedStyle + '>' +
|
|
'<td>' + escapeHtml(getTypeLabel(record.related_type)) + '</td>' +
|
|
'<td class="' + pointsClass + '">' + (record.points_change > 0 ? '+' : '') + record.points_change + '×' + record.student_count + '</td>' +
|
|
'<td class="history-reason">' + escapeHtml(record.reason) + '</td>' +
|
|
'<td class="history-students">' + escapeHtml(names) + '</td>' +
|
|
'<td>' + escapeHtml(record.recorder_name || '') + '</td>' +
|
|
'<td class="history-time">' + formatDateTime(record.created_at) + '</td>';
|
|
if (role === '班主任' || role === '班长') {
|
|
if (allRevoked) {
|
|
html += '<td><span class="text-muted">已撤销</span></td>';
|
|
} else {
|
|
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>';
|
|
}
|
|
}
|
|
html += '</tr>';
|
|
});
|
|
if (res.data.records.length === 0) {
|
|
let colSpan = (role === '班主任' || role === '班长') ? 7 : 6;
|
|
html = '<tr><td colspan="' + colSpan + '" style="text-align:center;">暂无记录</td></tr>';
|
|
}
|
|
} else {
|
|
res.data.records.forEach(function(record) {
|
|
let pointsClass = record.points_change > 0 ? 'plus' : 'minus';
|
|
let revokedStyle = record.is_revoked == 1 ? ' style="opacity:0.5;text-decoration:line-through;"' : '';
|
|
html += '<tr' + revokedStyle + '>' +
|
|
'<td>' + escapeHtml(getTypeLabel(record.related_type)) + '</td>' +
|
|
'<td class="' + pointsClass + '">' + (record.points_change > 0 ? '+' : '') + record.points_change + '</td>' +
|
|
'<td class="history-reason">' + escapeHtml(record.reason) + '</td>' +
|
|
'<td>' + escapeHtml(record.student_name) + '</td>' +
|
|
'<td>' + escapeHtml(record.recorder_name) + '</td>' +
|
|
'<td class="history-time">' + formatDateTime(record.created_at) + '</td>';
|
|
if (role === '班主任') {
|
|
if (record.is_revoked == 1) {
|
|
let revokerInfo = record.revoker_name ? '由 ' + escapeHtml(record.revoker_name) + ' 撤销' : '已撤销';
|
|
html += '<td><span class="text-muted" style="margin-right:4px;">' + revokerInfo + '</span><button class="btn btn-sm btn-outline" onclick="restoreRecord(' + record.record_id + ')">反撤销</button></td>';
|
|
} else {
|
|
html += '<td><button class="btn btn-sm btn-outline" onclick="revokeRecord(' + record.record_id + ')">撤销</button></td>';
|
|
}
|
|
} else if (role === '班长') {
|
|
if (record.is_revoked == 1) {
|
|
let revokerInfo = record.revoker_name ? '由 ' + escapeHtml(record.revoker_name) + ' 撤销' : '已撤销';
|
|
html += '<td><span class="text-muted">' + revokerInfo + '</span></td>';
|
|
} else {
|
|
html += '<td><button class="btn btn-sm btn-outline" onclick="revokeRecord(' + record.record_id + ')">撤销</button></td>';
|
|
}
|
|
} else if (role === '考勤委员') {
|
|
if (record.is_revoked == 1) {
|
|
html += '<td><span class="text-muted">已撤销</span></td>';
|
|
} else if (record.recorder_id == currentUserId) {
|
|
html += '<td><button class="btn btn-sm btn-outline" onclick="revokeRecord(' + record.record_id + ')">撤销</button></td>';
|
|
} else {
|
|
html += '<td><span class="text-muted">-</span></td>';
|
|
}
|
|
}
|
|
html += '</tr>';
|
|
});
|
|
|
|
if (res.data.records.length === 0) {
|
|
let colSpan = (role === '班主任' || role === '班长' || role === '考勤委员') ? 7 : 6;
|
|
html = '<tr><td colspan="' + colSpan + '" style="text-align:center;">暂无记录</td></tr>';
|
|
}
|
|
}
|
|
|
|
document.getElementById('historyList').innerHTML = html;
|
|
|
|
totalHistoryPages = res.data.total_pages || 1;
|
|
renderHistoryPagination();
|
|
}
|
|
}
|
|
|
|
function renderHistoryPagination() {
|
|
renderSmartPagination('historyPagination', currentHistoryPage, totalHistoryPages, function(page) {
|
|
loadHistory(page);
|
|
});
|
|
}
|
|
|
|
async function exportHistoryRecords() {
|
|
let startDate = document.getElementById('historyStartDate').value;
|
|
let endDate = document.getElementById('historyEndDate').value;
|
|
let studentId = document.getElementById('historyStudentId').value;
|
|
|
|
showToast('正在导出历史记录...', 'info');
|
|
|
|
try {
|
|
let reasonFilter = document.getElementById('historyReasonFilter').value;
|
|
let subjectFilter = document.getElementById('historySubjectFilter').value;
|
|
let reasonSearch = document.getElementById('historyReasonSearch').value.trim();
|
|
let params = { page: 1, page_size: 1000 };
|
|
if (startDate) params.start_date = startDate;
|
|
if (endDate) params.end_date = endDate;
|
|
if (studentId) params.student_id = studentId;
|
|
if (subjectFilter) {
|
|
params.reason_prefix = '[' + subjectFilter + ']';
|
|
} else if (reasonFilter) {
|
|
params.reason_prefix = reasonFilter;
|
|
}
|
|
if (reasonSearch) params.reason_search = reasonSearch;
|
|
|
|
let res = await apiGet('/api/admin/conduct/history', params);
|
|
if (res && res.success && res.data.records) {
|
|
let records = res.data.records;
|
|
if (records.length === 0) {
|
|
showToast('没有找到记录', 'warning');
|
|
return;
|
|
}
|
|
|
|
function csvField(val) {
|
|
let s = String(val == null ? '' : val);
|
|
if (s.indexOf(',') >= 0 || s.indexOf('"') >= 0 || s.indexOf('\n') >= 0) {
|
|
return '"' + s.replace(/"/g, '""') + '"';
|
|
}
|
|
return s;
|
|
}
|
|
let csv = '\uFEFF';
|
|
csv += '时间,学号,姓名,分数变动,原因,操作人\n';
|
|
records.forEach(function(r) {
|
|
if (r.is_revoked == 1) return;
|
|
csv += csvField(r.created_at) + ',' + csvField(r.student_no) + ',' + csvField(r.student_name) + ',' + csvField((r.points_change > 0 ? '+' : '') + r.points_change) + ',' + csvField(r.reason) + ',' + csvField(r.recorder_name) + '\n';
|
|
});
|
|
|
|
let blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
|
|
let url = URL.createObjectURL(blob);
|
|
let link = document.createElement('a');
|
|
link.href = url;
|
|
link.download = '历史记录_' + new Date().toISOString().slice(0,10) + '.csv';
|
|
document.body.appendChild(link);
|
|
link.click();
|
|
document.body.removeChild(link);
|
|
URL.revokeObjectURL(url);
|
|
|
|
showToast('导出成功,共' + records.length + '条记录');
|
|
} else {
|
|
showToast('导出失败:' + (res && res.message || '未知错误'), 'error');
|
|
}
|
|
} catch (err) {
|
|
showToast('导出失败:' + err.message, 'error');
|
|
}
|
|
}
|
|
|
|
// 批量撤销合并记录(按条件查找并撤销)
|
|
async function batchRevokeGrouped(reason, pointsChange, recorderName, createdAt) {
|
|
if (!confirm('确定要撤销所有"' + reason + '"(' + (pointsChange > 0 ? '+' : '') + pointsChange + '分)的记录吗?')) return;
|
|
|
|
showToast('正在批量撤销...', 'info');
|
|
|
|
try {
|
|
let params = {
|
|
page: 1, page_size: 1000,
|
|
start_date: document.getElementById('historyStartDate').value,
|
|
end_date: document.getElementById('historyEndDate').value,
|
|
reason_prefix: reason,
|
|
grouped: false
|
|
};
|
|
|
|
let res = await apiGet('/api/admin/conduct/history', params);
|
|
if (!res || !res.success || !res.data.records) {
|
|
showToast('查询记录失败', 'error');
|
|
return;
|
|
}
|
|
|
|
let matchedIds = [];
|
|
res.data.records.forEach(function(r) {
|
|
if (r.reason === reason && r.points_change === pointsChange && r.is_revoked == 0) {
|
|
matchedIds.push(r.record_id);
|
|
}
|
|
});
|
|
|
|
if (matchedIds.length === 0) {
|
|
showToast('没有找到可撤销的记录', 'warning');
|
|
return;
|
|
}
|
|
|
|
let revokeRes = await apiPost('/api/admin/conduct/batch-revoke', { record_ids: matchedIds });
|
|
if (revokeRes && revokeRes.success) {
|
|
showToast('批量撤销完成: ' + (revokeRes.data ? revokeRes.data.success_count : 0) + '条成功');
|
|
loadHistory(currentHistoryPage);
|
|
} else {
|
|
showToast(revokeRes && revokeRes.message || '批量撤销失败', 'error');
|
|
}
|
|
} catch (err) {
|
|
showToast('批量撤销失败: ' + err.message, 'error');
|
|
}
|
|
}
|
|
|
|
// 初始化:并行加载学生和科目列表,然后加载历史记录
|
|
Promise.all([loadStudentsForSelect(), loadSubjectsForFilter()]).then(function() {
|
|
let urlParams = new URLSearchParams(window.location.search);
|
|
let preStudentId = urlParams.get('student_id');
|
|
if (preStudentId) {
|
|
document.getElementById('historyStudentId').value = preStudentId;
|
|
onStudentFilterChange();
|
|
}
|
|
loadHistory();
|
|
});
|
|
|
|
window.loadHistory = loadHistory;
|
|
window.loadStudentsForSelect = loadStudentsForSelect;
|
|
window.exportHistoryRecords = exportHistoryRecords;
|
|
window.batchRevokeGrouped = batchRevokeGrouped;
|
|
window.onStudentFilterChange = onStudentFilterChange;
|
|
window.onSubjectFilterChange = onSubjectFilterChange;
|
|
window.toggleFilterPanel = toggleFilterPanel;
|
|
|
|
})();
|