/**
* 班级操行分管理系统 - 管理端首页JS
*
* 开发者: Canglan
* 版权归属: Sea Network Technology Studio
*
* 版权所有 © Sea Network Technology Studio
*/
(function() {
'use strict';
const role = window.PAGE_CONFIG.role;
let totalStudents = 0;
async function loadDashboard() {
const studentsRes = await apiGet('/api/admin/students');
if (studentsRes && studentsRes.success) {
document.getElementById('dashboardStats').innerHTML = `
学生总数
${studentsRes.data.total || 0}
`;
}
let quickActions = '';
if (role === '班主任' || role === '班长' || role === '劳动委员' || role === '志愿委员') {
quickActions += '';
}
if (role === '班主任') {
quickActions += '';
quickActions += '';
}
document.getElementById('quickActions').innerHTML = quickActions || '暂无快捷操作
';
const rankingRes = await apiGet('/api/student/ranking', { limit: 100 });
if (rankingRes && rankingRes.success) {
totalStudents = rankingRes.data.total_students || 0;
let html = '';
rankingRes.data.ranking.forEach((student, index) => {
const rank = index + 1;
html += `
| ${rank} |
${escapeHtml(student.student_no)} |
${escapeHtml(student.name)} |
${student.total_points} |
`;
});
if (rankingRes.data.ranking.length === 0) {
html = '| 暂无数据 |
';
}
document.getElementById('rankingList').innerHTML = html;
}
}
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.applyPercentileFilter = applyPercentileFilter;
window.resetPercentileFilter = resetPercentileFilter;
})();