91 lines
3.3 KiB
JavaScript
91 lines
3.3 KiB
JavaScript
/**
|
|
* 班级操行分管理系统 - 管理端首页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 = `
|
|
<div class="stat-card">
|
|
<div class="stat-label">学生总数</div>
|
|
<div class="stat-value">${studentsRes.data.total || 0}</div>
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
let quickActions = '';
|
|
if (role === '班主任' || role === '班长' || role === '劳动委员' || role === '志愿委员') {
|
|
quickActions += '<button class="btn btn-primary" onclick="location.href=\'/admin/conduct.php\'">操行分管理</button>';
|
|
}
|
|
if (role === '班主任') {
|
|
quickActions += '<button class="btn btn-outline" onclick="location.href=\'/admin/students.php\'">导入学生</button>';
|
|
quickActions += '<button class="btn btn-secondary" onclick="location.href=\'/admin/conduct.php\'">导出德育分记录</button>';
|
|
}
|
|
document.getElementById('quickActions').innerHTML = quickActions || '<p>暂无快捷操作</p>';
|
|
|
|
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 += `<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) {
|
|
html = '<tr><td colspan="4" style="text-align:center;">暂无数据</td></tr>';
|
|
}
|
|
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;
|
|
|
|
})();
|