feat: 增加学生信息管理功能,优化操行分历史记录展示并更新使用文档
This commit is contained in:
@@ -69,7 +69,7 @@ async function loadStudents() {
|
||||
html += `<tr>
|
||||
<td><input type="checkbox" class="student-checkbox" data-id="${student.student_id}"></td>
|
||||
<td>${escapeHtml(student.student_no)}</td>
|
||||
<td>${escapeHtml(student.name)}</td>
|
||||
<td><a href="/admin/history.php?student_id=${student.student_id}" style="color: #3498db; text-decoration: none;">${escapeHtml(student.name)}</a></td>
|
||||
<td>${student.total_points}</td>
|
||||
<td><button class="btn btn-sm btn-primary" onclick="showSinglePointsModal(${student.student_id}, '${escapeHtml(student.name)}')">加减分</button></td>
|
||||
</tr>`;
|
||||
|
||||
@@ -53,6 +53,7 @@ include __DIR__ . '/../includes/header.php';
|
||||
<tr>
|
||||
<th>时间</th>
|
||||
<th>学生</th>
|
||||
<th>人数</th>
|
||||
<th>分数变动</th>
|
||||
<th>原因</th>
|
||||
<th>操作人</th>
|
||||
@@ -82,7 +83,6 @@ async function loadStudentsForSelect() {
|
||||
document.getElementById('historyStudentId').innerHTML = html;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadHistory(page = 1) {
|
||||
currentHistoryPage = page;
|
||||
const startDate = document.getElementById('historyStartDate').value;
|
||||
@@ -92,7 +92,8 @@ async function loadHistory(page = 1) {
|
||||
const params = {
|
||||
page, page_size: 20,
|
||||
start_date: startDate,
|
||||
end_date: endDate
|
||||
end_date: endDate,
|
||||
grouped: true
|
||||
};
|
||||
if (studentId) params.student_id = studentId;
|
||||
|
||||
@@ -104,18 +105,19 @@ async function loadHistory(page = 1) {
|
||||
const pointsClass = record.points_change > 0 ? 'plus' : 'minus';
|
||||
html += `<tr>
|
||||
<td>${formatDateTime(record.created_at)}</td>
|
||||
<td>${escapeHtml(record.student_name)}</td>
|
||||
<td>${escapeHtml(record.student_names)}</td>
|
||||
<td>${record.student_count || 1}</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><button class="btn btn-sm btn-danger" onclick="revokeRecord(${record.record_id})">撤销</button></td>`;
|
||||
html += `<td>-</td>`;
|
||||
<?php endif; ?>
|
||||
html += `</tr>`;
|
||||
});
|
||||
|
||||
if (res.data.records.length === 0) {
|
||||
const colSpan = <?php echo ($role === '班主任' || $role === '班长') ? '6' : '5'; ?>;
|
||||
const colSpan = <?php echo ($role === '班主任' || $role === '班长') ? '7' : '6'; ?>;
|
||||
html = `<tr><td colspan="${colSpan}" style="text-align:center;">暂无记录</td></tr>`;
|
||||
}
|
||||
|
||||
@@ -125,6 +127,7 @@ async function loadHistory(page = 1) {
|
||||
renderHistoryPagination();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function renderHistoryPagination() {
|
||||
const container = document.getElementById('historyPagination');
|
||||
@@ -194,8 +197,16 @@ async function exportHistoryRecords() {
|
||||
}
|
||||
}
|
||||
|
||||
loadStudentsForSelect();
|
||||
loadHistory();
|
||||
loadStudentsForSelect().then(() => {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const preStudentId = urlParams.get('student_id');
|
||||
if (preStudentId) {
|
||||
document.getElementById('historyStudentId').value = preStudentId;
|
||||
loadHistory();
|
||||
} else {
|
||||
loadHistory();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<script src="/assets/js/admin.js"></script>
|
||||
|
||||
|
||||
@@ -65,6 +65,14 @@ include __DIR__ . '/../includes/header.php';
|
||||
<label>已选学生</label>
|
||||
<div id="selectedStudentsCount" class="selected-info">未选择学生</div>
|
||||
</div>
|
||||
<?php if ($role === '学习委员'): ?>
|
||||
<div class="form-group">
|
||||
<label>科目</label>
|
||||
<select id="hwSubjectSelect">
|
||||
<option value="">不选择科目</option>
|
||||
</select>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="form-group">
|
||||
<label>扣分类型</label>
|
||||
<div class="deduction-types">
|
||||
@@ -92,6 +100,7 @@ include __DIR__ . '/../includes/header.php';
|
||||
|
||||
<script>
|
||||
var selectedStudentIds = [];
|
||||
const hwRole = '<?php echo $role; ?>';
|
||||
|
||||
// 初始化扣分配置
|
||||
const hwMaxPoints = window.HOMEWORK_MAX_POINTS || 3;
|
||||
@@ -107,6 +116,21 @@ document.querySelectorAll('.hw-max').forEach(el => el.textContent = hwMaxPoints)
|
||||
document.getElementById('pointsChange').setAttribute('min', -hwMaxPoints);
|
||||
document.getElementById('pointsChange').setAttribute('max', hwMaxPoints);
|
||||
|
||||
// 加载科目列表(学习委员)
|
||||
async function loadSubjectsForHomework() {
|
||||
if (hwRole !== '学习委员') return;
|
||||
const subjectSelect = document.getElementById('hwSubjectSelect');
|
||||
if (!subjectSelect) return;
|
||||
const res = await apiGet('/api/subject/list');
|
||||
if (res && res.success && res.data && res.data.subjects) {
|
||||
let html = '<option value="">不选择科目</option>';
|
||||
res.data.subjects.forEach(s => {
|
||||
html += `<option value="${escapeHtml(s.subject_name)}">${escapeHtml(s.subject_name)}</option>`;
|
||||
});
|
||||
subjectSelect.innerHTML = html;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadStudents() {
|
||||
const res = await apiGet('/api/admin/students', {page_size: 1000});
|
||||
if (res && res.success) {
|
||||
@@ -169,10 +193,22 @@ function handleSubmitPoints() {
|
||||
showToast(`每次加减分不超过${hwMaxPoints}分`, 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
// 学习委员附加科目前缀
|
||||
if (hwRole === '学习委员') {
|
||||
const subjectSelect = document.getElementById('hwSubjectSelect');
|
||||
const subjectName = subjectSelect ? subjectSelect.value : '';
|
||||
const reasonEl = document.getElementById('pointsReason');
|
||||
if (subjectName && !reasonEl.value.startsWith('[')) {
|
||||
reasonEl.value = `[${subjectName}] ${reasonEl.value}`;
|
||||
}
|
||||
}
|
||||
|
||||
submitBatchPoints();
|
||||
}
|
||||
|
||||
loadStudents();
|
||||
loadSubjectsForHomework();
|
||||
</script>
|
||||
<script src="/assets/js/admin.js"></script>
|
||||
|
||||
|
||||
@@ -110,6 +110,57 @@ include __DIR__ . '/../includes/header.php';
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 编辑学生模态框 -->
|
||||
<div id="editStudentModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h3>编辑学生信息</h3>
|
||||
<button class="modal-close" onclick="closeModal('editStudentModal')">×</button>
|
||||
</div>
|
||||
<form onsubmit="event.preventDefault(); submitEditStudent()">
|
||||
<input type="hidden" id="editStudentId">
|
||||
<div class="form-group">
|
||||
<label>学号</label>
|
||||
<input type="text" id="editStudentNo" disabled>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>姓名</label>
|
||||
<input type="text" id="editStudentName" required maxlength="50">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>家长手机号</label>
|
||||
<input type="text" id="editStudentPhone" maxlength="20">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" class="btn btn-primary">保存修改</button>
|
||||
<button type="button" class="btn" onclick="closeModal('editStudentModal')">取消</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 重置学生密码模态框 -->
|
||||
<div id="resetStudentPasswordModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h3>重置学生密码</h3>
|
||||
<button class="modal-close" onclick="closeModal('resetStudentPasswordModal')">×</button>
|
||||
</div>
|
||||
<form onsubmit="event.preventDefault(); submitResetStudentPassword()">
|
||||
<input type="hidden" id="resetStudentId">
|
||||
<p id="resetStudentInfo" style="margin: 10px 0;"></p>
|
||||
<div class="form-group">
|
||||
<label>新密码</label>
|
||||
<input type="password" id="newStudentPassword" required minlength="6" maxlength="20">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" class="btn btn-warning">确认重置</button>
|
||||
<button type="button" class="btn" onclick="closeModal('resetStudentPasswordModal')">取消</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const userRole = '<?php echo $role; ?>';
|
||||
var currentPage = 1;
|
||||
@@ -126,11 +177,14 @@ async function loadStudents(page = 1) {
|
||||
html += `<tr>
|
||||
<td><input type="checkbox" class="student-checkbox" data-id="${student.student_id}"></td>
|
||||
<td>${escapeHtml(student.student_no)}</td>
|
||||
<td>${escapeHtml(student.name)}</td>
|
||||
<td><a href="/admin/history.php?student_id=${student.student_id}" style="color: #3498db; text-decoration: none;">${escapeHtml(student.name)}</a></td>
|
||||
<td>${student.total_points}</td>
|
||||
${userRole === '班主任' ? `<td>${student.parent_phone || '-'}</td>` : ''}
|
||||
<td>
|
||||
<button class="btn btn-sm btn-primary" onclick="showSinglePointsModal(${student.student_id}, '${escapeHtml(student.name)}')">加减分</button>
|
||||
${userRole === '班主任' ? `<button class="btn btn-sm btn-secondary" onclick="showEditStudentModal(${student.student_id}, '${escapeHtml(student.student_no)}', '${escapeHtml(student.name)}', '${escapeHtml(student.parent_phone || '')}')">编辑</button>
|
||||
<button class="btn btn-sm btn-warning" onclick="showResetStudentPasswordModal(${student.student_id}, '${escapeHtml(student.name)}')">重置密码</button>
|
||||
<button class="btn btn-sm btn-danger" onclick="deleteStudent(${student.student_id}, '${escapeHtml(student.name)}')">删除</button>` : ''}
|
||||
</td>
|
||||
</tr>`;
|
||||
});
|
||||
|
||||
@@ -297,4 +297,79 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
if (fileInput) {
|
||||
fileInput.addEventListener('change', previewImportFile);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// ===== 学生编辑/删除/重置密码 =====
|
||||
|
||||
function showEditStudentModal(studentId, studentNo, name, phone) {
|
||||
document.getElementById('editStudentId').value = studentId;
|
||||
document.getElementById('editStudentNo').value = studentNo;
|
||||
document.getElementById('editStudentName').value = name;
|
||||
document.getElementById('editStudentPhone').value = phone || '';
|
||||
document.getElementById('editStudentModal').style.display = 'flex';
|
||||
}
|
||||
|
||||
async function submitEditStudent() {
|
||||
const studentId = document.getElementById('editStudentId').value;
|
||||
const name = document.getElementById('editStudentName').value.trim();
|
||||
const phone = document.getElementById('editStudentPhone').value.trim();
|
||||
|
||||
if (!name) {
|
||||
showToast('请输入姓名', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await apiPut(`/api/admin/students/${studentId}`, {
|
||||
name: name,
|
||||
parent_phone: phone || null
|
||||
});
|
||||
|
||||
if (res && res.success) {
|
||||
showToast('学生信息更新成功');
|
||||
closeModal('editStudentModal');
|
||||
location.reload();
|
||||
} else {
|
||||
showToast(res?.message || '更新失败', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
function showResetStudentPasswordModal(studentId, name) {
|
||||
document.getElementById('resetStudentId').value = studentId;
|
||||
document.getElementById('resetStudentInfo').textContent = `正在重置学生 "${name}" 的密码`;
|
||||
document.getElementById('newStudentPassword').value = '';
|
||||
document.getElementById('resetStudentPasswordModal').style.display = 'flex';
|
||||
}
|
||||
|
||||
async function submitResetStudentPassword() {
|
||||
const studentId = document.getElementById('resetStudentId').value;
|
||||
const newPassword = document.getElementById('newStudentPassword').value;
|
||||
|
||||
if (!newPassword || newPassword.length < 6) {
|
||||
showToast('密码至少6位', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await apiPost(`/api/admin/students/reset-password/${studentId}`, {
|
||||
new_password: newPassword
|
||||
});
|
||||
|
||||
if (res && res.success) {
|
||||
showToast('密码重置成功');
|
||||
closeModal('resetStudentPasswordModal');
|
||||
} else {
|
||||
showToast(res?.message || '重置失败', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteStudent(studentId, name) {
|
||||
if (!confirm(`确定要删除学生 "${name}" 吗?删除后学生账号将被禁用。`)) return;
|
||||
|
||||
const res = await apiDelete(`/api/admin/students/${studentId}`);
|
||||
|
||||
if (res && res.success) {
|
||||
showToast('学生删除成功');
|
||||
location.reload();
|
||||
} else {
|
||||
showToast(res?.message || '删除失败', 'error');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user