v4.4 数据报表/操作日志/系统设置与月度分排行
1. 月度分排行:管理端首页支持总分/月度分切换与月份选择,新增排行榜导出CSV 2. 数据报表:新增考勤/作业统计页(日期范围、汇总与每人明细、CSV导出) 3. 操作日志:新增查看页(操作类型/操作人/日期筛选,分页) 4. 系统设置:密码策略可配置(长度/字符种类),全站改密与重置统一校验、前端提示同步;策略通过公开配置下发 5. 学期归档对比:查看归档时展示与上一学期的分数变化与名次升降 6. 历史记录导出支持按学生分表(每人一段,便于发家长) 7. 移动端适配:导航横向滚动、表格触控滚动、字号与弹窗优化 8. 版本升级至4.4(无数据库结构变更)
This commit is contained in:
1 parent
9a19add6c1
commit
768ea281e0
54 files changed
+1782
-90
No files matched your search
@@ -231,8 +231,9 @@ async function submitResetPassword() {
|
||||
if (!currentResetUserId) return;
|
||||
|
||||
const newPassword = document.getElementById('newPassword').value;
|
||||
if (!newPassword || newPassword.length < 6) {
|
||||
showToast('密码长度至少6位', 'warning');
|
||||
const policyError = validatePasswordByPolicy(newPassword);
|
||||
if (policyError) {
|
||||
showToast(policyError, 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -275,6 +275,45 @@ function validateScoreChange(value) {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前密码策略(由后端配置下发)
|
||||
*/
|
||||
function getPasswordPolicy() {
|
||||
return {
|
||||
minLength: window.PASSWORD_MIN_LENGTH || 6,
|
||||
maxLength: window.PASSWORD_MAX_LENGTH || 20,
|
||||
minTypes: window.PASSWORD_MIN_TYPES || 3
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 密码策略提示文本
|
||||
*/
|
||||
function describePasswordPolicy() {
|
||||
const p = getPasswordPolicy();
|
||||
return '密码长度' + p.minLength + '-' + p.maxLength + '位,需包含大写字母、小写字母、数字、特殊符号中的至少' + p.minTypes + '种';
|
||||
}
|
||||
|
||||
/**
|
||||
* 按密码策略校验,返回错误信息(空字符串表示通过)
|
||||
*/
|
||||
function validatePasswordByPolicy(password) {
|
||||
const p = getPasswordPolicy();
|
||||
if (!password || password.length < p.minLength) {
|
||||
return '密码长度至少' + p.minLength + '位';
|
||||
}
|
||||
if (password.length > p.maxLength) {
|
||||
return '密码长度不能超过' + p.maxLength + '位';
|
||||
}
|
||||
const types = [/[A-Z]/, /[a-z]/, /[0-9]/, /[^A-Za-z0-9]/].filter(function(re) {
|
||||
return re.test(password);
|
||||
}).length;
|
||||
if (types < p.minTypes) {
|
||||
return '密码需包含大写字母、小写字母、数字、特殊符号中的至少' + p.minTypes + '种';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function showToast(message, type = 'success') {
|
||||
const toast = document.createElement('div');
|
||||
toast.className = `toast toast-${type}`;
|
||||
@@ -490,6 +529,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
if (logoutBtn) {
|
||||
logoutBtn.addEventListener('click', logout);
|
||||
}
|
||||
document.querySelectorAll('.pwd-policy').forEach(function(el) {
|
||||
el.textContent = describePasswordPolicy();
|
||||
});
|
||||
});
|
||||
|
||||
function toggleActionDropdown(el) {
|
||||
|
||||
@@ -71,24 +71,109 @@ async function loadDashboard() {
|
||||
}
|
||||
document.getElementById('quickActions').innerHTML = quickActions || '<p>暂无快捷操作</p>';
|
||||
|
||||
const rankingRes = await apiGet('/api/student/ranking', { limit: 100 });
|
||||
if (rankingRes && rankingRes.success) {
|
||||
totalStudents = rankingRes.data.total_students || 0;
|
||||
let html = '';
|
||||
rankingRes.data.ranking.forEach((student, index) => {
|
||||
const rank = index + 1;
|
||||
await loadRanking();
|
||||
}
|
||||
|
||||
async function loadRanking() {
|
||||
const type = document.getElementById('rankingType').value;
|
||||
const params = { limit: 100 };
|
||||
if (type === 'monthly') {
|
||||
const monthInput = document.getElementById('rankingMonth');
|
||||
if (monthInput.value) params.month = monthInput.value;
|
||||
}
|
||||
|
||||
const rankingRes = await apiGet('/api/student/ranking', params);
|
||||
const head = document.getElementById('rankingHead');
|
||||
if (type === 'monthly') {
|
||||
head.innerHTML = '<th>排名</th><th>学号</th><th>姓名</th><th>加分</th><th>减分</th><th>月度分</th>';
|
||||
} else {
|
||||
head.innerHTML = '<th>排名</th><th>学号</th><th>姓名</th><th>操行分</th>';
|
||||
}
|
||||
if (!rankingRes || !rankingRes.success) return;
|
||||
|
||||
totalStudents = rankingRes.data.total_students || 0;
|
||||
let html = '';
|
||||
rankingRes.data.ranking.forEach((student, index) => {
|
||||
const rank = index + 1;
|
||||
if (type === 'monthly') {
|
||||
const score = student.month_score || 0;
|
||||
const cls = score > 0 ? 'plus' : (score < 0 ? 'minus' : '');
|
||||
html += `<tr>
|
||||
<td>${rank}</td>
|
||||
<td>${escapeHtml(student.student_no)}</td>
|
||||
<td>${escapeHtml(student.name)}</td>
|
||||
<td class="plus">+${student.bonus || 0}</td>
|
||||
<td class="minus">${student.deduction || 0}</td>
|
||||
<td class="${cls}">${score > 0 ? '+' : ''}${score}</td>
|
||||
</tr>`;
|
||||
} else {
|
||||
html += `<tr>
|
||||
<td>${rank}</td>
|
||||
<td>${escapeHtml(student.student_no)}</td>
|
||||
<td>${escapeHtml(student.name)}</td>
|
||||
<td>${student.total_points}</td>
|
||||
</tr>`;
|
||||
});
|
||||
if (rankingRes.data.ranking.length === 0) {
|
||||
html = '<tr><td colspan="4" style="text-align:center;">暂无数据</td></tr>';
|
||||
}
|
||||
document.getElementById('rankingList').innerHTML = html;
|
||||
});
|
||||
if (rankingRes.data.ranking.length === 0) {
|
||||
const cols = type === 'monthly' ? 6 : 4;
|
||||
html = `<tr><td colspan="${cols}" style="text-align:center;">暂无数据</td></tr>`;
|
||||
}
|
||||
document.getElementById('rankingList').innerHTML = html;
|
||||
}
|
||||
|
||||
function onRankingTypeChange() {
|
||||
const isMonthly = document.getElementById('rankingType').value === 'monthly';
|
||||
const monthInput = document.getElementById('rankingMonth');
|
||||
monthInput.style.display = isMonthly ? '' : 'none';
|
||||
if (isMonthly && !monthInput.value) {
|
||||
const now = new Date();
|
||||
monthInput.value = now.getFullYear() + '-' + String(now.getMonth() + 1).padStart(2, '0');
|
||||
}
|
||||
resetPercentileFilter();
|
||||
loadRanking();
|
||||
}
|
||||
|
||||
async function exportRanking() {
|
||||
const type = document.getElementById('rankingType').value;
|
||||
const params = { limit: 1000 };
|
||||
let label = '总分排行';
|
||||
if (type === 'monthly') {
|
||||
const month = document.getElementById('rankingMonth').value;
|
||||
if (!month) {
|
||||
showToast('请先选择月份', 'warning');
|
||||
return;
|
||||
}
|
||||
params.month = month;
|
||||
label = '月度排行_' + month;
|
||||
}
|
||||
|
||||
const res = await apiGet('/api/student/ranking', params);
|
||||
if (!res || !res.success) {
|
||||
showToast('导出失败', 'error');
|
||||
return;
|
||||
}
|
||||
const ranking = res.data.ranking || [];
|
||||
if (ranking.length === 0) {
|
||||
showToast('没有可导出的数据', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
let csv = type === 'monthly'
|
||||
? '排名,学号,姓名,加分,减分,月度分\n'
|
||||
: '排名,学号,姓名,操行分\n';
|
||||
ranking.forEach(function(s, index) {
|
||||
if (type === 'monthly') {
|
||||
csv += [index + 1, s.student_no, s.name, s.bonus || 0, s.deduction || 0, s.month_score || 0]
|
||||
.map(csvEscape).join(',') + '\n';
|
||||
} else {
|
||||
csv += [index + 1, s.student_no, s.name, s.total_points]
|
||||
.map(csvEscape).join(',') + '\n';
|
||||
}
|
||||
});
|
||||
|
||||
downloadCsv('排行榜_' + label + '_' + new Date().toISOString().slice(0,10) + '.csv', csv);
|
||||
showToast('导出成功,共' + ranking.length + '人');
|
||||
}
|
||||
|
||||
function applyPercentileFilter() {
|
||||
@@ -121,6 +206,9 @@ document.getElementById('percentileFilter').addEventListener('keypress', functio
|
||||
loadDashboard();
|
||||
|
||||
window.loadDashboard = loadDashboard;
|
||||
window.loadRanking = loadRanking;
|
||||
window.onRankingTypeChange = onRankingTypeChange;
|
||||
window.exportRanking = exportRanking;
|
||||
window.applyPercentileFilter = applyPercentileFilter;
|
||||
window.resetPercentileFilter = resetPercentileFilter;
|
||||
|
||||
|
||||
@@ -246,12 +246,81 @@ async function exportHistoryRecords() {
|
||||
return;
|
||||
}
|
||||
|
||||
var csv = '时间,学号,姓名,学期,类型,分数变动,原因,操作人\n';
|
||||
records.forEach(function(r) {
|
||||
var mode = getHistoryExportMode();
|
||||
var csv;
|
||||
if (mode === 'per_student') {
|
||||
csv = buildPerStudentCsv(records);
|
||||
} else {
|
||||
csv = '时间,学号,姓名,学期,类型,分数变动,原因,操作人\n';
|
||||
records.forEach(function(r) {
|
||||
csv += [
|
||||
r.created_at || '',
|
||||
r.student_no || '',
|
||||
r.student_name || '',
|
||||
r.semester_name || '',
|
||||
typeMap(r.related_type),
|
||||
(r.points_change > 0 ? '+' : '') + r.points_change,
|
||||
r.reason || '',
|
||||
r.recorder_name || ''
|
||||
].map(csvEscape).join(',') + '\n';
|
||||
});
|
||||
}
|
||||
|
||||
var semesterLabel = '全部学期';
|
||||
if (semesterSelect && semesterId && semesterSelect.selectedIndex >= 0) {
|
||||
semesterLabel = semesterSelect.options[semesterSelect.selectedIndex].textContent.replace(/((当前|已归档))$/, '');
|
||||
}
|
||||
var safeLabel = semesterLabel.replace(/[\\/:*?"<>|]/g, '_');
|
||||
var modeLabel = mode === 'per_student' ? '_按学生分表' : '';
|
||||
downloadCsv('历史记录_' + safeLabel + modeLabel + '_' + new Date().toISOString().slice(0,10) + '.csv', csv);
|
||||
|
||||
closeModal('exportHistoryModal');
|
||||
showToast('导出成功,共' + records.length + '条记录');
|
||||
} catch (err) {
|
||||
showToast('导出失败:' + err.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
function showExportHistoryModal() {
|
||||
document.getElementById('exportHistoryModal').style.display = 'flex';
|
||||
}
|
||||
|
||||
function getHistoryExportMode() {
|
||||
var el = document.querySelector('input[name="historyExportMode"]:checked');
|
||||
return el ? el.value : 'detail';
|
||||
}
|
||||
|
||||
// 按学生分表:每个学生一段(汇总 + 明细),便于发给家长
|
||||
function buildPerStudentCsv(records) {
|
||||
var groups = {};
|
||||
var order = [];
|
||||
records.forEach(function(r) {
|
||||
var key = r.student_id;
|
||||
if (!groups[key]) {
|
||||
groups[key] = { no: r.student_no || '', name: r.student_name || '', records: [] };
|
||||
order.push(key);
|
||||
}
|
||||
groups[key].records.push(r);
|
||||
});
|
||||
order.sort(function(a, b) {
|
||||
return String(groups[a].no).localeCompare(String(groups[b].no));
|
||||
});
|
||||
|
||||
var csv = '';
|
||||
order.forEach(function(key) {
|
||||
var group = groups[key];
|
||||
var bonus = 0;
|
||||
var deduction = 0;
|
||||
group.records.forEach(function(r) {
|
||||
if (r.points_change > 0) bonus += r.points_change;
|
||||
else deduction += r.points_change;
|
||||
});
|
||||
csv += ['学生', group.no + ' ' + group.name, '加分合计', '+' + bonus, '减分合计', deduction]
|
||||
.map(csvEscape).join(',') + '\n';
|
||||
csv += '时间,学期,类型,分值,原因,操作人\n';
|
||||
group.records.forEach(function(r) {
|
||||
csv += [
|
||||
r.created_at || '',
|
||||
r.student_no || '',
|
||||
r.student_name || '',
|
||||
r.semester_name || '',
|
||||
typeMap(r.related_type),
|
||||
(r.points_change > 0 ? '+' : '') + r.points_change,
|
||||
@@ -259,18 +328,9 @@ async function exportHistoryRecords() {
|
||||
r.recorder_name || ''
|
||||
].map(csvEscape).join(',') + '\n';
|
||||
});
|
||||
|
||||
var semesterLabel = '全部学期';
|
||||
if (semesterSelect && semesterId && semesterSelect.selectedIndex >= 0) {
|
||||
semesterLabel = semesterSelect.options[semesterSelect.selectedIndex].textContent.replace(/((当前|已归档))$/, '');
|
||||
}
|
||||
var safeLabel = semesterLabel.replace(/[\\/:*?"<>|]/g, '_');
|
||||
downloadCsv('历史记录_' + safeLabel + '_' + new Date().toISOString().slice(0,10) + '.csv', csv);
|
||||
|
||||
showToast('导出成功,共' + records.length + '条记录');
|
||||
} catch (err) {
|
||||
showToast('导出失败:' + err.message, 'error');
|
||||
}
|
||||
csv += '\n';
|
||||
});
|
||||
return csv;
|
||||
}
|
||||
|
||||
// 批量撤销合并记录(按条件查找并撤销)
|
||||
@@ -333,6 +393,7 @@ Promise.all([loadStudentsForSelect(), loadSubjectsForFilter(), loadSemestersForF
|
||||
|
||||
window.loadHistory = loadHistory;
|
||||
window.loadStudentsForSelect = loadStudentsForSelect;
|
||||
window.showExportHistoryModal = showExportHistoryModal;
|
||||
window.exportHistoryRecords = exportHistoryRecords;
|
||||
window.batchRevokeGrouped = batchRevokeGrouped;
|
||||
window.onStudentFilterChange = onStudentFilterChange;
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
/**
|
||||
* 班级操行分管理系统 - 操作日志页JS
|
||||
*
|
||||
* 开发者: Canglan
|
||||
* 版权归属: Sea Network Technology Studio
|
||||
*
|
||||
* 版权所有 © Sea Network Technology Studio
|
||||
*/
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
const OPERATION_TYPES = {
|
||||
add_student: '新增学生',
|
||||
update_student: '编辑学生',
|
||||
delete_student: '删除学生',
|
||||
import_students: '导入学生',
|
||||
reset_student_password: '重置学生密码',
|
||||
add_points: '加减分',
|
||||
revoke_record: '撤销记录',
|
||||
restore_record: '反撤销记录',
|
||||
add_attendance: '添加考勤',
|
||||
add_admin: '添加管理员',
|
||||
reactivate_admin: '重新激活管理员',
|
||||
update_admin: '编辑管理员',
|
||||
toggle_admin_status: '启用/禁用管理员',
|
||||
reset_password: '重置管理员密码',
|
||||
unlock_user: '解除登录锁定',
|
||||
create_semester: '创建学期',
|
||||
update_semester: '编辑学期',
|
||||
delete_semester: '删除学期',
|
||||
activate_semester: '激活学期',
|
||||
associate_records: '关联学期数据',
|
||||
archive_semester: '归档学期',
|
||||
create_permission_group: '新建权限组',
|
||||
update_permission_group: '编辑权限组',
|
||||
delete_permission_group: '删除权限组',
|
||||
update_password_policy: '修改密码策略'
|
||||
};
|
||||
|
||||
const TARGET_TYPES = {
|
||||
student: '学生',
|
||||
admin: '管理员',
|
||||
conduct: '操行分',
|
||||
attendance: '考勤',
|
||||
semester: '学期',
|
||||
subject: '科目',
|
||||
permission_group: '权限组',
|
||||
user: '用户',
|
||||
setting: '系统设置'
|
||||
};
|
||||
|
||||
let currentPage = 1;
|
||||
|
||||
function operationLabel(type) {
|
||||
return OPERATION_TYPES[type] || type;
|
||||
}
|
||||
|
||||
function targetLabel(type) {
|
||||
return type ? (TARGET_TYPES[type] || type) : '-';
|
||||
}
|
||||
|
||||
async function loadLogTypes() {
|
||||
const res = await apiGet('/api/admin/operation-logs/types');
|
||||
if (res && res.success && res.data && res.data.types) {
|
||||
const select = document.getElementById('logTypeFilter');
|
||||
let html = '<option value="">全部</option>';
|
||||
res.data.types.forEach(function(type) {
|
||||
html += '<option value="' + escapeHtml(type) + '">' + escapeHtml(operationLabel(type)) + '</option>';
|
||||
});
|
||||
select.innerHTML = html;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadLogs(page) {
|
||||
currentPage = page || 1;
|
||||
const params = {
|
||||
page: currentPage,
|
||||
page_size: 20,
|
||||
operation_type: document.getElementById('logTypeFilter').value,
|
||||
operator: document.getElementById('logOperatorFilter').value.trim(),
|
||||
start_date: document.getElementById('logStartDate').value,
|
||||
end_date: document.getElementById('logEndDate').value
|
||||
};
|
||||
|
||||
const res = await apiGet('/api/admin/operation-logs', params);
|
||||
if (!res || !res.success) {
|
||||
showToast((res && res.message) || '加载操作日志失败', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
let html = '';
|
||||
(res.data.logs || []).forEach(function(log) {
|
||||
const targetText = targetLabel(log.target_type) + (log.target_id ? '#' + log.target_id : '');
|
||||
html += `<tr>
|
||||
<td style="white-space: nowrap;">${formatDateTime(log.created_at)}</td>
|
||||
<td>${escapeHtml(log.operator_name || '-')}</td>
|
||||
<td>${escapeHtml(log.operator_role || '-')}</td>
|
||||
<td>${escapeHtml(operationLabel(log.operation_type))}</td>
|
||||
<td style="white-space: nowrap;">${escapeHtml(targetText)}</td>
|
||||
<td class="cell-wrap">${escapeHtml(log.details || '-')}</td>
|
||||
<td>${escapeHtml(log.ip_address || '-')}</td>
|
||||
</tr>`;
|
||||
});
|
||||
if ((res.data.logs || []).length === 0) {
|
||||
html = '<tr><td colspan="7" style="text-align:center;">暂无日志</td></tr>';
|
||||
}
|
||||
document.getElementById('logList').innerHTML = html;
|
||||
|
||||
renderSmartPagination('logPagination', currentPage, res.data.total_pages || 1, function(page) {
|
||||
loadLogs(page);
|
||||
});
|
||||
}
|
||||
|
||||
loadLogTypes();
|
||||
loadLogs(1);
|
||||
|
||||
window.loadLogs = loadLogs;
|
||||
|
||||
})();
|
||||
@@ -94,8 +94,9 @@
|
||||
const studentId = document.getElementById('resetStudentId').value;
|
||||
const newPassword = document.getElementById('newStudentPassword').value;
|
||||
|
||||
if (!newPassword || newPassword.length < 6) {
|
||||
showToast('密码至少6位', 'warning');
|
||||
const policyError = validatePasswordByPolicy(newPassword);
|
||||
if (policyError) {
|
||||
showToast(policyError, 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
/**
|
||||
* 班级操行分管理系统 - 数据报表页JS
|
||||
*
|
||||
* 开发者: Canglan
|
||||
* 版权归属: Sea Network Technology Studio
|
||||
*
|
||||
* 版权所有 © Sea Network Technology Studio
|
||||
*/
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
let attendanceCache = null;
|
||||
let homeworkCache = null;
|
||||
|
||||
function formatDateValue(date) {
|
||||
return date.getFullYear() + '-' + String(date.getMonth() + 1).padStart(2, '0') + '-' + String(date.getDate()).padStart(2, '0');
|
||||
}
|
||||
|
||||
async function initReportDates() {
|
||||
const startInput = document.getElementById('reportStartDate');
|
||||
const endInput = document.getElementById('reportEndDate');
|
||||
const today = new Date();
|
||||
let start = new Date(today.getFullYear(), today.getMonth(), 1);
|
||||
|
||||
try {
|
||||
const res = await apiGet('/api/semester/active');
|
||||
if (res && res.success && res.data && res.data.start_date) {
|
||||
start = new Date(res.data.start_date);
|
||||
}
|
||||
} catch (e) { /* 使用默认月初 */ }
|
||||
|
||||
startInput.value = formatDateValue(start);
|
||||
endInput.value = formatDateValue(today);
|
||||
}
|
||||
|
||||
async function loadReports() {
|
||||
const startDate = document.getElementById('reportStartDate').value;
|
||||
const endDate = document.getElementById('reportEndDate').value;
|
||||
if (!startDate || !endDate) {
|
||||
showToast('请选择开始和结束日期', 'warning');
|
||||
return;
|
||||
}
|
||||
if (startDate > endDate) {
|
||||
showToast('开始日期不能晚于结束日期', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
document.getElementById('reportRangeHint').textContent = `统计范围:${startDate} ~ ${endDate}`;
|
||||
|
||||
const [attendanceRes, homeworkRes] = await Promise.all([
|
||||
apiGet('/api/report/attendance', { start_date: startDate, end_date: endDate }),
|
||||
apiGet('/api/report/homework', { start_date: startDate, end_date: endDate })
|
||||
]);
|
||||
|
||||
if (attendanceRes && attendanceRes.success) {
|
||||
attendanceCache = attendanceRes.data;
|
||||
renderAttendance(attendanceRes.data);
|
||||
} else {
|
||||
showToast((attendanceRes && attendanceRes.message) || '考勤报表加载失败', 'error');
|
||||
}
|
||||
if (homeworkRes && homeworkRes.success) {
|
||||
homeworkCache = homeworkRes.data;
|
||||
renderHomework(homeworkRes.data);
|
||||
} else {
|
||||
showToast((homeworkRes && homeworkRes.message) || '作业报表加载失败', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
function rateText(rate) {
|
||||
return (rate === null || rate === undefined) ? '-' : rate + '%';
|
||||
}
|
||||
|
||||
function renderAttendance(data) {
|
||||
const rows = data.rows || [];
|
||||
const summary = data.summary || {};
|
||||
document.getElementById('attendanceSummary').textContent =
|
||||
`共 ${rows.length} 人,${summary.total || 0} 条记录:出勤 ${summary.present || 0}、缺勤 ${summary.absent || 0}、迟到 ${summary.late || 0}、请假 ${summary.leave || 0},出勤率 ${rateText(summary.rate)}`;
|
||||
|
||||
let html = '';
|
||||
rows.forEach((row, index) => {
|
||||
html += `<tr>
|
||||
<td>${index + 1}</td>
|
||||
<td>${escapeHtml(row.student_no)}</td>
|
||||
<td>${escapeHtml(row.name)}</td>
|
||||
<td class="plus">${row.present}</td>
|
||||
<td class="minus">${row.absent}</td>
|
||||
<td>${row.late}</td>
|
||||
<td>${row.leave}</td>
|
||||
<td>${row.total}</td>
|
||||
<td>${rateText(row.rate)}</td>
|
||||
</tr>`;
|
||||
});
|
||||
if (rows.length === 0) {
|
||||
html = '<tr><td colspan="9" style="text-align:center;">暂无数据</td></tr>';
|
||||
}
|
||||
document.getElementById('attendanceReportList').innerHTML = html;
|
||||
}
|
||||
|
||||
function renderHomework(data) {
|
||||
const rows = data.rows || [];
|
||||
const summary = data.summary || {};
|
||||
document.getElementById('homeworkSummary').textContent =
|
||||
`共 ${rows.length} 人,${summary.total || 0} 条记录:已交 ${summary.submitted || 0}、未交 ${summary.not_submitted || 0}、迟交 ${summary.late || 0},未交率 ${rateText(summary.miss_rate)}`;
|
||||
|
||||
let html = '';
|
||||
rows.forEach((row, index) => {
|
||||
html += `<tr>
|
||||
<td>${index + 1}</td>
|
||||
<td>${escapeHtml(row.student_no)}</td>
|
||||
<td>${escapeHtml(row.name)}</td>
|
||||
<td class="plus">${row.submitted}</td>
|
||||
<td class="minus">${row.not_submitted}</td>
|
||||
<td>${row.late}</td>
|
||||
<td>${row.total}</td>
|
||||
<td>${rateText(row.miss_rate)}</td>
|
||||
</tr>`;
|
||||
});
|
||||
if (rows.length === 0) {
|
||||
html = '<tr><td colspan="8" style="text-align:center;">暂无数据</td></tr>';
|
||||
}
|
||||
document.getElementById('homeworkReportList').innerHTML = html;
|
||||
}
|
||||
|
||||
function exportReport(type) {
|
||||
const data = type === 'attendance' ? attendanceCache : homeworkCache;
|
||||
if (!data || !data.rows || data.rows.length === 0) {
|
||||
showToast('请先查询报表数据', 'warning');
|
||||
return;
|
||||
}
|
||||
let csv = '';
|
||||
if (type === 'attendance') {
|
||||
csv += '序号,学号,姓名,出勤,缺勤,迟到,请假,记录数,出勤率(%)\n';
|
||||
data.rows.forEach((row, index) => {
|
||||
csv += [index + 1, row.student_no, row.name, row.present, row.absent, row.late, row.leave, row.total,
|
||||
(row.rate === null || row.rate === undefined) ? '' : row.rate].map(csvEscape).join(',') + '\n';
|
||||
});
|
||||
} else {
|
||||
csv += '序号,学号,姓名,已交,未交,迟交,记录数,未交率(%)\n';
|
||||
data.rows.forEach((row, index) => {
|
||||
csv += [index + 1, row.student_no, row.name, row.submitted, row.not_submitted, row.late, row.total,
|
||||
(row.miss_rate === null || row.miss_rate === undefined) ? '' : row.miss_rate].map(csvEscape).join(',') + '\n';
|
||||
});
|
||||
}
|
||||
const label = type === 'attendance' ? '考勤统计' : '作业统计';
|
||||
downloadCsv(`${label}_${data.start_date}_${data.end_date}.csv`, csv);
|
||||
showToast('导出成功,共' + data.rows.length + '人');
|
||||
}
|
||||
|
||||
initReportDates().then(loadReports);
|
||||
|
||||
window.loadReports = loadReports;
|
||||
window.exportReport = exportReport;
|
||||
|
||||
})();
|
||||
@@ -253,13 +253,33 @@ async function viewArchiveData(semesterId, semesterName, page) {
|
||||
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>
|
||||
@@ -270,7 +290,7 @@ async function viewArchiveData(semesterId, semesterName, page) {
|
||||
</tr>`;
|
||||
});
|
||||
if (archives.length === 0) {
|
||||
html = '<tr><td colspan="11" style="text-align:center;">暂无归档数据</td></tr>';
|
||||
html = '<tr><td colspan="13" style="text-align:center;">暂无归档数据</td></tr>';
|
||||
}
|
||||
document.getElementById('archiveDataList').innerHTML = html;
|
||||
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* 班级操行分管理系统 - 系统设置页JS
|
||||
*
|
||||
* 开发者: Canglan
|
||||
* 版权归属: Sea Network Technology Studio
|
||||
*
|
||||
* 版权所有 © Sea Network Technology Studio
|
||||
*/
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
async function loadPasswordPolicy() {
|
||||
const res = await apiGet('/api/admin/settings/password-policy');
|
||||
if (!res || !res.success) {
|
||||
showToast((res && res.message) || '获取密码策略失败', 'error');
|
||||
return;
|
||||
}
|
||||
document.getElementById('pwdMinLength').value = res.data.min_length;
|
||||
document.getElementById('pwdMaxLength').value = res.data.max_length;
|
||||
document.getElementById('pwdMinTypes').value = res.data.min_types;
|
||||
applyPolicyGlobals(res.data);
|
||||
}
|
||||
|
||||
function applyPolicyGlobals(policy) {
|
||||
window.PASSWORD_MIN_LENGTH = policy.min_length;
|
||||
window.PASSWORD_MAX_LENGTH = policy.max_length;
|
||||
window.PASSWORD_MIN_TYPES = policy.min_types;
|
||||
document.querySelectorAll('.pwd-policy').forEach(function(el) {
|
||||
el.textContent = describePasswordPolicy();
|
||||
});
|
||||
}
|
||||
|
||||
async function savePasswordPolicy() {
|
||||
const minLength = parseInt(document.getElementById('pwdMinLength').value);
|
||||
const maxLength = parseInt(document.getElementById('pwdMaxLength').value);
|
||||
const minTypes = parseInt(document.getElementById('pwdMinTypes').value);
|
||||
|
||||
if (isNaN(minLength) || isNaN(maxLength) || isNaN(minTypes)) {
|
||||
showToast('请填写完整的密码策略', 'warning');
|
||||
return;
|
||||
}
|
||||
if (minLength < 4 || minLength > 64) {
|
||||
showToast('最小长度需在4-64之间', 'warning');
|
||||
return;
|
||||
}
|
||||
if (maxLength < 8 || maxLength > 100) {
|
||||
showToast('最大长度需在8-100之间', 'warning');
|
||||
return;
|
||||
}
|
||||
if (minLength > maxLength) {
|
||||
showToast('最小长度不能大于最大长度', 'warning');
|
||||
return;
|
||||
}
|
||||
if (minTypes < 1 || minTypes > 4) {
|
||||
showToast('字符种类数需在1-4之间', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await apiPut('/api/admin/settings/password-policy', {
|
||||
min_length: minLength,
|
||||
max_length: maxLength,
|
||||
min_types: minTypes
|
||||
});
|
||||
if (res && res.success) {
|
||||
applyPolicyGlobals({ min_length: minLength, max_length: maxLength, min_types: minTypes });
|
||||
showToast(res.message || '密码策略已保存');
|
||||
} else {
|
||||
showToast((res && res.message) || '保存失败', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById('passwordPolicyForm').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
savePasswordPolicy();
|
||||
});
|
||||
|
||||
loadPasswordPolicy();
|
||||
|
||||
window.savePasswordPolicy = savePasswordPolicy;
|
||||
|
||||
})();
|
||||
Reference in new issue
Block a user