1. 权限组:去掉锁定/预置限制,所有组可编辑/删除/分配;管理员新增/编辑可选任意组;管理员列表不再显示锁定徽标 2. 个人查询:月度分独立计算(当月净得分,与基础分无关),总分=基础分+加分-减分 3. 绑定邮箱:发送验证码与确认绑定不再需要密码(解绑仍需密码) 4. 权限组编辑UI:权限项按 学生/操行分/教务/系统管理 分区,支持全选/清空,上限两行布局,弹窗加宽 5. 样式统一:颜色变量化(硬编码色值清零)、check-grid/check-item 统一复选框网格、cell-wrap、subject-status 全局化、success-msg 6. 旧库升级期兼容保留(登录/权限降级、待升级提示) 7. 文档同步更新
261 lines
11 KiB
JavaScript
261 lines
11 KiB
JavaScript
/**
|
||
* 班级操行分管理系统 - 操行分管理页JS
|
||
*
|
||
* 开发者: Canglan
|
||
* 版权归属: Sea Network Technology Studio
|
||
*
|
||
* 版权所有 © Sea Network Technology Studio
|
||
*/
|
||
|
||
(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="${detailUrl}" class="link">${escapeHtml(student.name)}</a></td>
|
||
<td>${student.total_points}</td>
|
||
<td>${pointsButton}</td>
|
||
</tr>`;
|
||
});
|
||
if (res.data.students.length === 0) {
|
||
html = '<tr><td colspan="5" style="text-align:center;">暂无学生数据</td></tr>';
|
||
}
|
||
document.getElementById('studentList').innerHTML = html;
|
||
}
|
||
}
|
||
|
||
function showSinglePointsModal(studentId, studentName) {
|
||
window.selectedStudentIds = [studentId];
|
||
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 {
|
||
const studentsRes = await apiGet('/api/admin/students', { page_size: 1000 });
|
||
if (!studentsRes || !studentsRes.success) {
|
||
showToast('获取学生列表失败', 'error');
|
||
return;
|
||
}
|
||
|
||
const students = studentsRes.data.students;
|
||
if (students.length === 0) {
|
||
showToast('没有找到学生', 'warning');
|
||
return;
|
||
}
|
||
|
||
const params = { is_revoked: 0 };
|
||
if (semesterId) params.semester_id = semesterId;
|
||
const allRecords = await apiGetAll('/api/admin/conduct/history', params);
|
||
|
||
const basePoints = parseInt(window.STUDENT_INITIAL_POINTS || 60, 10) || 60;
|
||
|
||
// 按 学生 + 学期 分组
|
||
const groups = {};
|
||
allRecords.forEach(record => {
|
||
const label = semesterId ? semesterName : (record.semester_name || '未关联学期');
|
||
const key = record.student_id + '|' + label;
|
||
if (!groups[key]) groups[key] = [];
|
||
groups[key].push(record);
|
||
});
|
||
|
||
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));
|
||
});
|
||
}
|
||
}
|
||
});
|
||
|
||
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';
|
||
});
|
||
|
||
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);
|
||
}
|
||
}
|
||
// 宿舍集体加分相关
|
||
var dormitoryStudentIds = [];
|
||
|
||
async function showDormitoryPointsModal() {
|
||
dormitoryStudentIds = [];
|
||
document.getElementById('dormitorySelect').innerHTML = '<option value="">-- 请选择宿舍 --</option>';
|
||
document.getElementById('dormitoryStudentsGroup').style.display = 'none';
|
||
document.getElementById('dormitoryStudentsList').innerHTML = '';
|
||
document.getElementById('dormitoryPointsChange').value = '';
|
||
document.getElementById('dormitoryPointsReason').value = '';
|
||
|
||
// 加载宿舍列表
|
||
const res = await apiGet('/api/admin/students/dormitories');
|
||
if (res && res.success && res.data.dormitories) {
|
||
const select = document.getElementById('dormitorySelect');
|
||
res.data.dormitories.forEach(d => {
|
||
const option = document.createElement('option');
|
||
option.value = d;
|
||
option.textContent = d;
|
||
select.appendChild(option);
|
||
});
|
||
}
|
||
|
||
document.getElementById('dormitoryPointsModal').style.display = 'flex';
|
||
}
|
||
|
||
async function onDormitorySelected() {
|
||
const dormitory = document.getElementById('dormitorySelect').value;
|
||
const studentsGroup = document.getElementById('dormitoryStudentsGroup');
|
||
const studentsList = document.getElementById('dormitoryStudentsList');
|
||
const studentsCount = document.getElementById('dormitoryStudentsCount');
|
||
|
||
dormitoryStudentIds = [];
|
||
studentsList.innerHTML = '';
|
||
|
||
if (!dormitory) {
|
||
studentsGroup.style.display = 'none';
|
||
return;
|
||
}
|
||
|
||
// 加载该宿舍的学生
|
||
const res = await apiGet('/api/admin/students', { dormitory_number: dormitory, page_size: 1000 });
|
||
if (res && res.success && res.data.students) {
|
||
const students = res.data.students;
|
||
if (students.length === 0) {
|
||
studentsList.innerHTML = '<p style="color: var(--color-text-secondary);">该宿舍暂无学生</p>';
|
||
studentsCount.textContent = '';
|
||
} else {
|
||
students.forEach(s => {
|
||
dormitoryStudentIds.push(s.student_id);
|
||
const div = document.createElement('div');
|
||
div.style.cssText = 'display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid var(--color-border);';
|
||
div.innerHTML = `<span>${escapeHtml(s.name)}</span><span style="color: var(--color-text-secondary);">${escapeHtml(s.student_no)}</span>`;
|
||
studentsList.appendChild(div);
|
||
});
|
||
studentsCount.textContent = `共 ${students.length} 人`;
|
||
}
|
||
studentsGroup.style.display = 'block';
|
||
} else {
|
||
studentsList.innerHTML = '<p style="color: var(--color-text-secondary);">加载失败</p>';
|
||
studentsGroup.style.display = 'block';
|
||
}
|
||
}
|
||
|
||
async function submitDormitoryPoints() {
|
||
if (dormitoryStudentIds.length === 0) {
|
||
showToast('该宿舍没有学生', 'warning');
|
||
return;
|
||
}
|
||
|
||
const pointsChange = parseInt(document.getElementById('dormitoryPointsChange').value);
|
||
const reason = document.getElementById('dormitoryPointsReason').value;
|
||
|
||
if (isNaN(pointsChange) || pointsChange === 0) {
|
||
showToast('分值不能为0', 'error');
|
||
return;
|
||
}
|
||
|
||
if (!reason.trim()) {
|
||
showToast('请填写原因', 'error');
|
||
return;
|
||
}
|
||
|
||
const data = {
|
||
student_ids: dormitoryStudentIds,
|
||
points_change: pointsChange,
|
||
reason: reason
|
||
};
|
||
|
||
const res = await apiPost('/api/admin/conduct/add', data);
|
||
|
||
if (res && res.success) {
|
||
showToast(`操作成功: ${res.data.success_count} 人成功`);
|
||
closeModal('dormitoryPointsModal');
|
||
loadStudents();
|
||
initPointsLimitHint();
|
||
} else {
|
||
showToast(res?.message || '操作失败', 'error');
|
||
}
|
||
}
|
||
|
||
loadStudents();
|
||
|
||
window.loadStudents = loadStudents;
|
||
window.showSinglePointsModal = showSinglePointsModal;
|
||
window.showExportMoralityModal = showExportMoralityModal;
|
||
window.exportMoralityRecords = exportMoralityRecords;
|
||
window.showDormitoryPointsModal = showDormitoryPointsModal;
|
||
window.onDormitorySelected = onDormitorySelected;
|
||
window.submitDormitoryPoints = submitDormitoryPoints;
|
||
|
||
})();
|