feat(conduct): add restore revoked record functionality and update history view

This commit is contained in:
2026-04-23 11:19:35 +08:00
parent 03aaaa53a9
commit bf0314f098
5 changed files with 115 additions and 13 deletions

View File

@@ -53,7 +53,6 @@ include __DIR__ . '/../includes/header.php';
<tr>
<th>时间</th>
<th>学生</th>
<th>人数</th>
<th>分数变动</th>
<th>原因</th>
<th>操作人</th>
@@ -92,8 +91,7 @@ async function loadHistory(page = 1) {
const params = {
page, page_size: 20,
start_date: startDate,
end_date: endDate,
grouped: true
end_date: endDate
};
if (studentId) params.student_id = studentId;
@@ -103,21 +101,31 @@ async function loadHistory(page = 1) {
let html = '';
res.data.records.forEach(record => {
const pointsClass = record.points_change > 0 ? 'plus' : 'minus';
html += `<tr>
const revokedStyle = record.is_revoked == 1 ? ' style="opacity:0.5; text-decoration:line-through;"' : '';
html += `<tr${revokedStyle}>
<td>${formatDateTime(record.created_at)}</td>
<td>${escapeHtml(record.student_names)}</td>
<td>${record.student_count || 1}</td>
<td>${escapeHtml(record.student_name)}</td>
<td class="${pointsClass}">${record.points_change > 0 ? '+' : ''}${record.points_change}</td>
<td>${escapeHtml(record.reason)}</td>
<td>${escapeHtml(record.recorder_name)}</td>`;
<?php if ($role === '班主任' || $role === '班长'): ?>
html += `<td>-</td>`;
<?php if ($role === '班主任'): ?>
if (record.is_revoked == 1) {
html += `<td><span class="text-muted" style="margin-right:4px;">已撤销</span><button class="btn btn-sm btn-secondary" onclick="restoreRecord(${record.record_id})">反撤销</button></td>`;
} else {
html += `<td><button class="btn btn-sm btn-danger" onclick="revokeRecord(${record.record_id})">撤销</button></td>`;
}
<?php elseif ($role === '班长'): ?>
if (record.is_revoked == 1) {
html += `<td><span class="text-muted">已撤销</span></td>`;
} else {
html += `<td><button class="btn btn-sm btn-danger" onclick="revokeRecord(${record.record_id})">撤销</button></td>`;
}
<?php endif; ?>
html += `</tr>`;
});
if (res.data.records.length === 0) {
const colSpan = <?php echo ($role === '班主任' || $role === '班长') ? '7' : '6'; ?>;
const colSpan = <?php echo ($role === '班主任' || $role === '班长') ? '6' : '5'; ?>;
html = `<tr><td colspan="${colSpan}" style="text-align:center;">暂无记录</td></tr>`;
}

View File

@@ -251,7 +251,7 @@ async function submitAddSubject() {
// 撤销扣分记录
async function revokeRecord(recordId) {
if (!confirm('确定要撤销这条扣分记录吗?')) return;
if (!confirm('确定要撤销这条记录吗?撤销后学生分数将恢复。')) return;
const res = await apiPost('/api/admin/conduct/revoke', { record_id: recordId });
if (res && res.success) {
@@ -262,6 +262,19 @@ async function revokeRecord(recordId) {
}
}
// 反撤销(恢复)记录
async function restoreRecord(recordId) {
if (!confirm('确定要反撤销这条记录吗?分数变动将重新生效。')) return;
const res = await apiPost('/api/admin/conduct/restore', { record_id: recordId });
if (res && res.success) {
showToast('反撤销成功');
loadHistory(currentHistoryPage);
} else {
showToast(res?.message || '反撤销失败', 'error');
}
}
// 关闭模态框
function closeModal(modalId) {
const modal = document.getElementById(modalId);