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
@@ -10,17 +10,26 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
const canViewPersonalQuery = hasPermission('view_all_records');
|
||||
const canManageConduct = hasPermission('manage_conduct');
|
||||
|
||||
async function loadStudents() {
|
||||
const res = await apiGet('/api/admin/students', {page_size: 1000});
|
||||
if (res && res.success) {
|
||||
let html = '';
|
||||
res.data.students.forEach(student => {
|
||||
const detailUrl = canViewPersonalQuery
|
||||
? `/admin/record_query.php?student_id=${student.student_id}`
|
||||
: `/admin/history.php?student_id=${student.student_id}`;
|
||||
const pointsButton = canManageConduct
|
||||
? `<button class="btn btn-sm btn-outline" onclick="showSinglePointsModal(${student.student_id}, '${escapeHtml(student.name)}')">加减分</button>`
|
||||
: '<span class="text-muted">-</span>';
|
||||
html += `<tr>
|
||||
<td><input type="checkbox" class="student-checkbox" data-id="${student.student_id}"></td>
|
||||
<td>${escapeHtml(student.student_no)}</td>
|
||||
<td><a href="/admin/history.php?student_id=${student.student_id}" class="link">${escapeHtml(student.name)}</a></td>
|
||||
<td><a href="${detailUrl}" class="link">${escapeHtml(student.name)}</a></td>
|
||||
<td>${student.total_points}</td>
|
||||
<td><button class="btn btn-sm btn-outline" onclick="showSinglePointsModal(${student.student_id}, '${escapeHtml(student.name)}')">加减分</button></td>
|
||||
<td>${pointsButton}</td>
|
||||
</tr>`;
|
||||
});
|
||||
if (res.data.students.length === 0) {
|
||||
@@ -35,10 +44,45 @@ function showSinglePointsModal(studentId, studentName) {
|
||||
document.getElementById('selectedStudentsCount').innerHTML = `${studentName} (1人)`;
|
||||
document.getElementById('pointsChange').value = '';
|
||||
document.getElementById('pointsReason').value = '';
|
||||
if (typeof preparePointsLimitHint === 'function') preparePointsLimitHint();
|
||||
document.getElementById('batchPointsModal').style.display = 'flex';
|
||||
}
|
||||
|
||||
function initPointsLimitHint() {
|
||||
const hintEl = document.getElementById('pointsLimitHint');
|
||||
if (hintEl) hintEl.textContent = describeScoreLimits();
|
||||
}
|
||||
|
||||
async function showExportMoralityModal() {
|
||||
await loadSemesterOptions('exportSemesterSelect', { includeAll: true });
|
||||
document.getElementById('exportMoralityModal').style.display = 'flex';
|
||||
}
|
||||
|
||||
function buildExportRow(student, semesterLabel, records, basePoints) {
|
||||
const positiveRecords = records.filter(r => r.points_change > 0);
|
||||
const negativeRecords = records.filter(r => r.points_change < 0);
|
||||
const bonus = positiveRecords.reduce((sum, r) => sum + r.points_change, 0);
|
||||
const deduction = negativeRecords.reduce((sum, r) => sum + r.points_change, 0);
|
||||
return {
|
||||
student_no: student.student_no,
|
||||
name: student.name,
|
||||
semester: semesterLabel,
|
||||
base: basePoints,
|
||||
bonus: bonus,
|
||||
deduction: deduction,
|
||||
score: records.length ? basePoints + bonus + deduction : (student.total_points || 0),
|
||||
current: student.total_points || 0,
|
||||
positive: positiveRecords.map(r => `${r.reason}(+${r.points_change})`).join('; '),
|
||||
negative: negativeRecords.map(r => `${r.reason}(${r.points_change})`).join('; ')
|
||||
};
|
||||
}
|
||||
|
||||
async function exportMoralityRecords() {
|
||||
const select = document.getElementById('exportSemesterSelect');
|
||||
const semesterId = select ? select.value : '';
|
||||
const selectedOption = select && select.selectedIndex >= 0 ? select.options[select.selectedIndex] : null;
|
||||
const semesterName = selectedOption ? selectedOption.textContent.replace(/((当前|已归档))$/, '') : '全部学期';
|
||||
|
||||
showToast('正在导出德育分记录...', 'info');
|
||||
|
||||
try {
|
||||
@@ -54,65 +98,49 @@ async function exportMoralityRecords() {
|
||||
return;
|
||||
}
|
||||
|
||||
const historyRes = await apiGet('/api/admin/conduct/history', { page: 1, page_size: 1000 });
|
||||
if (!historyRes || !historyRes.success) {
|
||||
showToast('获取历史记录失败', 'error');
|
||||
return;
|
||||
}
|
||||
const params = { is_revoked: 0 };
|
||||
if (semesterId) params.semester_id = semesterId;
|
||||
const allRecords = await apiGetAll('/api/admin/conduct/history', params);
|
||||
|
||||
const allRecords = historyRes.data.records || [];
|
||||
const basePoints = parseInt(window.STUDENT_INITIAL_POINTS || 60, 10) || 60;
|
||||
|
||||
const recordsByStudent = {};
|
||||
// 按 学生 + 学期 分组
|
||||
const groups = {};
|
||||
allRecords.forEach(record => {
|
||||
const sid = record.student_id;
|
||||
if (!recordsByStudent[sid]) {
|
||||
recordsByStudent[sid] = [];
|
||||
}
|
||||
recordsByStudent[sid].push(record);
|
||||
const label = semesterId ? semesterName : (record.semester_name || '未关联学期');
|
||||
const key = record.student_id + '|' + label;
|
||||
if (!groups[key]) groups[key] = [];
|
||||
groups[key].push(record);
|
||||
});
|
||||
|
||||
const studentRecords = [];
|
||||
for (const student of students) {
|
||||
const studentRecords_list = recordsByStudent[student.student_id] || [];
|
||||
const positiveRecords = studentRecords_list.filter(r => r.points_change > 0).map(r => `${r.reason}(+${r.points_change})`);
|
||||
const negativeRecords = studentRecords_list.filter(r => r.points_change < 0).map(r => `${r.reason}(${r.points_change})`);
|
||||
|
||||
studentRecords.push({
|
||||
student_no: student.student_no,
|
||||
name: student.name,
|
||||
total_points: student.total_points || 0,
|
||||
positive_history: positiveRecords.join('; '),
|
||||
negative_history: negativeRecords.join('; ')
|
||||
});
|
||||
}
|
||||
|
||||
function escapeCsvField(field) {
|
||||
if (field === null || field === undefined) return '';
|
||||
let str = String(field).replace(/[\r\n]+/g, ' ');
|
||||
str = str.replace(/"/g, '""');
|
||||
if (/[\,\;\"\s]/.test(str)) {
|
||||
str = '"' + str + '"';
|
||||
const rows = [];
|
||||
students.forEach(student => {
|
||||
if (semesterId) {
|
||||
const key = student.student_id + '|' + semesterName;
|
||||
rows.push(buildExportRow(student, semesterName, groups[key] || [], basePoints));
|
||||
} else {
|
||||
const prefix = student.student_id + '|';
|
||||
const labels = Object.keys(groups).filter(k => k.indexOf(prefix) === 0);
|
||||
if (labels.length === 0) {
|
||||
rows.push(buildExportRow(student, '-', [], basePoints));
|
||||
} else {
|
||||
labels.forEach(key => {
|
||||
rows.push(buildExportRow(student, key.substring(prefix.length), groups[key], basePoints));
|
||||
});
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
let csv = '\uFEFF';
|
||||
csv += '学号,姓名,分数,加分历史,减分记录\n';
|
||||
studentRecords.forEach(s => {
|
||||
csv += `${escapeCsvField(s.student_no)},${escapeCsvField(s.name)},${escapeCsvField(s.total_points)},${escapeCsvField(s.positive_history)},${escapeCsvField(s.negative_history)}\n`;
|
||||
});
|
||||
|
||||
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const 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);
|
||||
let csv = '学号,姓名,学期,基础分,加分合计,减分合计,学期得分,当前总分,加分历史,减分记录\n';
|
||||
rows.forEach(r => {
|
||||
csv += [r.student_no, r.name, r.semester, r.base, r.bonus, r.deduction, r.score, r.current, r.positive, r.negative]
|
||||
.map(csvEscape).join(',') + '\n';
|
||||
});
|
||||
|
||||
showToast(`导出成功,共${studentRecords.length}名学生`);
|
||||
const safeSemester = (semesterName || '全部学期').replace(/[\\/:*?"<>|]/g, '_');
|
||||
downloadCsv(`德育分记录_${safeSemester}_${new Date().toISOString().slice(0,10)}.csv`, csv);
|
||||
closeModal('exportMoralityModal');
|
||||
showToast(`导出成功,共${rows.length}条学生记录`);
|
||||
} catch (err) {
|
||||
showToast('导出失败:' + err.message, 'error');
|
||||
console.error('导出失败:', err);
|
||||
@@ -212,7 +240,8 @@ async function submitDormitoryPoints() {
|
||||
if (res && res.success) {
|
||||
showToast(`操作成功: ${res.data.success_count} 人成功`);
|
||||
closeModal('dormitoryPointsModal');
|
||||
loadStudents();
|
||||
loadStudents();
|
||||
initPointsLimitHint();
|
||||
} else {
|
||||
showToast(res?.message || '操作失败', 'error');
|
||||
}
|
||||
@@ -222,6 +251,7 @@ loadStudents();
|
||||
|
||||
window.loadStudents = loadStudents;
|
||||
window.showSinglePointsModal = showSinglePointsModal;
|
||||
window.showExportMoralityModal = showExportMoralityModal;
|
||||
window.exportMoralityRecords = exportMoralityRecords;
|
||||
window.showDormitoryPointsModal = showDormitoryPointsModal;
|
||||
window.onDormitorySelected = onDormitorySelected;
|
||||
|
||||
Reference in new issue
Block a user