Files
canglan ed3189096d 权限组全自定义、月度分独立、绑定邮箱免密与样式统一
1. 权限组:去掉锁定/预置限制,所有组可编辑/删除/分配;管理员新增/编辑可选任意组;管理员列表不再显示锁定徽标
2. 个人查询:月度分独立计算(当月净得分,与基础分无关),总分=基础分+加分-减分
3. 绑定邮箱:发送验证码与确认绑定不再需要密码(解绑仍需密码)
4. 权限组编辑UI:权限项按 学生/操行分/教务/系统管理 分区,支持全选/清空,上限两行布局,弹窗加宽
5. 样式统一:颜色变量化(硬编码色值清零)、check-grid/check-item 统一复选框网格、cell-wrap、subject-status 全局化、success-msg
6. 旧库升级期兼容保留(登录/权限降级、待升级提示)
7. 文档同步更新
2026-09-18 09:56:39 +08:00

316 lines
13 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 班级操行分管理系统 - 个人记录查询页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 + ' 条有效记录(不含已撤销)。' +
'月度分为当月加分与减分的净得分,与基础分无关;总分 = 基础分 + 全部加分 - 全部减分。';
renderMonthly(data.months);
renderReasonSummary(data.months);
}
function renderMonthly(months) {
let html = '';
if (!months || months.length === 0) {
html = '<tr><td colspan="5" style="text-align:center;">暂无记录</td></tr>';
} else {
months.forEach(m => {
const monthScore = (typeof m.month_score === 'number') ? m.month_score : ((m.bonus || 0) + (m.deduction || 0));
html += '<tr>' +
'<td>' + escapeHtml(monthLabel(m.month)) + '</td>' +
'<td class="plus">+' + m.bonus + '</td>' +
'<td class="minus">' + m.deduction + '</td>' +
'<td><strong>' + (monthScore > 0 ? '+' : '') + monthScore + '</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;
})();