1. 月度分排行:管理端首页支持总分/月度分切换与月份选择,新增排行榜导出CSV 2. 数据报表:新增考勤/作业统计页(日期范围、汇总与每人明细、CSV导出) 3. 操作日志:新增查看页(操作类型/操作人/日期筛选,分页) 4. 系统设置:密码策略可配置(长度/字符种类),全站改密与重置统一校验、前端提示同步;策略通过公开配置下发 5. 学期归档对比:查看归档时展示与上一学期的分数变化与名次升降 6. 历史记录导出支持按学生分表(每人一段,便于发家长) 7. 移动端适配:导航横向滚动、表格触控滚动、字号与弹窗优化 8. 版本升级至4.4(无数据库结构变更)
327 lines
13 KiB
JavaScript
327 lines
13 KiB
JavaScript
/**
|
||
* 班级操行分管理系统 - 学期管理页JS
|
||
*
|
||
* 开发者: Canglan
|
||
* 版权归属: Sea Network Technology Studio
|
||
*
|
||
* 版权所有 © Sea Network Technology Studio
|
||
*/
|
||
|
||
(function() {
|
||
'use strict';
|
||
|
||
let archiveSemesterId = null;
|
||
let archivePage = 1;
|
||
let archiveTotalPages = 1;
|
||
let associateSemesterId = null;
|
||
|
||
function fillSemesterDates(type) {
|
||
const now = new Date();
|
||
const currentYear = now.getFullYear();
|
||
const currentMonth = now.getMonth() + 1;
|
||
const startDateInput = document.getElementById('semesterStartDate');
|
||
const endDateInput = document.getElementById('semesterEndDate');
|
||
|
||
if (type === 'upper') {
|
||
const year = currentMonth >= 6 ? currentYear : currentYear - 1;
|
||
const endYear = year + 1;
|
||
let febDay = 28;
|
||
if ((endYear % 4 === 0 && endYear % 100 !== 0) || endYear % 400 === 0) {
|
||
febDay = 29;
|
||
}
|
||
startDateInput.value = year + '-09-01';
|
||
endDateInput.value = endYear + '-02-' + febDay;
|
||
} else if (type === 'lower') {
|
||
startDateInput.value = currentYear + '-03-01';
|
||
endDateInput.value = currentYear + '-07-15';
|
||
}
|
||
}
|
||
|
||
async function loadSemesters() {
|
||
const res = await apiGet('/api/semester/list');
|
||
if (res && res.success) {
|
||
let html = '';
|
||
const semesters = res.data || [];
|
||
semesters.forEach(sem => {
|
||
let statusText = '';
|
||
let statusClass = '';
|
||
if (sem.is_archived) {
|
||
statusText = '已归档';
|
||
statusClass = 'status-badge status-not_submitted';
|
||
} else if (sem.is_active) {
|
||
statusText = '当前学期';
|
||
statusClass = 'status-badge status-submitted';
|
||
} else {
|
||
statusText = '未激活';
|
||
statusClass = 'status-badge status-late';
|
||
}
|
||
|
||
let actions = '';
|
||
const startDate = sem.start_date || '';
|
||
const endDate = sem.end_date || '';
|
||
if (!sem.is_archived) {
|
||
actions += `<div class="action-dropdown">
|
||
<button class="btn btn-sm action-dropdown-toggle" onclick="toggleActionDropdown(this)">操作 ▼</button>
|
||
<div class="action-dropdown-menu">
|
||
<a onclick="showEditSemesterModal(${sem.semester_id}, '${escapeHtml(sem.semester_name)}', '${startDate}', '${endDate}')">编辑</a>
|
||
${!sem.is_active ? `<a onclick="activateSemester(${sem.semester_id})">激活</a>` : ''}
|
||
<a onclick="showAssociateConfirm(${sem.semester_id}, '${escapeHtml(sem.semester_name)}', '${startDate}', '${endDate}')">关联数据</a>
|
||
<a class="danger" onclick="showArchiveConfirm(${sem.semester_id}, '${escapeHtml(sem.semester_name)}')">归档</a>
|
||
</div>
|
||
</div>`;
|
||
}
|
||
if (sem.is_archived) {
|
||
actions += `<button class="btn btn-sm btn-secondary" onclick="viewArchiveData(${sem.semester_id}, '${escapeHtml(sem.semester_name)}')">查看归档</button>`;
|
||
}
|
||
|
||
const conductCount = sem.conduct_count || 0;
|
||
const attendanceCount = sem.attendance_count || 0;
|
||
let recordText = '-';
|
||
if (conductCount > 0 || attendanceCount > 0) {
|
||
recordText = `${conductCount}条操行分 / ${attendanceCount}条考勤`;
|
||
}
|
||
|
||
const weekText = sem.current_week ? `第${sem.current_week}周` : '-';
|
||
html += `<tr>
|
||
<td>${escapeHtml(sem.semester_name)}</td>
|
||
<td>${formatDate(sem.start_date)}</td>
|
||
<td>${formatDate(sem.end_date)}</td>
|
||
<td>${weekText}</td>
|
||
<td><span class="${statusClass}">${statusText}</span></td>
|
||
<td>${recordText}</td>
|
||
<td>${formatDateTime(sem.created_at)}</td>
|
||
<td>${actions}</td>
|
||
</tr>`;
|
||
});
|
||
if (semesters.length === 0) {
|
||
html = '<tr><td colspan="8" style="text-align:center;">暂无学期,请点击上方按钮创建新学期</td></tr>';
|
||
}
|
||
document.getElementById('semesterList').innerHTML = html;
|
||
}
|
||
}
|
||
|
||
function showCreateSemesterModal() {
|
||
document.getElementById('semesterName').value = '';
|
||
document.getElementById('semesterStartDate').value = '';
|
||
document.getElementById('semesterEndDate').value = '';
|
||
document.getElementById('createSemesterModal').style.display = 'flex';
|
||
}
|
||
|
||
async function submitCreateSemester() {
|
||
const name = document.getElementById('semesterName').value.trim();
|
||
const startDate = document.getElementById('semesterStartDate').value;
|
||
const endDate = document.getElementById('semesterEndDate').value;
|
||
|
||
if (!name) {
|
||
showToast('请输入学期名称', 'warning');
|
||
return;
|
||
}
|
||
|
||
const res = await apiPost('/api/semester/create', {
|
||
semester_name: name,
|
||
start_date: startDate || null,
|
||
end_date: endDate || null
|
||
});
|
||
|
||
if (res && res.success) {
|
||
showToast(res.message || '学期创建成功');
|
||
closeModal('createSemesterModal');
|
||
loadSemesters();
|
||
} else {
|
||
showToast(res?.message || '创建失败', 'error');
|
||
}
|
||
}
|
||
|
||
async function activateSemester(semesterId) {
|
||
if (!confirm('确认将此学期设为当前活跃学期?其他学期将被设为非活跃。')) {
|
||
return;
|
||
}
|
||
|
||
const res = await apiPut(`/api/semester/activate/${semesterId}`);
|
||
if (res && res.success) {
|
||
showToast(res.message || '已设为当前学期');
|
||
loadSemesters();
|
||
} else {
|
||
showToast(res?.message || '操作失败', 'error');
|
||
}
|
||
}
|
||
|
||
function showEditSemesterModal(id, name, startDate, endDate) {
|
||
document.getElementById('editSemesterId').value = id;
|
||
document.getElementById('editSemesterName').value = name;
|
||
document.getElementById('editSemesterStartDate').value = startDate || '';
|
||
document.getElementById('editSemesterEndDate').value = endDate || '';
|
||
document.getElementById('editSemesterModal').style.display = 'flex';
|
||
}
|
||
|
||
async function submitEditSemester() {
|
||
const id = document.getElementById('editSemesterId').value;
|
||
const name = document.getElementById('editSemesterName').value.trim();
|
||
const startDate = document.getElementById('editSemesterStartDate').value;
|
||
const endDate = document.getElementById('editSemesterEndDate').value;
|
||
|
||
if (!name) {
|
||
showToast('请输入学期名称', 'warning');
|
||
return;
|
||
}
|
||
|
||
const data = { semester_name: name };
|
||
if (startDate) data.start_date = startDate;
|
||
if (endDate) data.end_date = endDate;
|
||
|
||
const res = await apiPut(`/api/semester/update/${id}`, data);
|
||
if (res && res.success) {
|
||
showToast(res.message || '更新成功');
|
||
closeModal('editSemesterModal');
|
||
loadSemesters();
|
||
} else {
|
||
showToast(res?.message || '更新失败', 'error');
|
||
}
|
||
}
|
||
|
||
async function deleteSemester() {
|
||
const id = document.getElementById('editSemesterId').value;
|
||
if (!confirm('确定要删除该学期吗?如果学期已有归档数据则无法删除。')) {
|
||
return;
|
||
}
|
||
|
||
const res = await apiDelete(`/api/semester/delete/${id}`);
|
||
if (res && res.success) {
|
||
showToast(res.message || '删除成功');
|
||
closeModal('editSemesterModal');
|
||
loadSemesters();
|
||
} else {
|
||
showToast(res?.message || '删除失败', 'error');
|
||
}
|
||
}
|
||
|
||
function showAssociateConfirm(id, name, startDate, endDate) {
|
||
associateSemesterId = id;
|
||
const dateRange = startDate ? `${startDate} ~ ${endDate || '至今'}` : '未设置日期范围';
|
||
document.getElementById('associateConfirmText').innerHTML =
|
||
`即将关联 <strong>${dateRange}</strong> 内的所有未分配学期的操行分记录和考勤记录到学期 "<strong>${name}</strong>"。`;
|
||
document.getElementById('associateConfirmModal').style.display = 'flex';
|
||
}
|
||
|
||
async function confirmAssociate() {
|
||
if (!associateSemesterId) return;
|
||
|
||
const res = await apiPost(`/api/semester/${associateSemesterId}/associate`);
|
||
if (res && res.success) {
|
||
showToast(res.message || '关联成功');
|
||
closeModal('associateConfirmModal');
|
||
associateSemesterId = null;
|
||
} else {
|
||
showToast(res?.message || '关联失败', 'error');
|
||
}
|
||
}
|
||
|
||
function showArchiveConfirm(semesterId, semesterName) {
|
||
archiveSemesterId = semesterId;
|
||
document.getElementById('archiveResetScores').checked = false;
|
||
document.getElementById('archiveConfirmText').innerHTML =
|
||
`确定要归档学期 "<strong>${semesterName}</strong>" 吗?<br>归档后将保存所有学生的当前操行分快照,该学期数据将变为只读。`;
|
||
document.getElementById('archiveConfirmModal').style.display = 'flex';
|
||
}
|
||
|
||
async function confirmArchive() {
|
||
if (!archiveSemesterId) return;
|
||
|
||
const resetScores = document.getElementById('archiveResetScores').checked;
|
||
const url = `/api/semester/archive/${archiveSemesterId}?reset_scores=${resetScores}`;
|
||
|
||
const res = await apiPost(url);
|
||
if (res && res.success) {
|
||
showToast(res.message || '归档成功');
|
||
closeModal('archiveConfirmModal');
|
||
archiveSemesterId = null;
|
||
loadSemesters();
|
||
} else {
|
||
showToast(res?.message || '归档失败', 'error');
|
||
}
|
||
}
|
||
|
||
async function viewArchiveData(semesterId, semesterName, page) {
|
||
page = page || 1;
|
||
archivePage = page;
|
||
document.getElementById('archiveDataTitle').textContent = `归档数据 - ${semesterName}`;
|
||
|
||
const res = await apiGet(`/api/semester/archive/${semesterId}/records`, {
|
||
page: page, page_size: 50
|
||
});
|
||
|
||
if (res && res.success) {
|
||
const data = res.data || {};
|
||
const archives = data.archives || [];
|
||
const prevName = data.previous_semester ? data.previous_semester.semester_name : null;
|
||
document.getElementById('archiveDataTitle').textContent =
|
||
`归档数据 - ${semesterName}` + (prevName ? `(对比:${prevName})` : '(无对比学期)');
|
||
let html = '';
|
||
archives.forEach(a => {
|
||
const points = a.points_change;
|
||
const hasPoints = (points !== null && points !== undefined);
|
||
const pointsText = hasPoints ? (points > 0 ? '+' + points : String(points)) : '-';
|
||
const pointsClass = hasPoints ? (points > 0 ? 'plus' : (points < 0 ? 'minus' : '')) : '';
|
||
|
||
const rankChange = a.rank_change;
|
||
const hasRank = (rankChange !== null && rankChange !== undefined);
|
||
let rankText = '-';
|
||
let rankClass = '';
|
||
if (hasRank) {
|
||
if (rankChange > 0) { rankText = '↑' + rankChange; rankClass = 'plus'; }
|
||
else if (rankChange < 0) { rankText = '↓' + Math.abs(rankChange); rankClass = 'minus'; }
|
||
else { rankText = '-'; }
|
||
}
|
||
|
||
html += `<tr>
|
||
<td>${a.rank_position || '-'}</td>
|
||
<td>${escapeHtml(a.student_no)}</td>
|
||
<td>${escapeHtml(a.student_name)}</td>
|
||
<td>${a.final_points}</td>
|
||
<td class="${pointsClass}">${pointsText}</td>
|
||
<td class="${rankClass}">${rankText}</td>
|
||
<td>${a.attendance_present || 0}</td>
|
||
<td>${a.attendance_absent || 0}</td>
|
||
<td>${a.attendance_late || 0}</td>
|
||
<td>${a.attendance_leave || 0}</td>
|
||
<td>${a.homework_submitted || 0}</td>
|
||
<td>${a.homework_not_submitted || 0}</td>
|
||
<td>${a.homework_late || 0}</td>
|
||
</tr>`;
|
||
});
|
||
if (archives.length === 0) {
|
||
html = '<tr><td colspan="13" style="text-align:center;">暂无归档数据</td></tr>';
|
||
}
|
||
document.getElementById('archiveDataList').innerHTML = html;
|
||
|
||
archiveTotalPages = data.total_pages || 1;
|
||
renderArchivePagination(semesterId, semesterName);
|
||
document.getElementById('archiveDataModal').style.display = 'flex';
|
||
} else {
|
||
showToast(res?.message || '获取归档数据失败', 'error');
|
||
}
|
||
}
|
||
|
||
function renderArchivePagination(semesterId, semesterName) {
|
||
renderSmartPagination('archivePagination', archivePage, archiveTotalPages, function(page) {
|
||
viewArchiveData(semesterId, semesterName, page);
|
||
});
|
||
}
|
||
|
||
loadSemesters();
|
||
|
||
window.fillSemesterDates = fillSemesterDates;
|
||
window.showCreateSemesterModal = showCreateSemesterModal;
|
||
window.submitCreateSemester = submitCreateSemester;
|
||
window.activateSemester = activateSemester;
|
||
window.showEditSemesterModal = showEditSemesterModal;
|
||
window.submitEditSemester = submitEditSemester;
|
||
window.deleteSemester = deleteSemester;
|
||
window.showAssociateConfirm = showAssociateConfirm;
|
||
window.confirmAssociate = confirmAssociate;
|
||
window.showArchiveConfirm = showArchiveConfirm;
|
||
window.confirmArchive = confirmArchive;
|
||
window.viewArchiveData = viewArchiveData;
|
||
|
||
})();
|