v4.0 权限组重构与导出/个人查询优化
1. 权限重构:自定义权限组(14项功能权限+允许加分/加分上限/允许扣分/扣分上限),管理员账号绑定权限组,预置六组且班主任组锁定;全站前后端改为权限驱动,权限变更60秒内自动生效 2. 新增班主任导出学生名单(导出前自选字段) 3. 加减分/考勤上限改为按权限组动态校验,弹窗实时提示并限制输入 4. 导出按学期隔离(默认当前学期,可选历史/全部),历史导出不再受1000条限制 5. 新增管理端个人查询:基础分/加分/扣分/月度分/月度理由汇总及明细导出 6. 版本升级至4.0(sql/upgrades/v4.0.sql)
This commit is contained in:
1 parent
3067542e53
commit
3588b4c28c
55 files changed
+2846
-801
No files matched your search
@@ -0,0 +1,315 @@
|
||||
/**
|
||||
* 班级操行分管理系统 - 个人记录查询页JS
|
||||
*
|
||||
* 开发者: Canglan
|
||||
* 版权归属: Sea Network Technology Studio
|
||||
*
|
||||
* 版权所有 © Sea Network Technology Studio
|
||||
*/
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
const canRevokeAny = hasPermission('revoke_any');
|
||||
const canRevokeOwn = hasPermission('revoke_own');
|
||||
const canRestore = hasPermission('restore_records');
|
||||
const canManage = canRevokeAny || canRevokeOwn;
|
||||
let currentStudentId = null;
|
||||
let currentPage = 1;
|
||||
|
||||
function typeMap(relatedType) {
|
||||
var map = { manual: '手动', homework: '作业', attendance: '考勤' };
|
||||
return map[relatedType] || '手动';
|
||||
}
|
||||
|
||||
function monthLabel(month) {
|
||||
if (!month || month.indexOf('-') < 0) return month || '-';
|
||||
var parts = month.split('-');
|
||||
return parts[0] + '年' + parseInt(parts[1], 10) + '月';
|
||||
}
|
||||
|
||||
async function loadStudents() {
|
||||
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('queryStudentId').innerHTML = html;
|
||||
}
|
||||
}
|
||||
|
||||
async function queryStudentRecords(page) {
|
||||
const studentId = document.getElementById('queryStudentId').value;
|
||||
if (!studentId) {
|
||||
showToast('请先选择学生', 'warning');
|
||||
return;
|
||||
}
|
||||
currentStudentId = studentId;
|
||||
currentPage = page || 1;
|
||||
const semesterId = document.getElementById('querySemesterId').value;
|
||||
|
||||
document.getElementById('queryPlaceholder').style.display = 'none';
|
||||
document.getElementById('queryResult').style.display = 'block';
|
||||
|
||||
await Promise.all([
|
||||
loadSummary(studentId, semesterId),
|
||||
loadRecords(studentId, semesterId, currentPage)
|
||||
]);
|
||||
}
|
||||
|
||||
function onQueryStudentChange() {
|
||||
if (!document.getElementById('queryStudentId').value) {
|
||||
document.getElementById('queryResult').style.display = 'none';
|
||||
document.getElementById('queryPlaceholder').style.display = 'block';
|
||||
return;
|
||||
}
|
||||
queryStudentRecords(1);
|
||||
}
|
||||
|
||||
function onQuerySemesterChange() {
|
||||
if (document.getElementById('queryStudentId').value) {
|
||||
queryStudentRecords(1);
|
||||
}
|
||||
}
|
||||
|
||||
async function loadSummary(studentId, semesterId) {
|
||||
const params = { student_id: studentId };
|
||||
if (semesterId) params.semester_id = semesterId;
|
||||
|
||||
const res = await apiGet('/api/admin/conduct/student-summary', params);
|
||||
if (!res || !res.success) {
|
||||
showToast((res && res.message) || '获取汇总失败', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
const data = res.data;
|
||||
const semesterName = data.semester ? data.semester.semester_name : '全部学期';
|
||||
document.getElementById('queryStudentTitle').textContent =
|
||||
data.student.name + '(' + data.student.student_no + ') - ' + semesterName;
|
||||
|
||||
const s = data.summary;
|
||||
document.getElementById('querySummaryCards').innerHTML =
|
||||
'<div class="stat-card"><div class="stat-label">基础分</div><div class="stat-value">' + data.base_points + '</div></div>' +
|
||||
'<div class="stat-card"><div class="stat-label">加分合计</div><div class="stat-value plus">+' + s.bonus_total + '</div></div>' +
|
||||
'<div class="stat-card"><div class="stat-label">减分合计</div><div class="stat-value minus">' + s.deduction_total + '</div></div>' +
|
||||
'<div class="stat-card"><div class="stat-label">得分(基础分+加减分)</div><div class="stat-value">' + s.computed_total + '</div></div>' +
|
||||
'<div class="stat-card"><div class="stat-label">当前实时总分</div><div class="stat-value">' + s.current_total_points + '</div></div>';
|
||||
|
||||
document.getElementById('querySummaryHint').textContent =
|
||||
'共 ' + s.record_count + ' 条有效记录(不含已撤销)。' +
|
||||
(data.semester ? '学期得分按“基础分 + 学期内加分 - 学期内减分”计算。' : '全部学期得分按“基础分 + 全部加分 - 全部减分”计算,仅供参考。');
|
||||
|
||||
renderMonthly(data.months);
|
||||
renderReasonSummary(data.months);
|
||||
}
|
||||
|
||||
function renderMonthly(months) {
|
||||
let html = '';
|
||||
if (!months || months.length === 0) {
|
||||
html = '<tr><td colspan="6" style="text-align:center;">暂无记录</td></tr>';
|
||||
} else {
|
||||
months.forEach(m => {
|
||||
html += '<tr>' +
|
||||
'<td>' + escapeHtml(monthLabel(m.month)) + '</td>' +
|
||||
'<td>' + m.start_score + '</td>' +
|
||||
'<td class="plus">+' + m.bonus + '</td>' +
|
||||
'<td class="minus">' + m.deduction + '</td>' +
|
||||
'<td><strong>' + m.end_score + '</strong></td>' +
|
||||
'<td>' + m.record_count + '</td>' +
|
||||
'</tr>';
|
||||
});
|
||||
}
|
||||
document.getElementById('queryMonthlyList').innerHTML = html;
|
||||
}
|
||||
|
||||
function renderReasonTable(reasons, emptyText) {
|
||||
if (!reasons || reasons.length === 0) {
|
||||
return '<div style="color:var(--color-text-secondary); font-size:12px; padding:8px 0;">' + emptyText + '</div>';
|
||||
}
|
||||
let html = '<table class="table"><thead><tr><th>理由</th><th style="width:60px;">次数</th><th style="width:80px;">合计</th></tr></thead><tbody>';
|
||||
reasons.forEach(r => {
|
||||
html += '<tr>' +
|
||||
'<td>' + escapeHtml(r.reason) + '</td>' +
|
||||
'<td>' + r.count + '</td>' +
|
||||
'<td class="' + (r.points > 0 ? 'plus' : 'minus') + '">' + (r.points > 0 ? '+' : '') + r.points + '</td>' +
|
||||
'</tr>';
|
||||
});
|
||||
html += '</tbody></table>';
|
||||
return html;
|
||||
}
|
||||
|
||||
function renderReasonSummary(months) {
|
||||
const container = document.getElementById('queryReasonSummary');
|
||||
if (!months || months.length === 0) {
|
||||
container.innerHTML = '<div style="text-align:center; color:var(--color-text-secondary); padding:16px 0;">暂无记录</div>';
|
||||
return;
|
||||
}
|
||||
let html = '';
|
||||
months.forEach(m => {
|
||||
html += '<div style="margin-bottom: 20px;">' +
|
||||
'<div style="font-weight: bold; margin-bottom: 8px;">' + escapeHtml(monthLabel(m.month)) +
|
||||
' <span style="font-weight: normal; font-size: 12px; color: var(--color-text-secondary);">' +
|
||||
'加分 +' + m.bonus + ' / 减分 ' + m.deduction + '</span></div>' +
|
||||
'<div style="display:grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px;">' +
|
||||
'<div><div style="color:var(--color-success); font-size:13px; margin-bottom:4px;">加分理由</div>' + renderReasonTable(m.bonus_reasons, '本月无加分') + '</div>' +
|
||||
'<div><div style="color:var(--color-danger); font-size:13px; margin-bottom:4px;">减分理由</div>' + renderReasonTable(m.deduction_reasons, '本月无减分') + '</div>' +
|
||||
'</div></div>';
|
||||
});
|
||||
container.innerHTML = html;
|
||||
}
|
||||
|
||||
async function loadRecords(studentId, semesterId, page) {
|
||||
const params = { student_id: studentId, page: page || 1, page_size: 20 };
|
||||
if (semesterId) params.semester_id = semesterId;
|
||||
|
||||
const res = await apiGet('/api/admin/conduct/history', params);
|
||||
if (!res || !res.success) {
|
||||
showToast('获取明细记录失败', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
const records = res.data.records || [];
|
||||
let html = '';
|
||||
records.forEach(record => {
|
||||
const pointsClass = record.points_change > 0 ? 'plus' : 'minus';
|
||||
const revokedStyle = record.is_revoked == 1 ? ' style="opacity:0.5;text-decoration:line-through;"' : '';
|
||||
html += '<tr' + revokedStyle + '>' +
|
||||
'<td>' + typeMap(record.related_type) + '</td>' +
|
||||
'<td class="' + pointsClass + '">' + (record.points_change > 0 ? '+' : '') + record.points_change + '</td>' +
|
||||
'<td>' + escapeHtml(record.reason) + '</td>' +
|
||||
'<td>' + escapeHtml(record.recorder_name || '') + '</td>' +
|
||||
'<td style="white-space:nowrap;">' + formatDateTime(record.created_at) + '</td>';
|
||||
if (canManage) {
|
||||
if (record.is_revoked == 1) {
|
||||
if (canRestore) {
|
||||
html += '<td><span class="text-muted">已撤销</span> <button class="btn btn-sm btn-outline" onclick="restoreQueryRecord(' + record.record_id + ')">反撤销</button></td>';
|
||||
} else {
|
||||
html += '<td><span class="text-muted">已撤销</span></td>';
|
||||
}
|
||||
} else if (canRevokeAny || (canRevokeOwn && record.recorder_id == window.PAGE_CONFIG.userId)) {
|
||||
html += '<td><button class="btn btn-sm btn-outline" onclick="revokeQueryRecord(' + record.record_id + ')">撤销</button></td>';
|
||||
} else {
|
||||
html += '<td><span class="text-muted">-</span></td>';
|
||||
}
|
||||
}
|
||||
html += '</tr>';
|
||||
});
|
||||
|
||||
if (records.length === 0) {
|
||||
html = '<tr><td colspan="' + (canManage ? 6 : 5) + '" style="text-align:center;">暂无记录</td></tr>';
|
||||
}
|
||||
document.getElementById('queryRecordList').innerHTML = html;
|
||||
|
||||
const totalPages = res.data.total_pages || 1;
|
||||
renderSmartPagination('queryPagination', page || 1, totalPages, function(p) {
|
||||
currentPage = p;
|
||||
loadRecords(currentStudentId, document.getElementById('querySemesterId').value, p);
|
||||
});
|
||||
}
|
||||
|
||||
async function revokeQueryRecord(recordId) {
|
||||
if (!confirm('确定要撤销这条记录吗?撤销后学生分数将恢复。')) return;
|
||||
const res = await apiPost('/api/admin/conduct/revoke', { record_id: recordId });
|
||||
if (res && res.success) {
|
||||
showToast('撤销成功');
|
||||
queryStudentRecords(currentPage);
|
||||
} else {
|
||||
showToast((res && res.message) || '撤销失败', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async function restoreQueryRecord(recordId) {
|
||||
if (!confirm('确定要反撤销这条记录吗?分数变动将重新生效。')) return;
|
||||
const res = await apiPost('/api/admin/conduct/restore', { record_id: recordId });
|
||||
if (res && res.success) {
|
||||
showToast('反撤销成功');
|
||||
queryStudentRecords(currentPage);
|
||||
} else {
|
||||
showToast((res && res.message) || '反撤销失败', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async function exportStudentRecords() {
|
||||
const studentId = document.getElementById('queryStudentId').value;
|
||||
if (!studentId) {
|
||||
showToast('请先选择学生', 'warning');
|
||||
return;
|
||||
}
|
||||
const semesterSelect = document.getElementById('querySemesterId');
|
||||
const semesterId = semesterSelect.value;
|
||||
const semesterName = (semesterSelect.selectedIndex >= 0)
|
||||
? semesterSelect.options[semesterSelect.selectedIndex].textContent.replace(/((当前|已归档))$/, '')
|
||||
: '全部学期';
|
||||
const studentName = document.getElementById('queryStudentId').selectedOptions[0].textContent.trim();
|
||||
|
||||
showToast('正在导出个人记录...', 'info');
|
||||
|
||||
try {
|
||||
const params = { student_id: studentId, is_revoked: 0 };
|
||||
if (semesterId) params.semester_id = semesterId;
|
||||
const records = await apiGetAll('/api/admin/conduct/history', params);
|
||||
|
||||
let summaryLines = [];
|
||||
const summaryParams = { student_id: studentId };
|
||||
if (semesterId) summaryParams.semester_id = semesterId;
|
||||
const summaryRes = await apiGet('/api/admin/conduct/student-summary', summaryParams);
|
||||
if (summaryRes && summaryRes.success) {
|
||||
const d = summaryRes.data;
|
||||
summaryLines = [
|
||||
['学生', studentName],
|
||||
['学期', semesterName],
|
||||
['基础分', d.base_points],
|
||||
['加分合计', d.summary.bonus_total],
|
||||
['减分合计', d.summary.deduction_total],
|
||||
['得分(基础分+加减分)', d.summary.computed_total],
|
||||
['当前实时总分', d.summary.current_total_points]
|
||||
];
|
||||
}
|
||||
|
||||
let csv = '';
|
||||
summaryLines.forEach(line => {
|
||||
csv += [line[0], line[1]].map(csvEscape).join(',') + '\n';
|
||||
});
|
||||
csv += '\n时间,类型,分值,原因,操作人,状态\n';
|
||||
records.forEach(r => {
|
||||
csv += [
|
||||
r.created_at || '',
|
||||
typeMap(r.related_type),
|
||||
(r.points_change > 0 ? '+' : '') + r.points_change,
|
||||
r.reason || '',
|
||||
r.recorder_name || '',
|
||||
r.is_revoked == 1 ? '已撤销' : '正常'
|
||||
].map(csvEscape).join(',') + '\n';
|
||||
});
|
||||
|
||||
const safeLabel = (semesterName || '全部学期').replace(/[\\/:*?"<>|]/g, '_');
|
||||
downloadCsv('个人记录_' + studentName + '_' + safeLabel + '_' + new Date().toISOString().slice(0,10) + '.csv', csv);
|
||||
showToast('导出成功,共' + records.length + '条明细记录');
|
||||
} catch (err) {
|
||||
showToast('导出失败:' + err.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
(async function init() {
|
||||
await Promise.all([
|
||||
loadStudents(),
|
||||
loadSemesterOptions('querySemesterId', { includeAll: true })
|
||||
]);
|
||||
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const preStudentId = urlParams.get('student_id');
|
||||
if (preStudentId) {
|
||||
document.getElementById('queryStudentId').value = preStudentId;
|
||||
queryStudentRecords(1);
|
||||
}
|
||||
})();
|
||||
|
||||
window.queryStudentRecords = queryStudentRecords;
|
||||
window.onQueryStudentChange = onQueryStudentChange;
|
||||
window.onQuerySemesterChange = onQuerySemesterChange;
|
||||
window.exportStudentRecords = exportStudentRecords;
|
||||
window.revokeQueryRecord = revokeQueryRecord;
|
||||
window.restoreQueryRecord = restoreQueryRecord;
|
||||
|
||||
})();
|
||||
Reference in new issue
Block a user