feat: add mine and class filters to statistics page
This commit is contained in:
@@ -6,6 +6,20 @@
|
||||
<div class="container-fluid py-4">
|
||||
<h2 class="mb-4"><i class="bi bi-bar-chart"></i> 数据统计</h2>
|
||||
|
||||
<!-- 筛选工具栏 -->
|
||||
<div class="card mb-4">
|
||||
<div class="card-body">
|
||||
<div class="d-flex flex-wrap gap-3 align-items-center">
|
||||
<button class="btn btn-primary btn-sm" id="mineFilterBtn" onclick="toggleMineFilter()">
|
||||
<i class="bi bi-person"></i> 我的
|
||||
</button>
|
||||
<select class="form-select form-select-sm" style="width:auto; min-width:120px;" id="classFilter" onchange="loadStatistics()">
|
||||
<option value="">全部班级</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 顶部统计卡片 -->
|
||||
<div class="row mb-4">
|
||||
<div class="col-md-4">
|
||||
@@ -131,12 +145,43 @@
|
||||
{% block extra_js %}
|
||||
<script>
|
||||
let severityChart, levelChart, classStudentChart, classProblemChart, problemNameChart;
|
||||
let mineFilterActive = false;
|
||||
|
||||
function toggleMineFilter() {
|
||||
mineFilterActive = !mineFilterActive;
|
||||
const btn = document.getElementById('mineFilterBtn');
|
||||
if (mineFilterActive) {
|
||||
btn.classList.add('active');
|
||||
} else {
|
||||
btn.classList.remove('active');
|
||||
}
|
||||
loadStatistics();
|
||||
}
|
||||
|
||||
async function loadStatistics() {
|
||||
try {
|
||||
const resp = await fetch('/api/statistics/students');
|
||||
const params = new URLSearchParams();
|
||||
if (mineFilterActive) params.set('mine', 'true');
|
||||
const classId = document.getElementById('classFilter').value;
|
||||
if (classId) params.set('class_id', classId);
|
||||
|
||||
const resp = await fetch('/api/statistics/students?' + params.toString());
|
||||
const data = await resp.json();
|
||||
|
||||
// 填充班级筛选器
|
||||
const classSelect = document.getElementById('classFilter');
|
||||
if (classSelect.options.length <= 1) {
|
||||
for (const c of data.classes || []) {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = c.id;
|
||||
opt.textContent = c.name;
|
||||
classSelect.appendChild(opt);
|
||||
}
|
||||
}
|
||||
if (classId) {
|
||||
classSelect.value = classId;
|
||||
}
|
||||
|
||||
// 更新顶部卡片
|
||||
document.getElementById('totalStudents').textContent = data.total_students || 0;
|
||||
document.getElementById('totalProblems').textContent = data.total_problems || 0;
|
||||
|
||||
Reference in New Issue
Block a user