96 lines
4.0 KiB
JavaScript
96 lines
4.0 KiB
JavaScript
/**
|
|
* 班级操行分管理系统 - 学生管理页JS
|
|
*
|
|
* 开发者: Canglan
|
|
* 版权归属: Sea Network Technology Studio
|
|
*
|
|
* 版权所有 © Sea Network Technology Studio
|
|
*/
|
|
|
|
(function() {
|
|
'use strict';
|
|
|
|
const userRole = window.PAGE_CONFIG.role;
|
|
let currentPage = 1;
|
|
let totalPages = 1;
|
|
|
|
async function loadStudents(page = 1) {
|
|
currentPage = page;
|
|
const search = document.getElementById('searchInput').value;
|
|
const res = await apiGet('/api/admin/students', { page, page_size: 20, search });
|
|
|
|
if (res && res.success) {
|
|
let html = '';
|
|
res.data.students.forEach(student => {
|
|
html += `<tr>
|
|
<td><input type="checkbox" class="student-checkbox" data-id="${student.student_id}"></td>
|
|
<td>${escapeHtml(student.student_no)}</td>
|
|
<td><a href="/admin/history.php?student_id=${student.student_id}" style="color: #3498db; text-decoration: none;">${escapeHtml(student.name)}</a></td>
|
|
<td>${escapeHtml(student.dormitory_number || '-')}</td>
|
|
<td>${student.total_points}</td>
|
|
${userRole === '班主任' ? `<td>${student.parent_phone ? student.parent_phone.slice(0,3) + '******' + student.parent_phone.slice(-2) : '-'}</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 || '')}', '${escapeHtml(student.dormitory_number || '')}')">编辑</button>
|
|
<button class="btn btn-sm btn-warning" onclick="showResetStudentPasswordModal(${student.student_id}, '${escapeHtml(student.name)}')">重置密码</button>
|
|
<button class="btn btn-sm btn-info" onclick="unlockStudent('${escapeHtml(student.student_no)}', '${escapeHtml(student.name)}')">解锁</button>
|
|
<button class="btn btn-sm btn-danger" onclick="deleteStudent(${student.student_id}, '${escapeHtml(student.name)}')">删除</button>` : ''}
|
|
</td>
|
|
</tr>`;
|
|
});
|
|
|
|
if (res.data.students.length === 0) {
|
|
html = `<tr><td colspan="${userRole === '班主任' ? '7' : '6'}" style="text-align:center;">暂无学生数据</td></tr>`;
|
|
}
|
|
|
|
document.getElementById('studentList').innerHTML = html;
|
|
|
|
totalPages = res.data.total_pages || 1;
|
|
renderPagination();
|
|
}
|
|
}
|
|
|
|
function renderPagination() {
|
|
renderSmartPagination('pagination', currentPage, totalPages, function(page) {
|
|
loadStudents(page);
|
|
});
|
|
}
|
|
|
|
function showSinglePointsModal(studentId, studentName) {
|
|
window.selectedStudentIds = [studentId];
|
|
document.getElementById('selectedStudentsCount').innerHTML = `${studentName} (1人)`;
|
|
document.getElementById('pointsChange').value = '';
|
|
document.getElementById('pointsReason').value = '';
|
|
document.getElementById('batchPointsModal').style.display = 'flex';
|
|
}
|
|
|
|
async function unlockStudent(studentNo, studentName) {
|
|
if (!confirm(`确定要解除学生 "${studentName}" 的登录锁定吗?\n(适用于多次登录失败被禁止登录的情况)`)) {
|
|
return;
|
|
}
|
|
|
|
const res = await apiPost('/api/admin/unlock-user', {
|
|
username: studentNo
|
|
});
|
|
|
|
if (res && res.success) {
|
|
showToast(res.message || '解锁成功');
|
|
} else {
|
|
showToast(res?.message || '解锁失败', 'error');
|
|
}
|
|
}
|
|
|
|
loadStudents();
|
|
|
|
let searchTimeout;
|
|
document.getElementById('searchInput').addEventListener('input', () => {
|
|
clearTimeout(searchTimeout);
|
|
searchTimeout = setTimeout(() => loadStudents(1), 500);
|
|
});
|
|
|
|
window.loadStudents = loadStudents;
|
|
window.showSinglePointsModal = showSinglePointsModal;
|
|
window.unlockStudent = unlockStudent;
|
|
|
|
})();
|