v0.8.5测试
This commit is contained in:
@@ -36,7 +36,7 @@ include __DIR__ . '/../includes/header.php';
|
||||
<div class="action-buttons">
|
||||
<button class="btn btn-primary" onclick="showBatchPointsModal()">批量加减分</button>
|
||||
<?php if ($role === '班主任'): ?>
|
||||
<button class="btn btn-secondary" onclick="exportConductRecords()">导出记录</button>
|
||||
<button class="btn btn-secondary" onclick="exportMoralityRecords()">导出德育分记录</button>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
@@ -96,50 +96,62 @@ function showSinglePointsModal(studentId, studentName) {
|
||||
document.getElementById('batchPointsModal').style.display = 'flex';
|
||||
}
|
||||
|
||||
// 导出操行分记录
|
||||
async function exportConductRecords() {
|
||||
const startDate = prompt('请输入开始日期(格式:YYYY-MM-DD,留空则不限):', '');
|
||||
if (startDate === null) return;
|
||||
const endDate = prompt('请输入结束日期(格式:YYYY-MM-DD,留空则不限):', '');
|
||||
if (endDate === null) return;
|
||||
|
||||
showToast('正在导出...', 'info');
|
||||
// 导出德育分记录(格式:学号 姓名 分数 加分历史 减分记录)
|
||||
async function exportMoralityRecords() {
|
||||
showToast('正在导出德育分记录...', 'info');
|
||||
|
||||
try {
|
||||
const params = { page: 1, page_size: 1000 };
|
||||
if (startDate) params.start_date = startDate;
|
||||
if (endDate) params.end_date = endDate;
|
||||
|
||||
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');
|
||||
// 获取所有学生
|
||||
const studentsRes = await apiGet('/api/admin/students', { page_size: 1000 });
|
||||
if (!studentsRes || !studentsRes.success) {
|
||||
showToast('获取学生列表失败', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
const students = studentsRes.data.students;
|
||||
if (students.length === 0) {
|
||||
showToast('没有找到学生', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取每个学生的历史记录
|
||||
const studentRecords = [];
|
||||
for (const student of students) {
|
||||
const historyRes = await apiGet(`/api/student/conduct/${student.student_id}`, { limit: 1000 });
|
||||
if (historyRes && historyRes.success) {
|
||||
const records = historyRes.data.records || [];
|
||||
const positiveRecords = records.filter(r => r.points_change > 0).map(r => `${r.reason}(${r.points_change > 0 ? '+' : ''}${r.points_change})`);
|
||||
const negativeRecords = records.filter(r => r.points_change < 0).map(r => `${r.reason}(${r.points_change})`);
|
||||
|
||||
studentRecords.push({
|
||||
student_no: student.student_no,
|
||||
name: student.name,
|
||||
total_points: historyRes.data.total_points || 0,
|
||||
positive_history: positiveRecords.join(', '),
|
||||
negative_history: negativeRecords.join(', ')
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 构建CSV内容
|
||||
let csv = '\uFEFF'; // BOM for UTF-8
|
||||
csv += '学号,姓名,分数,加分历史,减分记录\n';
|
||||
studentRecords.forEach(s => {
|
||||
csv += `${s.student_no},${s.name},${s.total_points},"${(s.positive_history || '').replace(/"/g, '""')}","${(s.negative_history || '').replace(/"/g, '""')}"\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(`导出成功,共${studentRecords.length}名学生`);
|
||||
} catch (err) {
|
||||
showToast('导出失败:' + err.message, 'error');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user