130 lines
5.0 KiB
PHP
130 lines
5.0 KiB
PHP
<?php
|
|
/**
|
|
* 班级操行分管理系统 - 管理端首页
|
|
*
|
|
* 开发者: Canglan
|
|
* 联系方式: admin@sea-studio.top
|
|
* 版权归属: Sea Network Technology Studio
|
|
* 许可证: MIT License
|
|
*
|
|
* 版权所有 © Sea Network Technology Studio
|
|
*/
|
|
|
|
require_once __DIR__ . '/../config.php';
|
|
|
|
if (!isset($_SESSION['user_id']) || $_SESSION['user_type'] !== 'admin') {
|
|
header('Location: /index.php');
|
|
exit();
|
|
}
|
|
|
|
$page_title = '首页';
|
|
$role = $_SESSION['role'] ?? '';
|
|
include __DIR__ . '/../includes/header.php';
|
|
?>
|
|
|
|
<?php include __DIR__ . '/../includes/nav.php'; ?>
|
|
|
|
<div class="container">
|
|
<div class="stats-grid" id="dashboardStats"></div>
|
|
|
|
<div class="card">
|
|
<div class="card-title">快捷操作</div>
|
|
<div class="action-buttons" id="quickActions"></div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-title">操行分排行榜</div>
|
|
<div class="table-wrapper">
|
|
<div style="display: flex; align-items: center; margin-bottom: 12px; gap: 8px;">
|
|
<span style="font-size: 14px; color: #666;">显示前</span>
|
|
<input type="number" id="percentileFilter" style="width: 70px; padding: 4px 8px; border: 1px solid #ddd; border-radius: 4px;" min="1" max="100" value="100" placeholder="1-100">
|
|
<span style="font-size: 14px; color: #666;">% 的学生</span>
|
|
<button class="btn btn-sm" style="background: #667eea; color: white;" onclick="applyPercentileFilter()">筛选</button>
|
|
<button class="btn btn-sm" style="border: 1px solid #ccc; color: #666;" onclick="resetPercentileFilter()">显示全部</button>
|
|
</div>
|
|
<table class="table">
|
|
<thead>
|
|
<tr><th>排名</th><th>学号</th><th>姓名</th><th>操行分</th></tr>
|
|
</thead>
|
|
<tbody id="rankingList"></tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
var 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 ('<?php echo $role; ?>' === '班主任' || '<?php echo $role; ?>' === '班长' || '<?php echo $role; ?>' === '劳动委员' || '<?php echo $role; ?>' === '志愿委员') {
|
|
quickActions += '<button class="btn btn-primary" onclick="location.href=\'/admin/conduct.php\'">操行分管理</button>';
|
|
}
|
|
if ('<?php echo $role; ?>' === '班主任') {
|
|
quickActions += '<button class="btn btn-success" 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;
|
|
}
|
|
}
|
|
|
|
document.getElementById('percentileFilter').addEventListener('keypress', function(e) {
|
|
if (e.key === 'Enter') applyPercentileFilter();
|
|
});
|
|
|
|
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 = '';
|
|
});
|
|
}
|
|
|
|
loadDashboard();
|
|
</script>
|
|
<script src="/assets/js/admin.js"></script>
|
|
|
|
<?php include __DIR__ . '/../includes/footer.php'; ?>
|