/**
* 多班级版班级管理系统 - 排行榜JS
*
* 开发者: Canglan
* 版权归属: Sea Network Technology Studio
*
* 版权所有 © Sea Network Technology Studio
*/
(function() {
'use strict';
let currentType = 'conduct';
async function loadRankings(type) {
const res = await apiGet('/api/admin/rankings', { type: type, limit: 50 });
if (res && res.success && res.data) {
const rankings = res.data.ranking || [];
let html = '';
if (rankings.length === 0) {
html = '
| 暂无排行数据 |
';
} else {
rankings.forEach(function(item, index) {
let rankClass = '';
if (index === 0) rankClass = 'rank-gold';
else if (index === 1) rankClass = 'rank-silver';
else if (index === 2) rankClass = 'rank-bronze';
let pointsText = Number(item.points !== undefined ? item.points : (item.total_points || 0));
if (pointsText > 0) {
pointsText = '+' + pointsText;
}
html += '' +
'| ' + (index + 1) + ' | ' +
'' + escapeHtml(item.student_no || '-') + ' | ' +
'' + escapeHtml(item.name || '-') + ' | ' +
'' + pointsText + ' | ' +
'
';
});
}
document.getElementById('rankingList').innerHTML = html;
} else {
document.getElementById('rankingList').innerHTML = '| 加载失败 |
';
}
}
window.switchTab = function(type, btn) {
currentType = type;
document.querySelectorAll('.tab-btn').forEach(function(b) { b.classList.remove('active'); });
btn.classList.add('active');
loadRankings(type);
};
document.addEventListener('DOMContentLoaded', function() {
loadRankings(currentType);
});
})();