1. 月度分排行:管理端首页支持总分/月度分切换与月份选择,新增排行榜导出CSV 2. 数据报表:新增考勤/作业统计页(日期范围、汇总与每人明细、CSV导出) 3. 操作日志:新增查看页(操作类型/操作人/日期筛选,分页) 4. 系统设置:密码策略可配置(长度/字符种类),全站改密与重置统一校验、前端提示同步;策略通过公开配置下发 5. 学期归档对比:查看归档时展示与上一学期的分数变化与名次升降 6. 历史记录导出支持按学生分表(每人一段,便于发家长) 7. 移动端适配:导航横向滚动、表格触控滚动、字号与弹窗优化 8. 版本升级至4.4(无数据库结构变更)
216 lines
7.9 KiB
JavaScript
216 lines
7.9 KiB
JavaScript
/**
|
|
* 班级操行分管理系统 - 管理端首页JS
|
|
*
|
|
* 开发者: Canglan
|
|
* 版权归属: Sea Network Technology Studio
|
|
*
|
|
* 版权所有 © Sea Network Technology Studio
|
|
*/
|
|
|
|
(function() {
|
|
'use strict';
|
|
|
|
let totalStudents = 0;
|
|
|
|
async function loadDashboard() {
|
|
// 并行加载学生数据和学期信息
|
|
const [studentsRes, semesterRes] = await Promise.all([
|
|
apiGet('/api/admin/students'),
|
|
apiGet('/api/semester/active')
|
|
]);
|
|
|
|
let statsHtml = '';
|
|
if (studentsRes && studentsRes.success) {
|
|
statsHtml += `
|
|
<div class="stat-card">
|
|
<div class="stat-label">学生总数</div>
|
|
<div class="stat-value">${studentsRes.data.total || 0}</div>
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
// 显示学期信息和当前周数
|
|
if (semesterRes && semesterRes.success && semesterRes.data) {
|
|
const sem = semesterRes.data;
|
|
const weekNum = sem.current_week;
|
|
let semesterInfo = escapeHtml(sem.semester_name);
|
|
if (weekNum && weekNum > 0) {
|
|
semesterInfo += ` · 第${weekNum}周`;
|
|
}
|
|
statsHtml += `
|
|
<div class="stat-card">
|
|
<div class="stat-label">当前学期</div>
|
|
<div class="stat-value" style="font-size:20px;">${semesterInfo}</div>
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
document.getElementById('dashboardStats').innerHTML = statsHtml;
|
|
|
|
let quickActions = '';
|
|
if (hasPermission('manage_conduct')) {
|
|
quickActions += '<button class="btn btn-primary" onclick="location.href=\'/admin/conduct.php\'">操行分管理</button>';
|
|
}
|
|
if (hasPermission('manage_homework')) {
|
|
quickActions += '<button class="btn btn-primary" onclick="location.href=\'/admin/homework.php\'">作业扣分</button>';
|
|
}
|
|
if (hasPermission('manage_attendance')) {
|
|
quickActions += '<button class="btn btn-primary" onclick="location.href=\'/admin/attendance.php\'">考勤管理</button>';
|
|
}
|
|
if (hasPermission('manage_students')) {
|
|
quickActions += '<button class="btn btn-outline" onclick="location.href=\'/admin/students.php\'">学生管理</button>';
|
|
}
|
|
if (hasPermission('manage_semesters')) {
|
|
quickActions += '<button class="btn btn-outline" onclick="location.href=\'/admin/semesters.php\'">学期管理</button>';
|
|
}
|
|
if (hasPermission('export_data')) {
|
|
quickActions += '<button class="btn btn-secondary" onclick="location.href=\'/admin/conduct.php\'">导出德育分记录</button>';
|
|
}
|
|
if (hasPermission('export_students')) {
|
|
quickActions += '<button class="btn btn-secondary" onclick="location.href=\'/admin/students.php\'">导出学生名单</button>';
|
|
}
|
|
document.getElementById('quickActions').innerHTML = quickActions || '<p>暂无快捷操作</p>';
|
|
|
|
await loadRanking();
|
|
}
|
|
|
|
async function loadRanking() {
|
|
const type = document.getElementById('rankingType').value;
|
|
const params = { limit: 100 };
|
|
if (type === 'monthly') {
|
|
const monthInput = document.getElementById('rankingMonth');
|
|
if (monthInput.value) params.month = monthInput.value;
|
|
}
|
|
|
|
const rankingRes = await apiGet('/api/student/ranking', params);
|
|
const head = document.getElementById('rankingHead');
|
|
if (type === 'monthly') {
|
|
head.innerHTML = '<th>排名</th><th>学号</th><th>姓名</th><th>加分</th><th>减分</th><th>月度分</th>';
|
|
} else {
|
|
head.innerHTML = '<th>排名</th><th>学号</th><th>姓名</th><th>操行分</th>';
|
|
}
|
|
if (!rankingRes || !rankingRes.success) return;
|
|
|
|
totalStudents = rankingRes.data.total_students || 0;
|
|
let html = '';
|
|
rankingRes.data.ranking.forEach((student, index) => {
|
|
const rank = index + 1;
|
|
if (type === 'monthly') {
|
|
const score = student.month_score || 0;
|
|
const cls = score > 0 ? 'plus' : (score < 0 ? 'minus' : '');
|
|
html += `<tr>
|
|
<td>${rank}</td>
|
|
<td>${escapeHtml(student.student_no)}</td>
|
|
<td>${escapeHtml(student.name)}</td>
|
|
<td class="plus">+${student.bonus || 0}</td>
|
|
<td class="minus">${student.deduction || 0}</td>
|
|
<td class="${cls}">${score > 0 ? '+' : ''}${score}</td>
|
|
</tr>`;
|
|
} else {
|
|
html += `<tr>
|
|
<td>${rank}</td>
|
|
<td>${escapeHtml(student.student_no)}</td>
|
|
<td>${escapeHtml(student.name)}</td>
|
|
<td>${student.total_points}</td>
|
|
</tr>`;
|
|
}
|
|
});
|
|
if (rankingRes.data.ranking.length === 0) {
|
|
const cols = type === 'monthly' ? 6 : 4;
|
|
html = `<tr><td colspan="${cols}" style="text-align:center;">暂无数据</td></tr>`;
|
|
}
|
|
document.getElementById('rankingList').innerHTML = html;
|
|
}
|
|
|
|
function onRankingTypeChange() {
|
|
const isMonthly = document.getElementById('rankingType').value === 'monthly';
|
|
const monthInput = document.getElementById('rankingMonth');
|
|
monthInput.style.display = isMonthly ? '' : 'none';
|
|
if (isMonthly && !monthInput.value) {
|
|
const now = new Date();
|
|
monthInput.value = now.getFullYear() + '-' + String(now.getMonth() + 1).padStart(2, '0');
|
|
}
|
|
resetPercentileFilter();
|
|
loadRanking();
|
|
}
|
|
|
|
async function exportRanking() {
|
|
const type = document.getElementById('rankingType').value;
|
|
const params = { limit: 1000 };
|
|
let label = '总分排行';
|
|
if (type === 'monthly') {
|
|
const month = document.getElementById('rankingMonth').value;
|
|
if (!month) {
|
|
showToast('请先选择月份', 'warning');
|
|
return;
|
|
}
|
|
params.month = month;
|
|
label = '月度排行_' + month;
|
|
}
|
|
|
|
const res = await apiGet('/api/student/ranking', params);
|
|
if (!res || !res.success) {
|
|
showToast('导出失败', 'error');
|
|
return;
|
|
}
|
|
const ranking = res.data.ranking || [];
|
|
if (ranking.length === 0) {
|
|
showToast('没有可导出的数据', 'warning');
|
|
return;
|
|
}
|
|
|
|
let csv = type === 'monthly'
|
|
? '排名,学号,姓名,加分,减分,月度分\n'
|
|
: '排名,学号,姓名,操行分\n';
|
|
ranking.forEach(function(s, index) {
|
|
if (type === 'monthly') {
|
|
csv += [index + 1, s.student_no, s.name, s.bonus || 0, s.deduction || 0, s.month_score || 0]
|
|
.map(csvEscape).join(',') + '\n';
|
|
} else {
|
|
csv += [index + 1, s.student_no, s.name, s.total_points]
|
|
.map(csvEscape).join(',') + '\n';
|
|
}
|
|
});
|
|
|
|
downloadCsv('排行榜_' + label + '_' + new Date().toISOString().slice(0,10) + '.csv', csv);
|
|
showToast('导出成功,共' + ranking.length + '人');
|
|
}
|
|
|
|
function applyPercentileFilter() {
|
|
const input = document.getElementById('percentileFilter');
|
|
const percentile = parseInt(input.value);
|
|
if (isNaN(percentile) || percentile < 1 || percentile > 100) {
|
|
showToast('请输入 1-100 之间的整数', 'error');
|
|
return;
|
|
}
|
|
const rows = document.getElementById('rankingList').querySelectorAll('tr');
|
|
if (rows.length === 0) return;
|
|
const showCount = Math.max(1, Math.floor(totalStudents * (percentile / 100)));
|
|
rows.forEach(function(row, index) {
|
|
row.style.display = index < showCount ? '' : 'none';
|
|
});
|
|
}
|
|
|
|
function resetPercentileFilter() {
|
|
document.getElementById('percentileFilter').value = 100;
|
|
const rows = document.getElementById('rankingList').querySelectorAll('tr');
|
|
rows.forEach(function(row) {
|
|
row.style.display = '';
|
|
});
|
|
}
|
|
|
|
document.getElementById('percentileFilter').addEventListener('keypress', function(e) {
|
|
if (e.key === 'Enter') applyPercentileFilter();
|
|
});
|
|
|
|
loadDashboard();
|
|
|
|
window.loadDashboard = loadDashboard;
|
|
window.loadRanking = loadRanking;
|
|
window.onRankingTypeChange = onRankingTypeChange;
|
|
window.exportRanking = exportRanking;
|
|
window.applyPercentileFilter = applyPercentileFilter;
|
|
window.resetPercentileFilter = resetPercentileFilter;
|
|
|
|
})();
|