v0.8.5测试

This commit is contained in:
2026-04-16 10:36:34 +08:00
parent 4cbf294cd9
commit 112dc94f7c
12 changed files with 297 additions and 90 deletions

View File

@@ -42,6 +42,9 @@ include __DIR__ . '/../includes/header.php';
</select>
</div>
<button class="btn btn-primary" onclick="loadHistory(1)">查询</button>
<?php if ($role === '班主任'): ?>
<button class="btn btn-secondary" onclick="exportHistoryRecords()">导出历史记录</button>
<?php endif; ?>
</div>
<div class="table-wrapper">
@@ -142,6 +145,55 @@ function renderHistoryPagination() {
container.innerHTML = html;
}
// 导出历史记录
async function exportHistoryRecords() {
const startDate = document.getElementById('historyStartDate').value;
const endDate = document.getElementById('historyEndDate').value;
const studentId = document.getElementById('historyStudentId').value;
showToast('正在导出历史记录...', 'info');
try {
const params = { page: 1, page_size: 1000 };
if (startDate) params.start_date = startDate;
if (endDate) params.end_date = endDate;
if (studentId) params.student_id = studentId;
const res = await apiGet('/api/admin/conduct/history', params);
if (res && res.success && res.data.records) {
const records = res.data.records;
if (records.length === 0) {
showToast('没有找到记录', 'warning');
return;
}
// 构建CSV内容
let csv = '\uFEFF'; // BOM for UTF-8
csv += '时间,学号,姓名,分数变动,原因,操作人\n';
records.forEach(r => {
csv += `${r.created_at || ''},${r.student_no || ''},${r.student_name || ''},${r.points_change > 0 ? '+' : ''}${r.points_change},${(r.reason || '').replace(/,/g, ';')},${r.recorder_name || ''}\n`;
});
// 下载文件
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = `历史记录_${new Date().toISOString().slice(0,10)}.csv`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(url);
showToast(`导出成功,共${records.length}条记录`);
} else {
showToast('导出失败:' + (res?.message || '未知错误'), 'error');
}
} catch (err) {
showToast('导出失败:' + err.message, 'error');
}
}
loadStudentsForSelect();
loadHistory();
</script>