v4.0 权限组重构与导出/个人查询优化
1. 权限重构:自定义权限组(14项功能权限+允许加分/加分上限/允许扣分/扣分上限),管理员账号绑定权限组,预置六组且班主任组锁定;全站前后端改为权限驱动,权限变更60秒内自动生效 2. 新增班主任导出学生名单(导出前自选字段) 3. 加减分/考勤上限改为按权限组动态校验,弹窗实时提示并限制输入 4. 导出按学期隔离(默认当前学期,可选历史/全部),历史导出不再受1000条限制 5. 新增管理端个人查询:基础分/加分/扣分/月度分/月度理由汇总及明细导出 6. 版本升级至4.0(sql/upgrades/v4.0.sql)
This commit is contained in:
1 parent
3067542e53
commit
3588b4c28c
55 files changed
+2846
-801
No files matched your search
+72
-22
@@ -17,11 +17,8 @@ if (!isset($_SESSION['user_id']) || $_SESSION['user_type'] !== 'admin') {
|
||||
exit();
|
||||
}
|
||||
|
||||
$role = $_SESSION['role'] ?? '';
|
||||
if ($role !== '班主任') {
|
||||
header('Location: /admin/dashboard.php');
|
||||
exit();
|
||||
}
|
||||
$role = current_group_name();
|
||||
require_perm('manage_admins');
|
||||
|
||||
$page_title = '管理员管理';
|
||||
include __DIR__ . '/../includes/header.php';
|
||||
@@ -37,12 +34,26 @@ include __DIR__ . '/../includes/header.php';
|
||||
<div class="table-wrapper">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr><th>用户名</th><th>姓名</th><th>角色</th><th>状态</th><th>操作</th></tr>
|
||||
<tr><th>用户名</th><th>姓名</th><th>权限组</th><th>加减分上限</th><th>状态</th><th>操作</th></tr>
|
||||
</thead>
|
||||
<tbody id="adminList"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="action-bar">
|
||||
<button class="btn btn-primary" onclick="showAddGroupModal()">新建权限组</button>
|
||||
</div>
|
||||
<div class="table-wrapper">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr><th>权限组</th><th>权限项</th><th>加分</th><th>扣分</th><th>成员</th><th>说明</th><th>操作</th></tr>
|
||||
</thead>
|
||||
<tbody id="groupList"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 添加管理员模态框 -->
|
||||
@@ -67,14 +78,9 @@ include __DIR__ . '/../includes/header.php';
|
||||
<small>自动生成8位随机密码</small>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>角色</label>
|
||||
<select id="adminRole" required>
|
||||
<option value="">请选择角色</option>
|
||||
<option value='班长'>班长</option>
|
||||
<option value='学习委员'>学习委员</option>
|
||||
<option value='考勤委员'>考勤委员</option>
|
||||
<option value='劳动委员'>劳动委员</option>
|
||||
<option value='志愿委员'>志愿委员</option>
|
||||
<label>权限组</label>
|
||||
<select id="adminGroupId" required>
|
||||
<option value="">请选择权限组</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
@@ -103,14 +109,9 @@ include __DIR__ . '/../includes/header.php';
|
||||
<input type="text" id="editAdminRealName" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>角色</label>
|
||||
<select id="editAdminRole" required>
|
||||
<option value="">请选择角色</option>
|
||||
<option value='班长'>班长</option>
|
||||
<option value='学习委员'>学习委员</option>
|
||||
<option value='考勤委员'>考勤委员</option>
|
||||
<option value='劳动委员'>劳动委员</option>
|
||||
<option value='志愿委员'>志愿委员</option>
|
||||
<label>权限组</label>
|
||||
<select id="editAdminGroupId" required>
|
||||
<option value="">请选择权限组</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
@@ -121,6 +122,55 @@ include __DIR__ . '/../includes/header.php';
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 权限组模态框 -->
|
||||
<div id="groupModal" class="modal">
|
||||
<div class="modal-content" style="max-width: 640px;">
|
||||
<div class="modal-header">
|
||||
<h3 id="groupModalTitle">新建权限组</h3>
|
||||
<button class="modal-close" onclick="closeModal('groupModal')">×</button>
|
||||
</div>
|
||||
<form onsubmit="event.preventDefault(); submitGroupForm()">
|
||||
<input type="hidden" id="editGroupId">
|
||||
<div class="form-group">
|
||||
<label>权限组名称 <span style="color:red;">*</span></label>
|
||||
<input type="text" id="groupName" required maxlength="50" placeholder="如:纪律委员">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>说明</label>
|
||||
<input type="text" id="groupDescription" maxlength="255" placeholder="选填">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>权限项</label>
|
||||
<div id="groupPermissionList" style="display:grid; grid-template-columns: repeat(2, 1fr); gap:8px;"></div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>加减分上限</label>
|
||||
<div style="display:flex; flex-wrap:wrap; gap:16px; align-items:center;">
|
||||
<label style="display:flex; align-items:center; gap:6px;">
|
||||
<input type="checkbox" id="groupCanAdd" checked onchange="onGroupCapChange()"> 允许加分
|
||||
</label>
|
||||
<label style="display:flex; align-items:center; gap:6px;">
|
||||
单次加分上限
|
||||
<input type="number" id="groupMaxAdd" min="1" max="100" style="width:90px;" placeholder="留空=不限">
|
||||
</label>
|
||||
<label style="display:flex; align-items:center; gap:6px;">
|
||||
<input type="checkbox" id="groupCanSubtract" checked onchange="onGroupCapChange()"> 允许扣分
|
||||
</label>
|
||||
<label style="display:flex; align-items:center; gap:6px;">
|
||||
单次扣分上限
|
||||
<input type="number" id="groupMaxSubtract" min="1" max="100" style="width:90px;" placeholder="留空=不限">
|
||||
</label>
|
||||
</div>
|
||||
<small>上限必须在1-100之间,留空表示无限制</small>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" class="btn btn-primary">保存</button>
|
||||
<button type="button" class="btn" onclick="closeModal('groupModal')">取消</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 重置密码模态框 -->
|
||||
<div id="resetPasswordModal" class="modal">
|
||||
<div class="modal-content">
|
||||
|
||||
@@ -18,12 +18,8 @@ if (!isset($_SESSION['user_id']) || $_SESSION['user_type'] !== 'admin') {
|
||||
}
|
||||
|
||||
$page_title = '考勤管理';
|
||||
$role = $_SESSION['role'] ?? '';
|
||||
|
||||
if (!in_array($role, ['班主任', '考勤委员'])) {
|
||||
header('Location: /admin/dashboard.php');
|
||||
exit();
|
||||
}
|
||||
$role = current_group_name();
|
||||
require_perm('manage_attendance');
|
||||
|
||||
include __DIR__ . '/../includes/header.php';
|
||||
?>
|
||||
|
||||
+26
-18
@@ -18,12 +18,7 @@ if (!isset($_SESSION['user_id']) || $_SESSION['user_type'] !== 'admin') {
|
||||
}
|
||||
|
||||
$page_title = '操行分管理';
|
||||
$role = $_SESSION['role'] ?? '';
|
||||
|
||||
if (!in_array($role, ['班主任', '班长', '学习委员', '考勤委员', '劳动委员', '志愿委员'])) {
|
||||
header('Location: /admin/dashboard.php');
|
||||
exit();
|
||||
}
|
||||
$role = current_group_name();
|
||||
|
||||
include __DIR__ . '/../includes/header.php';
|
||||
?>
|
||||
@@ -34,10 +29,12 @@ include __DIR__ . '/../includes/header.php';
|
||||
<div class="card">
|
||||
<div class="action-bar">
|
||||
<div class="action-buttons">
|
||||
<?php if (has_perm('manage_conduct')): ?>
|
||||
<button class="btn btn-primary" onclick="showBatchPointsModal()">批量加减分</button>
|
||||
<button class="btn btn-secondary" onclick="showDormitoryPointsModal()">宿舍加分</button>
|
||||
<?php if ($role === '班主任'): ?>
|
||||
<button class="btn btn-secondary" onclick="exportMoralityRecords()">导出德育分记录</button>
|
||||
<?php endif; ?>
|
||||
<?php if (has_perm('export_data')): ?>
|
||||
<button class="btn btn-secondary" onclick="showExportMoralityModal()">导出德育分记录</button>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
@@ -59,6 +56,7 @@ include __DIR__ . '/../includes/header.php';
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>window.PAGE_CONFIG = { role: '<?php echo htmlspecialchars($role, ENT_QUOTES, 'UTF-8'); ?>' };</script>
|
||||
<script src="/assets/js/modules/modal-utils.js"></script>
|
||||
<script src="/assets/js/modules/utils.js"></script>
|
||||
<script src="/assets/js/modules/points-mgmt.js"></script>
|
||||
@@ -92,16 +90,7 @@ include __DIR__ . '/../includes/header.php';
|
||||
<div class="form-group">
|
||||
<label>分数变动</label>
|
||||
<input type="number" id="pointsChange" required placeholder="正数为加分,负数为扣分">
|
||||
<small><?php
|
||||
$hints = [
|
||||
'班长' => '班长单次±5分以内',
|
||||
'学习委员' => '学习委员单次±5分以内',
|
||||
'考勤委员' => '考勤委员仅限扣分,单次最多扣8分',
|
||||
'劳动委员' => '劳动委员单次±1分以内',
|
||||
'志愿委员' => '志愿委员仅限加分,最多+5分',
|
||||
];
|
||||
echo $hints[$role] ?? '班主任无限制';
|
||||
?></small>
|
||||
<small id="pointsLimitHint"></small>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>原因</label>
|
||||
@@ -115,6 +104,25 @@ include __DIR__ . '/../includes/header.php';
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 导出德育分记录模态框 -->
|
||||
<div id="exportMoralityModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h3>导出德育分记录</h3>
|
||||
<button class="modal-close" onclick="closeModal('exportMoralityModal')">×</button>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>学期范围</label>
|
||||
<select id="exportSemesterSelect"></select>
|
||||
<small>默认导出当前学期,避免混入以往学期的记录;可选择某个历史学期或全部学期。</small>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-primary" onclick="exportMoralityRecords()">开始导出</button>
|
||||
<button type="button" class="btn" onclick="closeModal('exportMoralityModal')">取消</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 宿舍集体加分模态框 -->
|
||||
<div id="dormitoryPointsModal" class="modal">
|
||||
<div class="modal-content">
|
||||
|
||||
@@ -52,7 +52,7 @@ include __DIR__ . '/../includes/header.php';
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($role === '班主任'): ?>
|
||||
<?php if (has_perm('manage_upgrade')): ?>
|
||||
<!-- 升级提示模态框 -->
|
||||
<div id="upgradeModal" class="modal" style="display:none;">
|
||||
<div class="modal-content" style="max-width:520px;">
|
||||
@@ -79,10 +79,10 @@ include __DIR__ . '/../includes/header.php';
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<script>window.PAGE_CONFIG = { role: '<?php echo $role; ?>' };</script>
|
||||
<script>window.PAGE_CONFIG = { role: '<?php echo htmlspecialchars($role, ENT_QUOTES, 'UTF-8'); ?>' };</script>
|
||||
<script src="/assets/js/dashboard.js"></script>
|
||||
|
||||
<?php if ($role === '班主任'): ?>
|
||||
<?php if (has_perm('manage_upgrade')): ?>
|
||||
<script>
|
||||
(function() {
|
||||
var upgradeSteps = [];
|
||||
|
||||
@@ -32,7 +32,13 @@ include __DIR__ . '/../includes/header.php';
|
||||
<label class="history-grouped-label">
|
||||
<input type="checkbox" id="historyGrouped" checked onchange="loadHistory(1)"> 批次合并
|
||||
</label>
|
||||
<?php if ($role === '班主任'): ?>
|
||||
<label class="history-grouped-label" style="display:flex; align-items:center; gap:6px;">
|
||||
学期
|
||||
<select id="historySemesterFilter" onchange="loadHistory(1)" style="padding:4px 8px; border:1px solid var(--color-border); border-radius:4px;">
|
||||
<option value="">全部学期</option>
|
||||
</select>
|
||||
</label>
|
||||
<?php if (has_perm('export_data')): ?>
|
||||
<button class="btn btn-secondary" onclick="exportHistoryRecords()">导出</button>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
@@ -76,7 +82,7 @@ include __DIR__ . '/../includes/header.php';
|
||||
<option value="志愿">志愿</option>
|
||||
</select>
|
||||
</div>
|
||||
<?php if ($role === '班主任' || $role === '班长'): ?>
|
||||
<?php if (has_perm('revoke_any') || has_perm('restore_records')): ?>
|
||||
<div class="filter-group">
|
||||
<label>状态</label>
|
||||
<select id="historyStatusFilter">
|
||||
@@ -99,7 +105,7 @@ include __DIR__ . '/../includes/header.php';
|
||||
<th>学生</th>
|
||||
<th style="white-space: nowrap; min-width: 80px;">操作人</th>
|
||||
<th>时间</th>
|
||||
<?php if ($role === '班主任' || $role === '班长' || $role === '考勤委员'): ?>
|
||||
<?php if (has_perm('revoke_any') || has_perm('revoke_own')): ?>
|
||||
<th>操作</th>
|
||||
<?php endif; ?>
|
||||
</tr>
|
||||
|
||||
@@ -18,12 +18,8 @@ if (!isset($_SESSION['user_id']) || $_SESSION['user_type'] !== 'admin') {
|
||||
}
|
||||
|
||||
$page_title = '作业扣分';
|
||||
$role = $_SESSION['role'] ?? '';
|
||||
|
||||
if (!in_array($role, ['班主任', '学习委员'])) {
|
||||
header('Location: /admin/dashboard.php');
|
||||
exit();
|
||||
}
|
||||
$role = current_group_name();
|
||||
require_perm('manage_homework');
|
||||
|
||||
include __DIR__ . '/../includes/header.php';
|
||||
?>
|
||||
@@ -31,6 +27,7 @@ include __DIR__ . '/../includes/header.php';
|
||||
<?php include __DIR__ . '/../includes/nav.php'; ?>
|
||||
|
||||
<div class="container">
|
||||
<?php if (has_perm('manage_subjects')): ?>
|
||||
<!-- 科目管理折叠面板 -->
|
||||
<div class="card collapsible-card" style="margin-bottom: 20px;">
|
||||
<div class="collapsible-header" id="subjectPanelHeader">
|
||||
@@ -44,6 +41,7 @@ include __DIR__ . '/../includes/header.php';
|
||||
<div id="subjectList" class="subject-list"></div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="card">
|
||||
<div class="action-bar">
|
||||
@@ -79,14 +77,12 @@ include __DIR__ . '/../includes/header.php';
|
||||
<label>已选学生</label>
|
||||
<div id="selectedStudentsCount" class="selected-info">未选择学生</div>
|
||||
</div>
|
||||
<?php if (in_array($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" style="display: flex; flex-wrap: wrap; gap: 6px;">
|
||||
@@ -98,7 +94,6 @@ include __DIR__ . '/../includes/header.php';
|
||||
<button type="button" class="btn btn-sm" onclick="selectDeductionType(0, '')">自定义</button>
|
||||
</div>
|
||||
</div>
|
||||
<?php if (in_array($role, ['班主任', '学习委员'])): ?>
|
||||
<div class="form-group">
|
||||
<label>具体作业</label>
|
||||
<input type="text" id="hwTitle" placeholder="选填,如:第三章练习">
|
||||
@@ -107,14 +102,10 @@ include __DIR__ . '/../includes/header.php';
|
||||
<label>缴交时间</label>
|
||||
<input type="date" id="hwDeadline" value="<?php echo date('Y-m-d'); ?>">
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="form-group">
|
||||
<label>分数变动</label>
|
||||
<input type="number" id="pointsChange" required min="-5" max="5" step="1" placeholder="正数加分,负数扣分">
|
||||
<small><?php
|
||||
if ($role === '学习委员') echo '学习委员单次±5分以内';
|
||||
else echo '班主任无限制';
|
||||
?></small>
|
||||
<input type="number" id="pointsChange" required step="1" placeholder="正数加分,负数扣分">
|
||||
<small class="hw-max"></small>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>原因</label>
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
/**
|
||||
* 班级操行分管理系统 - 管理端个人记录查询
|
||||
*
|
||||
* 开发者: Canglan
|
||||
* 联系方式: admin@sea-studio.top
|
||||
* 版权归属: Sea Network Technology Studio
|
||||
* 许可证: MIT License
|
||||
*
|
||||
* 版权所有 © Sea Network Technology Studio
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../config.php';
|
||||
|
||||
if (!isset($_SESSION['user_id']) || $_SESSION['user_type'] !== 'admin') {
|
||||
header('Location: /index.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
$page_title = '个人查询';
|
||||
$role = current_group_name();
|
||||
require_perm('view_all_records');
|
||||
|
||||
include __DIR__ . '/../includes/header.php';
|
||||
?>
|
||||
|
||||
<?php include __DIR__ . '/../includes/nav.php'; ?>
|
||||
|
||||
<div class="container">
|
||||
<div class="card">
|
||||
<div class="filter-bar">
|
||||
<div class="filter-group" style="min-width: 220px;">
|
||||
<label>学生</label>
|
||||
<select id="queryStudentId" onchange="onQueryStudentChange()">
|
||||
<option value="">-- 请选择学生 --</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="filter-group">
|
||||
<label>学期</label>
|
||||
<select id="querySemesterId" onchange="onQuerySemesterChange()"></select>
|
||||
</div>
|
||||
<div class="filter-group" style="flex: 0 0 auto;">
|
||||
<button class="btn btn-primary" onclick="queryStudentRecords(1)">查询</button>
|
||||
</div>
|
||||
<div class="filter-group" style="flex: 0 0 auto;">
|
||||
<button class="btn btn-secondary" onclick="exportStudentRecords()">导出个人记录</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="queryPlaceholder" style="text-align: center; color: var(--color-text-secondary); padding: 32px 0;">
|
||||
请选择学生后点击“查询”,查看基础分、加分、月度分及月度加减分理由汇总
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="queryResult" style="display: none;">
|
||||
<div class="card">
|
||||
<div class="card-title" id="queryStudentTitle">学生汇总</div>
|
||||
<div class="stats-grid" id="querySummaryCards"></div>
|
||||
<div id="querySummaryHint" style="font-size: 12px; color: var(--color-text-secondary);"></div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-title">月度操行分</div>
|
||||
<div class="table-wrapper">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>月份</th>
|
||||
<th>月初分</th>
|
||||
<th>加分</th>
|
||||
<th>减分</th>
|
||||
<th>月末分</th>
|
||||
<th>记录数</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="queryMonthlyList"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-title">月度加减分理由汇总</div>
|
||||
<div id="queryReasonSummary"></div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-title">明细记录</div>
|
||||
<div class="table-wrapper">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>类型</th>
|
||||
<th>分值</th>
|
||||
<th>原因</th>
|
||||
<th>操作人</th>
|
||||
<th style="white-space: nowrap;">时间</th>
|
||||
<?php if (has_perm('revoke_any') || has_perm('revoke_own')): ?>
|
||||
<th>状态/操作</th>
|
||||
<?php endif; ?>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="queryRecordList"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="pagination" id="queryPagination"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>window.PAGE_CONFIG = { role: '<?php echo htmlspecialchars($role, ENT_QUOTES, 'UTF-8'); ?>', userId: <?php echo intval($_SESSION['user_id']); ?> };</script>
|
||||
<script src="/assets/js/modules/modal-utils.js"></script>
|
||||
<script src="/assets/js/modules/utils.js"></script>
|
||||
<script src="/assets/js/record-query.js"></script>
|
||||
|
||||
<?php include __DIR__ . '/../includes/footer.php'; ?>
|
||||
@@ -17,11 +17,8 @@ if (!isset($_SESSION['user_id']) || $_SESSION['user_type'] !== 'admin') {
|
||||
exit();
|
||||
}
|
||||
|
||||
$role = $_SESSION['role'] ?? '';
|
||||
if ($role !== '班主任') {
|
||||
header('Location: /admin/dashboard.php');
|
||||
exit();
|
||||
}
|
||||
$role = current_group_name();
|
||||
require_perm('manage_semesters');
|
||||
|
||||
$page_title = '学期管理';
|
||||
include __DIR__ . '/../includes/header.php';
|
||||
|
||||
+36
-14
@@ -18,7 +18,7 @@ if (!isset($_SESSION['user_id']) || $_SESSION['user_type'] !== 'admin') {
|
||||
}
|
||||
|
||||
$page_title = '学生管理';
|
||||
$role = $_SESSION['role'] ?? '';
|
||||
$role = current_group_name();
|
||||
include __DIR__ . '/../includes/header.php';
|
||||
?>
|
||||
|
||||
@@ -28,10 +28,13 @@ include __DIR__ . '/../includes/header.php';
|
||||
<div class="card">
|
||||
<div class="action-bar">
|
||||
<div class="action-buttons">
|
||||
<?php if ($role === '班主任'): ?>
|
||||
<?php if (has_perm('manage_students')): ?>
|
||||
<button class="btn btn-primary" onclick="showImportModal()">导入学生</button>
|
||||
<button class="btn btn-primary" onclick="showAddStudentModal()">新增学生</button>
|
||||
<?php endif; ?>
|
||||
<?php if (has_perm('export_students')): ?>
|
||||
<button class="btn btn-secondary" onclick="showExportStudentsModal()">导出学生名单</button>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="search-bar">
|
||||
<input type="text" id="searchInput" placeholder="搜索姓名/学号">
|
||||
@@ -48,7 +51,7 @@ include __DIR__ . '/../includes/header.php';
|
||||
<th>姓名</th>
|
||||
<th>宿舍号</th>
|
||||
<th>操行分</th>
|
||||
<?php if ($role === '班主任'): ?><th>家长手机号</th><?php endif; ?>
|
||||
<?php if (has_perm('manage_students')): ?><th>家长手机号</th><?php endif; ?>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -170,13 +173,41 @@ include __DIR__ . '/../includes/header.php';
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>window.PAGE_CONFIG = { role: '<?php echo $role; ?>' };</script>
|
||||
<script>window.PAGE_CONFIG = { role: '<?php echo htmlspecialchars($role, ENT_QUOTES, 'UTF-8'); ?>' };</script>
|
||||
<script src="/assets/js/modules/modal-utils.js"></script>
|
||||
<script src="/assets/js/modules/utils.js"></script>
|
||||
<script src="/assets/js/modules/student-mgmt.js"></script>
|
||||
<script src="/assets/js/modules/points-mgmt.js"></script>
|
||||
<script src="/assets/js/students-manage.js"></script>
|
||||
|
||||
<!-- 导出学生名单模态框 -->
|
||||
<div id="exportStudentsModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h3>导出学生名单</h3>
|
||||
<button class="modal-close" onclick="closeModal('exportStudentsModal')">×</button>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>导出字段</label>
|
||||
<div style="display:grid; grid-template-columns: repeat(2, 1fr); gap:8px;">
|
||||
<label><input type="checkbox" class="export-student-col" value="student_no" checked disabled> 学号</label>
|
||||
<label><input type="checkbox" class="export-student-col" value="name" checked disabled> 姓名</label>
|
||||
<label><input type="checkbox" class="export-student-col" value="dormitory_number" checked> 宿舍号</label>
|
||||
<label><input type="checkbox" class="export-student-col" value="total_points" checked> 当前操行分</label>
|
||||
<?php if (has_perm('manage_students')): ?>
|
||||
<label><input type="checkbox" class="export-student-col" value="parent_phone"> 家长手机号</label>
|
||||
<?php endif; ?>
|
||||
<label><input type="checkbox" class="export-student-col" value="status" checked> 状态</label>
|
||||
</div>
|
||||
<small>导出全班学生名单(CSV,可用Excel打开)</small>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-primary" onclick="exportStudents()">开始导出</button>
|
||||
<button type="button" class="btn" onclick="closeModal('exportStudentsModal')">取消</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 批量加减分模态框(共用) -->
|
||||
<div id="batchPointsModal" class="modal">
|
||||
<div class="modal-content">
|
||||
@@ -192,16 +223,7 @@ include __DIR__ . '/../includes/header.php';
|
||||
<div class="form-group">
|
||||
<label>分数变动</label>
|
||||
<input type="number" id="pointsChange" required placeholder="正数为加分,负数为扣分">
|
||||
<small><?php
|
||||
$hints = [
|
||||
'班长' => '班长单次±5分以内',
|
||||
'学习委员' => '学习委员单次±5分以内',
|
||||
'考勤委员' => '考勤委员仅限扣分,单次最多扣8分',
|
||||
'劳动委员' => '劳动委员单次±1分以内',
|
||||
'志愿委员' => '志愿委员仅限加分,最多+5分',
|
||||
];
|
||||
echo $hints[$role] ?? '班主任无限制';
|
||||
?></small>
|
||||
<small id="pointsLimitHint"></small>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>原因</label>
|
||||
|
||||
@@ -13,8 +13,8 @@ if (!isset($_SESSION['user_id']) || $_SESSION['user_type'] !== 'admin') {
|
||||
exit();
|
||||
}
|
||||
|
||||
$role = $_SESSION['role'] ?? '';
|
||||
if ($role !== '班主任') {
|
||||
$role = current_group_name();
|
||||
if (!has_perm('manage_upgrade')) {
|
||||
echo json_encode(['needs_upgrade' => false]);
|
||||
exit();
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@ if (!isset($_SESSION['user_id']) || $_SESSION['user_type'] !== 'admin') {
|
||||
exit();
|
||||
}
|
||||
|
||||
$role = $_SESSION['role'] ?? '';
|
||||
if ($role !== '班主任') {
|
||||
$role = current_group_name();
|
||||
if (!has_perm('manage_upgrade')) {
|
||||
http_response_code(403);
|
||||
echo json_encode(['success' => false, 'error' => '权限不足']);
|
||||
exit();
|
||||
|
||||
@@ -153,12 +153,16 @@ if ($tokenUserId === null || intval($tokenUserId) !== intval($data['user_id']))
|
||||
exit();
|
||||
}
|
||||
|
||||
// 设置 Session 变量
|
||||
$_SESSION['user_id'] = $data['user_id'];
|
||||
$_SESSION['user_type'] = $data['user_type'];
|
||||
$_SESSION['username'] = $data['username'];
|
||||
$_SESSION['real_name'] = $data['real_name'] ?? '';
|
||||
$_SESSION['role'] = $data['role'] ?? '';
|
||||
// 设置 Session 变量(权限组与权限以后端返回为准,避免客户端伪造)
|
||||
$apiUser = $tokenData['data'] ?? [];
|
||||
$_SESSION['user_id'] = $apiUser['user_id'] ?? $data['user_id'];
|
||||
$_SESSION['user_type'] = $apiUser['user_type'] ?? $data['user_type'];
|
||||
$_SESSION['username'] = $apiUser['username'] ?? $data['username'];
|
||||
$_SESSION['real_name'] = $apiUser['real_name'] ?? ($data['real_name'] ?? '');
|
||||
$_SESSION['role'] = $apiUser['role'] ?? '';
|
||||
$_SESSION['permissions'] = is_array($apiUser['permissions'] ?? null) ? $apiUser['permissions'] : [];
|
||||
$_SESSION['group'] = $apiUser['group'] ?? null;
|
||||
$_SESSION['permissions_synced_at'] = time();
|
||||
$_SESSION['login_time'] = time();
|
||||
$_SESSION['jwt_token'] = $token;
|
||||
|
||||
|
||||
@@ -746,6 +746,15 @@ tr:hover {
|
||||
color: var(--color-danger);
|
||||
}
|
||||
|
||||
/* 分值颜色(表格/统计卡片通用) */
|
||||
.plus {
|
||||
color: var(--color-success);
|
||||
}
|
||||
|
||||
.minus {
|
||||
color: var(--color-danger);
|
||||
}
|
||||
|
||||
.record-reason {
|
||||
flex: 1;
|
||||
margin: 0 15px;
|
||||
|
||||
+229
-10
@@ -10,8 +10,99 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
const PERMISSION_LABELS = {
|
||||
manage_students: '学生管理',
|
||||
export_students: '导出学生名单',
|
||||
manage_conduct: '操行分加减',
|
||||
revoke_any: '撤销任何记录',
|
||||
revoke_own: '撤销自己的记录',
|
||||
restore_records: '反撤销记录',
|
||||
manage_homework: '作业扣分',
|
||||
manage_attendance: '考勤管理',
|
||||
manage_subjects: '科目管理',
|
||||
manage_admins: '管理员/权限组管理',
|
||||
manage_semesters: '学期管理',
|
||||
view_all_records: '查看全班/个人查询',
|
||||
export_data: '导出德育分/历史',
|
||||
manage_upgrade: '系统升级'
|
||||
};
|
||||
|
||||
let currentEditUserId = null;
|
||||
let currentResetUserId = null;
|
||||
let groupsCache = [];
|
||||
|
||||
function groupCapsText(group) {
|
||||
const add = group.can_add_points
|
||||
? (group.max_add_points ? ('+' + group.max_add_points + '以内') : '不限')
|
||||
: '禁止';
|
||||
const subtract = group.can_subtract_points
|
||||
? (group.max_subtract_points ? ('-' + group.max_subtract_points + '以内') : '不限')
|
||||
: '禁止';
|
||||
return { add: add, subtract: subtract };
|
||||
}
|
||||
|
||||
function permissionSummary(group) {
|
||||
const permissions = group.permissions_data || {};
|
||||
const names = Object.keys(PERMISSION_LABELS)
|
||||
.filter(key => permissions[key])
|
||||
.map(key => PERMISSION_LABELS[key]);
|
||||
return names.length ? names.join('、') : '无';
|
||||
}
|
||||
|
||||
async function loadGroups() {
|
||||
const res = await apiGet('/api/admin/permission-groups');
|
||||
if (!res || !res.success) {
|
||||
showToast((res && res.message) || '获取权限组失败', 'error');
|
||||
return;
|
||||
}
|
||||
groupsCache = res.data.groups || [];
|
||||
|
||||
const options = groupsCache
|
||||
.filter(group => !group.is_locked)
|
||||
.map(group => `<option value="${group.group_id}">${escapeHtml(group.group_name)}</option>`)
|
||||
.join('');
|
||||
const placeholder = '<option value="">请选择权限组</option>';
|
||||
document.getElementById('adminGroupId').innerHTML = placeholder + options;
|
||||
document.getElementById('editAdminGroupId').innerHTML = placeholder + options;
|
||||
|
||||
renderGroupTable();
|
||||
}
|
||||
|
||||
function renderGroupTable() {
|
||||
let html = '';
|
||||
groupsCache.forEach(group => {
|
||||
const caps = groupCapsText(group);
|
||||
const badges = [];
|
||||
if (group.is_locked) {
|
||||
badges.push('<span class="subject-status subject-status-active">锁定</span>');
|
||||
} else if (group.is_system) {
|
||||
badges.push('<span class="subject-status">预置</span>');
|
||||
}
|
||||
let actions = '<span class="text-muted">-</span>';
|
||||
if (!group.is_locked) {
|
||||
const deleteItem = group.is_system
|
||||
? ''
|
||||
: `<a class="danger" onclick="deleteGroup(${group.group_id}, '${escapeHtml(group.group_name)}')">删除</a>`;
|
||||
actions = `<div class="action-dropdown">
|
||||
<button class="btn btn-sm action-dropdown-toggle" onclick="toggleActionDropdown(this)">操作 ▼</button>
|
||||
<div class="action-dropdown-menu">
|
||||
<a onclick="showEditGroupModal(${group.group_id})">编辑</a>
|
||||
${deleteItem}
|
||||
</div>
|
||||
</div>`;
|
||||
}
|
||||
html += `<tr>
|
||||
<td>${escapeHtml(group.group_name)} ${badges.join(' ')}</td>
|
||||
<td style="max-width: 340px; white-space: normal;">${escapeHtml(permissionSummary(group))}</td>
|
||||
<td>${caps.add}</td>
|
||||
<td>${caps.subtract}</td>
|
||||
<td>${group.member_count || 0}</td>
|
||||
<td>${escapeHtml(group.description || '-')}</td>
|
||||
<td>${actions}</td>
|
||||
</tr>`;
|
||||
});
|
||||
document.getElementById('groupList').innerHTML = html || '<tr><td colspan="7" style="text-align:center;">暂无权限组</td></tr>';
|
||||
}
|
||||
|
||||
async function loadAdmins() {
|
||||
const res = await apiGet('/api/admin/list');
|
||||
@@ -21,16 +112,25 @@ async function loadAdmins() {
|
||||
const isActive = admin.status === 1;
|
||||
const statusClass = isActive ? 'subject-status-active' : 'subject-status-inactive';
|
||||
const statusText = isActive ? '启用' : '禁用';
|
||||
const caps = {
|
||||
add: admin.can_add_points ? (admin.max_add_points ? ('+' + admin.max_add_points + '以内') : '不限') : '禁止',
|
||||
subtract: admin.can_subtract_points ? (admin.max_subtract_points ? ('-' + admin.max_subtract_points + '以内') : '不限') : '禁止'
|
||||
};
|
||||
const canEdit = !admin.is_locked && admin.group_id;
|
||||
const editItem = canEdit
|
||||
? `<a onclick="showEditAdminModal(${admin.user_id}, '${escapeHtml(admin.username)}', '${escapeHtml(admin.real_name)}', ${admin.group_id})">编辑</a>`
|
||||
: '';
|
||||
html += `<tr>
|
||||
<td>${escapeHtml(admin.username)}</td>
|
||||
<td>${escapeHtml(admin.real_name)}</td>
|
||||
<td>${escapeHtml(admin.role_type)}</td>
|
||||
<td>${escapeHtml(admin.group_name || admin.role_type || '-')}${admin.is_locked ? ' <span class="subject-status subject-status-active">锁定</span>' : ''}</td>
|
||||
<td>加${caps.add} / 扣${caps.subtract}</td>
|
||||
<td><span class="subject-status ${statusClass}">${statusText}</span></td>
|
||||
<td>
|
||||
<div class="action-dropdown">
|
||||
<button class="btn btn-sm action-dropdown-toggle" onclick="toggleActionDropdown(this)">操作 ▼</button>
|
||||
<div class="action-dropdown-menu">
|
||||
<a onclick="showEditAdminModal(${admin.user_id}, '${escapeHtml(admin.username)}', '${escapeHtml(admin.real_name)}', '${escapeHtml(admin.role_type)}')">编辑</a>
|
||||
${editItem}
|
||||
<a onclick="resetAdminPassword(${admin.user_id}, '${escapeHtml(admin.real_name)}')">重置密码</a>
|
||||
<a onclick="unlockUser('${escapeHtml(admin.username)}', '${escapeHtml(admin.real_name)}')">解锁</a>
|
||||
<a class="${isActive ? 'danger' : ''}" onclick="toggleAdminStatus(${admin.user_id}, '${escapeHtml(admin.real_name)}', ${isActive ? 1 : 0})">${isActive ? '禁用' : '启用'}</a>
|
||||
@@ -40,33 +140,33 @@ async function loadAdmins() {
|
||||
</tr>`;
|
||||
});
|
||||
if (res.data.admins.length === 0) {
|
||||
html = '<tr><td colspan="5" style="text-align:center;">暂无管理员</td></tr>';
|
||||
html = '<tr><td colspan="6" style="text-align:center;">暂无管理员</td></tr>';
|
||||
}
|
||||
document.getElementById('adminList').innerHTML = html;
|
||||
}
|
||||
}
|
||||
|
||||
function showEditAdminModal(userId, username, realName, roleType) {
|
||||
function showEditAdminModal(userId, username, realName, groupId) {
|
||||
currentEditUserId = userId;
|
||||
document.getElementById('editAdminUserId').value = userId;
|
||||
document.getElementById('editAdminUsername').value = username;
|
||||
document.getElementById('editAdminRealName').value = realName;
|
||||
document.getElementById('editAdminRole').value = roleType;
|
||||
document.getElementById('editAdminGroupId').value = groupId || '';
|
||||
document.getElementById('editAdminModal').style.display = 'flex';
|
||||
}
|
||||
|
||||
async function submitEditAdmin() {
|
||||
if (!currentEditUserId) return;
|
||||
|
||||
const roleType = document.getElementById('editAdminRole').value;
|
||||
if (!roleType) {
|
||||
showToast('请选择角色', 'warning');
|
||||
const groupId = parseInt(document.getElementById('editAdminGroupId').value);
|
||||
if (!groupId) {
|
||||
showToast('请选择权限组', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await apiPut(`/api/admin/update/${currentEditUserId}`, {
|
||||
real_name: document.getElementById('editAdminRealName').value,
|
||||
role_type: roleType
|
||||
real_name: document.getElementById('editAdminRealName').value.trim(),
|
||||
group_id: groupId
|
||||
});
|
||||
|
||||
if (res && res.success) {
|
||||
@@ -141,14 +241,133 @@ async function submitResetPassword() {
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 权限组管理 ==========
|
||||
|
||||
function renderPermissionCheckboxes(permissions) {
|
||||
const container = document.getElementById('groupPermissionList');
|
||||
container.innerHTML = Object.keys(PERMISSION_LABELS).map(key =>
|
||||
`<label style="display:flex; align-items:center; gap:6px;">
|
||||
<input type="checkbox" class="group-perm" value="${key}"${permissions[key] ? ' checked' : ''}> ${PERMISSION_LABELS[key]}
|
||||
</label>`
|
||||
).join('');
|
||||
}
|
||||
|
||||
function onGroupCapChange() {
|
||||
const canAdd = document.getElementById('groupCanAdd').checked;
|
||||
const canSubtract = document.getElementById('groupCanSubtract').checked;
|
||||
document.getElementById('groupMaxAdd').disabled = !canAdd;
|
||||
document.getElementById('groupMaxSubtract').disabled = !canSubtract;
|
||||
if (!canAdd) document.getElementById('groupMaxAdd').value = '';
|
||||
if (!canSubtract) document.getElementById('groupMaxSubtract').value = '';
|
||||
}
|
||||
|
||||
function showAddGroupModal() {
|
||||
document.getElementById('groupModalTitle').textContent = '新建权限组';
|
||||
document.getElementById('editGroupId').value = '';
|
||||
document.getElementById('groupName').value = '';
|
||||
document.getElementById('groupDescription').value = '';
|
||||
document.getElementById('groupCanAdd').checked = true;
|
||||
document.getElementById('groupCanSubtract').checked = true;
|
||||
document.getElementById('groupMaxAdd').value = '';
|
||||
document.getElementById('groupMaxSubtract').value = '';
|
||||
renderPermissionCheckboxes({});
|
||||
onGroupCapChange();
|
||||
document.getElementById('groupModal').style.display = 'flex';
|
||||
}
|
||||
|
||||
function showEditGroupModal(groupId) {
|
||||
const group = groupsCache.find(item => item.group_id === groupId);
|
||||
if (!group) return;
|
||||
if (group.is_locked) {
|
||||
showToast('该权限组已锁定,不可编辑', 'warning');
|
||||
return;
|
||||
}
|
||||
document.getElementById('groupModalTitle').textContent = '编辑权限组 - ' + group.group_name;
|
||||
document.getElementById('editGroupId').value = group.group_id;
|
||||
document.getElementById('groupName').value = group.group_name;
|
||||
document.getElementById('groupDescription').value = group.description || '';
|
||||
document.getElementById('groupCanAdd').checked = !!group.can_add_points;
|
||||
document.getElementById('groupCanSubtract').checked = !!group.can_subtract_points;
|
||||
document.getElementById('groupMaxAdd').value = group.max_add_points || '';
|
||||
document.getElementById('groupMaxSubtract').value = group.max_subtract_points || '';
|
||||
renderPermissionCheckboxes(group.permissions_data || {});
|
||||
onGroupCapChange();
|
||||
document.getElementById('groupModal').style.display = 'flex';
|
||||
}
|
||||
|
||||
async function submitGroupForm() {
|
||||
const groupId = document.getElementById('editGroupId').value;
|
||||
const canAdd = document.getElementById('groupCanAdd').checked;
|
||||
const canSubtract = document.getElementById('groupCanSubtract').checked;
|
||||
const maxAddRaw = document.getElementById('groupMaxAdd').value;
|
||||
const maxSubtractRaw = document.getElementById('groupMaxSubtract').value;
|
||||
const maxAdd = canAdd && maxAddRaw !== '' ? parseInt(maxAddRaw) : null;
|
||||
const maxSubtract = canSubtract && maxSubtractRaw !== '' ? parseInt(maxSubtractRaw) : null;
|
||||
|
||||
if (maxAdd !== null && (isNaN(maxAdd) || maxAdd < 1 || maxAdd > 100)) {
|
||||
showToast('加分上限必须在1-100之间', 'warning');
|
||||
return;
|
||||
}
|
||||
if (maxSubtract !== null && (isNaN(maxSubtract) || maxSubtract < 1 || maxSubtract > 100)) {
|
||||
showToast('扣分上限必须在1-100之间', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
const payload = {
|
||||
group_name: document.getElementById('groupName').value.trim(),
|
||||
description: document.getElementById('groupDescription').value.trim() || null,
|
||||
permissions: Array.from(document.querySelectorAll('.group-perm:checked')).map(el => el.value),
|
||||
can_add_points: canAdd,
|
||||
max_add_points: maxAdd,
|
||||
can_subtract_points: canSubtract,
|
||||
max_subtract_points: maxSubtract
|
||||
};
|
||||
if (!payload.group_name) {
|
||||
showToast('请填写权限组名称', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
const res = groupId
|
||||
? await apiPut(`/api/admin/permission-groups/${groupId}`, payload)
|
||||
: await apiPost('/api/admin/permission-groups', payload);
|
||||
|
||||
if (res && res.success) {
|
||||
showToast(groupId ? '权限组更新成功' : '权限组创建成功');
|
||||
closeModal('groupModal');
|
||||
loadGroups();
|
||||
} else {
|
||||
showToast(res?.message || '保存失败', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteGroup(groupId, groupName) {
|
||||
if (!confirm(`确定要删除权限组 "${groupName}" 吗?删除后不可恢复。`)) {
|
||||
return;
|
||||
}
|
||||
const res = await apiDelete(`/api/admin/permission-groups/${groupId}`);
|
||||
if (res && res.success) {
|
||||
showToast('权限组已删除');
|
||||
loadGroups();
|
||||
} else {
|
||||
showToast(res?.message || '删除失败', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
loadGroups();
|
||||
loadAdmins();
|
||||
|
||||
window.loadAdmins = loadAdmins;
|
||||
window.loadGroups = loadGroups;
|
||||
window.showEditAdminModal = showEditAdminModal;
|
||||
window.submitEditAdmin = submitEditAdmin;
|
||||
window.toggleAdminStatus = toggleAdminStatus;
|
||||
window.resetAdminPassword = resetAdminPassword;
|
||||
window.unlockUser = unlockUser;
|
||||
window.submitResetPassword = submitResetPassword;
|
||||
window.showAddGroupModal = showAddGroupModal;
|
||||
window.showEditGroupModal = showEditGroupModal;
|
||||
window.submitGroupForm = submitGroupForm;
|
||||
window.deleteGroup = deleteGroup;
|
||||
window.onGroupCapChange = onGroupCapChange;
|
||||
|
||||
})();
|
||||
@@ -32,6 +32,17 @@ function initAttendanceButtons() {
|
||||
if (attendanceDeductionMap.absent > 0) {
|
||||
document.getElementById('customDeduction').value = attendanceDeductionMap.absent;
|
||||
}
|
||||
// 按权限组动态扣分上限限制自定义扣分输入
|
||||
const limits = getScoreLimits();
|
||||
const deductionInput = document.getElementById('customDeduction');
|
||||
if (deductionInput) {
|
||||
if (limits.max_subtract !== null && limits.max_subtract !== undefined) {
|
||||
deductionInput.max = limits.max_subtract;
|
||||
}
|
||||
if (!limits.can_subtract) {
|
||||
deductionInput.disabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function selectStatus(btn) {
|
||||
|
||||
@@ -112,6 +112,161 @@ function apiDelete(url) {
|
||||
return apiRequest(url, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页拉取接口全部记录(用于导出等需要完整数据的场景)
|
||||
* @param {string} url 接口地址
|
||||
* @param {object} params 查询参数(page/page_size 会被自动覆盖)
|
||||
* @returns {Promise<Array>} 全部记录
|
||||
*/
|
||||
async function apiGetAll(url, params = {}) {
|
||||
const allRecords = [];
|
||||
const pageSize = 1000;
|
||||
let page = 1;
|
||||
while (page <= 100) {
|
||||
const pageParams = { ...params, page: page, page_size: pageSize };
|
||||
const res = await apiGet(url, pageParams);
|
||||
if (!res || !res.success || !res.data || !Array.isArray(res.data.records)) {
|
||||
break;
|
||||
}
|
||||
allRecords.push(...res.data.records);
|
||||
const total = res.data.total || 0;
|
||||
if (allRecords.length >= total || res.data.records.length < pageSize) {
|
||||
break;
|
||||
}
|
||||
page++;
|
||||
}
|
||||
return allRecords;
|
||||
}
|
||||
|
||||
/**
|
||||
* CSV字段转义
|
||||
*/
|
||||
function csvEscape(value) {
|
||||
if (value === null || value === undefined) return '';
|
||||
let str = String(value).replace(/[\r\n]+/g, ' ');
|
||||
str = str.replace(/"/g, '""');
|
||||
if (/[\,\;\"\s]/.test(str)) {
|
||||
str = '"' + str + '"';
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载CSV文件(自动添加BOM以兼容Excel)
|
||||
*/
|
||||
function downloadCsv(filename, csvContent) {
|
||||
const blob = new Blob(['\uFEFF' + csvContent], { type: 'text/csv;charset=utf-8;' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = filename;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载学期下拉选项
|
||||
* @param {string|HTMLElement} select 下拉框DOM或ID
|
||||
* @param {object} options { includeAll: 是否包含"全部学期", selectedValue: 默认选中值 }
|
||||
* @returns {Promise<Array>} 学期列表
|
||||
*/
|
||||
async function loadSemesterOptions(select, options = {}) {
|
||||
const el = typeof select === 'string' ? document.getElementById(select) : select;
|
||||
if (!el) return [];
|
||||
const res = await apiGet('/api/semester/options');
|
||||
const semesters = (res && res.success && Array.isArray(res.data)) ? res.data : [];
|
||||
const sorted = semesters.slice().sort((a, b) => (b.is_active ? 1 : 0) - (a.is_active ? 1 : 0));
|
||||
const includeAll = options.includeAll !== false;
|
||||
let html = includeAll ? '<option value="">全部学期</option>' : '';
|
||||
sorted.forEach(s => {
|
||||
const suffix = s.is_active ? '(当前)' : (s.is_archived ? '(已归档)' : '');
|
||||
html += '<option value="' + s.semester_id + '">' + escapeHtml(s.semester_name + suffix) + '</option>';
|
||||
});
|
||||
el.innerHTML = html;
|
||||
let value = options.selectedValue;
|
||||
if (value === undefined) {
|
||||
const active = sorted.find(s => s.is_active);
|
||||
value = active ? active.semester_id : '';
|
||||
}
|
||||
el.value = (value === null || value === undefined) ? '' : String(value);
|
||||
return semesters;
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前用户是否拥有指定权限
|
||||
*/
|
||||
function hasPermission(perm) {
|
||||
return !!(window.USER_PERMISSIONS && window.USER_PERMISSIONS[perm]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前权限组加减分上限配置
|
||||
*/
|
||||
function getScoreLimits() {
|
||||
return window.USER_SCORE_LIMITS || {
|
||||
can_add: true, max_add: null,
|
||||
can_subtract: true, max_subtract: null
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成加减分上限提示文本
|
||||
*/
|
||||
function describeScoreLimits() {
|
||||
const limits = getScoreLimits();
|
||||
if (!limits.can_add && !limits.can_subtract) return '当前权限组不允许加减分';
|
||||
if (!limits.can_add) {
|
||||
return '仅限扣分' + (limits.max_subtract ? (',单次最多扣' + limits.max_subtract + '分') : '');
|
||||
}
|
||||
if (!limits.can_subtract) {
|
||||
return '仅限加分' + (limits.max_add ? (',单次最多加' + limits.max_add + '分') : '');
|
||||
}
|
||||
const parts = [];
|
||||
parts.push(limits.max_add ? ('单次加分上限' + limits.max_add + '分') : '加分无限制');
|
||||
parts.push(limits.max_subtract ? ('单次扣分上限' + limits.max_subtract + '分') : '扣分无限制');
|
||||
return parts.join(',');
|
||||
}
|
||||
|
||||
/**
|
||||
* 将权限组上限应用到分数输入框(min/max)
|
||||
*/
|
||||
function applyScoreLimits(inputEl) {
|
||||
if (!inputEl) return;
|
||||
const limits = getScoreLimits();
|
||||
if (limits.max_add !== null && limits.max_add !== undefined) {
|
||||
inputEl.max = limits.max_add;
|
||||
} else {
|
||||
inputEl.removeAttribute('max');
|
||||
}
|
||||
if (limits.max_subtract !== null && limits.max_subtract !== undefined) {
|
||||
inputEl.min = -limits.max_subtract;
|
||||
} else {
|
||||
inputEl.removeAttribute('min');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验分值是否符合权限组上限,返回错误信息(空字符串表示通过)
|
||||
*/
|
||||
function validateScoreChange(value) {
|
||||
const limits = getScoreLimits();
|
||||
if (!value || value === 0) return '分值不能为0';
|
||||
if (value > 0) {
|
||||
if (!limits.can_add) return '当前权限组仅允许扣分';
|
||||
if (limits.max_add !== null && limits.max_add !== undefined && value > limits.max_add) {
|
||||
return '单次加分不能超过' + limits.max_add + '分';
|
||||
}
|
||||
} else {
|
||||
if (!limits.can_subtract) return '当前权限组仅允许加分';
|
||||
if (limits.max_subtract !== null && limits.max_subtract !== undefined && Math.abs(value) > limits.max_subtract) {
|
||||
return '单次扣分不能超过' + limits.max_subtract + '分';
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function showToast(message, type = 'success') {
|
||||
const toast = document.createElement('div');
|
||||
toast.className = `toast toast-${type}`;
|
||||
|
||||
@@ -10,17 +10,26 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
const canViewPersonalQuery = hasPermission('view_all_records');
|
||||
const canManageConduct = hasPermission('manage_conduct');
|
||||
|
||||
async function loadStudents() {
|
||||
const res = await apiGet('/api/admin/students', {page_size: 1000});
|
||||
if (res && res.success) {
|
||||
let html = '';
|
||||
res.data.students.forEach(student => {
|
||||
const detailUrl = canViewPersonalQuery
|
||||
? `/admin/record_query.php?student_id=${student.student_id}`
|
||||
: `/admin/history.php?student_id=${student.student_id}`;
|
||||
const pointsButton = canManageConduct
|
||||
? `<button class="btn btn-sm btn-outline" onclick="showSinglePointsModal(${student.student_id}, '${escapeHtml(student.name)}')">加减分</button>`
|
||||
: '<span class="text-muted">-</span>';
|
||||
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}" class="link">${escapeHtml(student.name)}</a></td>
|
||||
<td><a href="${detailUrl}" class="link">${escapeHtml(student.name)}</a></td>
|
||||
<td>${student.total_points}</td>
|
||||
<td><button class="btn btn-sm btn-outline" onclick="showSinglePointsModal(${student.student_id}, '${escapeHtml(student.name)}')">加减分</button></td>
|
||||
<td>${pointsButton}</td>
|
||||
</tr>`;
|
||||
});
|
||||
if (res.data.students.length === 0) {
|
||||
@@ -35,10 +44,45 @@ function showSinglePointsModal(studentId, studentName) {
|
||||
document.getElementById('selectedStudentsCount').innerHTML = `${studentName} (1人)`;
|
||||
document.getElementById('pointsChange').value = '';
|
||||
document.getElementById('pointsReason').value = '';
|
||||
if (typeof preparePointsLimitHint === 'function') preparePointsLimitHint();
|
||||
document.getElementById('batchPointsModal').style.display = 'flex';
|
||||
}
|
||||
|
||||
function initPointsLimitHint() {
|
||||
const hintEl = document.getElementById('pointsLimitHint');
|
||||
if (hintEl) hintEl.textContent = describeScoreLimits();
|
||||
}
|
||||
|
||||
async function showExportMoralityModal() {
|
||||
await loadSemesterOptions('exportSemesterSelect', { includeAll: true });
|
||||
document.getElementById('exportMoralityModal').style.display = 'flex';
|
||||
}
|
||||
|
||||
function buildExportRow(student, semesterLabel, records, basePoints) {
|
||||
const positiveRecords = records.filter(r => r.points_change > 0);
|
||||
const negativeRecords = records.filter(r => r.points_change < 0);
|
||||
const bonus = positiveRecords.reduce((sum, r) => sum + r.points_change, 0);
|
||||
const deduction = negativeRecords.reduce((sum, r) => sum + r.points_change, 0);
|
||||
return {
|
||||
student_no: student.student_no,
|
||||
name: student.name,
|
||||
semester: semesterLabel,
|
||||
base: basePoints,
|
||||
bonus: bonus,
|
||||
deduction: deduction,
|
||||
score: records.length ? basePoints + bonus + deduction : (student.total_points || 0),
|
||||
current: student.total_points || 0,
|
||||
positive: positiveRecords.map(r => `${r.reason}(+${r.points_change})`).join('; '),
|
||||
negative: negativeRecords.map(r => `${r.reason}(${r.points_change})`).join('; ')
|
||||
};
|
||||
}
|
||||
|
||||
async function exportMoralityRecords() {
|
||||
const select = document.getElementById('exportSemesterSelect');
|
||||
const semesterId = select ? select.value : '';
|
||||
const selectedOption = select && select.selectedIndex >= 0 ? select.options[select.selectedIndex] : null;
|
||||
const semesterName = selectedOption ? selectedOption.textContent.replace(/((当前|已归档))$/, '') : '全部学期';
|
||||
|
||||
showToast('正在导出德育分记录...', 'info');
|
||||
|
||||
try {
|
||||
@@ -54,65 +98,49 @@ async function exportMoralityRecords() {
|
||||
return;
|
||||
}
|
||||
|
||||
const historyRes = await apiGet('/api/admin/conduct/history', { page: 1, page_size: 1000 });
|
||||
if (!historyRes || !historyRes.success) {
|
||||
showToast('获取历史记录失败', 'error');
|
||||
return;
|
||||
}
|
||||
const params = { is_revoked: 0 };
|
||||
if (semesterId) params.semester_id = semesterId;
|
||||
const allRecords = await apiGetAll('/api/admin/conduct/history', params);
|
||||
|
||||
const allRecords = historyRes.data.records || [];
|
||||
const basePoints = parseInt(window.STUDENT_INITIAL_POINTS || 60, 10) || 60;
|
||||
|
||||
const recordsByStudent = {};
|
||||
// 按 学生 + 学期 分组
|
||||
const groups = {};
|
||||
allRecords.forEach(record => {
|
||||
const sid = record.student_id;
|
||||
if (!recordsByStudent[sid]) {
|
||||
recordsByStudent[sid] = [];
|
||||
}
|
||||
recordsByStudent[sid].push(record);
|
||||
const label = semesterId ? semesterName : (record.semester_name || '未关联学期');
|
||||
const key = record.student_id + '|' + label;
|
||||
if (!groups[key]) groups[key] = [];
|
||||
groups[key].push(record);
|
||||
});
|
||||
|
||||
const studentRecords = [];
|
||||
for (const student of students) {
|
||||
const studentRecords_list = recordsByStudent[student.student_id] || [];
|
||||
const positiveRecords = studentRecords_list.filter(r => r.points_change > 0).map(r => `${r.reason}(+${r.points_change})`);
|
||||
const negativeRecords = studentRecords_list.filter(r => r.points_change < 0).map(r => `${r.reason}(${r.points_change})`);
|
||||
|
||||
studentRecords.push({
|
||||
student_no: student.student_no,
|
||||
name: student.name,
|
||||
total_points: student.total_points || 0,
|
||||
positive_history: positiveRecords.join('; '),
|
||||
negative_history: negativeRecords.join('; ')
|
||||
});
|
||||
}
|
||||
|
||||
function escapeCsvField(field) {
|
||||
if (field === null || field === undefined) return '';
|
||||
let str = String(field).replace(/[\r\n]+/g, ' ');
|
||||
str = str.replace(/"/g, '""');
|
||||
if (/[\,\;\"\s]/.test(str)) {
|
||||
str = '"' + str + '"';
|
||||
const rows = [];
|
||||
students.forEach(student => {
|
||||
if (semesterId) {
|
||||
const key = student.student_id + '|' + semesterName;
|
||||
rows.push(buildExportRow(student, semesterName, groups[key] || [], basePoints));
|
||||
} else {
|
||||
const prefix = student.student_id + '|';
|
||||
const labels = Object.keys(groups).filter(k => k.indexOf(prefix) === 0);
|
||||
if (labels.length === 0) {
|
||||
rows.push(buildExportRow(student, '-', [], basePoints));
|
||||
} else {
|
||||
labels.forEach(key => {
|
||||
rows.push(buildExportRow(student, key.substring(prefix.length), groups[key], basePoints));
|
||||
});
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
let csv = '\uFEFF';
|
||||
csv += '学号,姓名,分数,加分历史,减分记录\n';
|
||||
studentRecords.forEach(s => {
|
||||
csv += `${escapeCsvField(s.student_no)},${escapeCsvField(s.name)},${escapeCsvField(s.total_points)},${escapeCsvField(s.positive_history)},${escapeCsvField(s.negative_history)}\n`;
|
||||
});
|
||||
|
||||
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = `德育分记录_${new Date().toISOString().slice(0,10)}.csv`;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
let csv = '学号,姓名,学期,基础分,加分合计,减分合计,学期得分,当前总分,加分历史,减分记录\n';
|
||||
rows.forEach(r => {
|
||||
csv += [r.student_no, r.name, r.semester, r.base, r.bonus, r.deduction, r.score, r.current, r.positive, r.negative]
|
||||
.map(csvEscape).join(',') + '\n';
|
||||
});
|
||||
|
||||
showToast(`导出成功,共${studentRecords.length}名学生`);
|
||||
const safeSemester = (semesterName || '全部学期').replace(/[\\/:*?"<>|]/g, '_');
|
||||
downloadCsv(`德育分记录_${safeSemester}_${new Date().toISOString().slice(0,10)}.csv`, csv);
|
||||
closeModal('exportMoralityModal');
|
||||
showToast(`导出成功,共${rows.length}条学生记录`);
|
||||
} catch (err) {
|
||||
showToast('导出失败:' + err.message, 'error');
|
||||
console.error('导出失败:', err);
|
||||
@@ -212,7 +240,8 @@ async function submitDormitoryPoints() {
|
||||
if (res && res.success) {
|
||||
showToast(`操作成功: ${res.data.success_count} 人成功`);
|
||||
closeModal('dormitoryPointsModal');
|
||||
loadStudents();
|
||||
loadStudents();
|
||||
initPointsLimitHint();
|
||||
} else {
|
||||
showToast(res?.message || '操作失败', 'error');
|
||||
}
|
||||
@@ -222,6 +251,7 @@ loadStudents();
|
||||
|
||||
window.loadStudents = loadStudents;
|
||||
window.showSinglePointsModal = showSinglePointsModal;
|
||||
window.showExportMoralityModal = showExportMoralityModal;
|
||||
window.exportMoralityRecords = exportMoralityRecords;
|
||||
window.showDormitoryPointsModal = showDormitoryPointsModal;
|
||||
window.onDormitorySelected = onDormitorySelected;
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
const role = window.PAGE_CONFIG.role;
|
||||
let totalStudents = 0;
|
||||
|
||||
async function loadDashboard() {
|
||||
@@ -49,19 +48,27 @@ async function loadDashboard() {
|
||||
document.getElementById('dashboardStats').innerHTML = statsHtml;
|
||||
|
||||
let quickActions = '';
|
||||
if (role === '班主任' || role === '班长' || role === '学习委员' || role === '劳动委员' || role === '志愿委员') {
|
||||
if (hasPermission('manage_conduct')) {
|
||||
quickActions += '<button class="btn btn-primary" onclick="location.href=\'/admin/conduct.php\'">操行分管理</button>';
|
||||
}
|
||||
if (role === '班主任' || role === '学习委员') {
|
||||
if (hasPermission('manage_homework')) {
|
||||
quickActions += '<button class="btn btn-primary" onclick="location.href=\'/admin/homework.php\'">作业扣分</button>';
|
||||
}
|
||||
if (role === '班主任' || role === '考勤委员') {
|
||||
if (hasPermission('manage_attendance')) {
|
||||
quickActions += '<button class="btn btn-primary" onclick="location.href=\'/admin/attendance.php\'">考勤管理</button>';
|
||||
}
|
||||
if (role === '班主任') {
|
||||
quickActions += '<button class="btn btn-outline" onclick="location.href=\'/admin/students.php\'">导入学生</button>';
|
||||
if (hasPermission('manage_students')) {
|
||||
quickActions += '<button class="btn btn-outline" onclick="location.href=\'/admin/students.php\'">学生管理</button>';
|
||||
}
|
||||
if (hasPermission('manage_semesters')) {
|
||||
quickActions += '<button class="btn btn-outline" onclick="location.href=\'/admin/semesters.php\'">学期管理</button>';
|
||||
}
|
||||
if (hasPermission('export_data')) {
|
||||
quickActions += '<button class="btn btn-secondary" onclick="location.href=\'/admin/conduct.php\'">导出德育分记录</button>';
|
||||
}
|
||||
if (hasPermission('export_students')) {
|
||||
quickActions += '<button class="btn btn-secondary" onclick="location.href=\'/admin/students.php\'">导出学生名单</button>';
|
||||
}
|
||||
document.getElementById('quickActions').innerHTML = quickActions || '<p>暂无快捷操作</p>';
|
||||
|
||||
const rankingRes = await apiGet('/api/student/ranking', { limit: 100 });
|
||||
|
||||
@@ -10,8 +10,11 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
const role = window.PAGE_CONFIG.role;
|
||||
const currentUserId = window.PAGE_CONFIG.userId;
|
||||
const canRevokeAny = hasPermission('revoke_any');
|
||||
const canRevokeOwn = hasPermission('revoke_own');
|
||||
const canRestore = hasPermission('restore_records');
|
||||
const canRevoke = canRevokeAny || canRevokeOwn;
|
||||
let currentHistoryPage = 1;
|
||||
let totalHistoryPages = 1;
|
||||
|
||||
@@ -52,6 +55,11 @@ async function loadSubjectsForFilter() {
|
||||
}
|
||||
}
|
||||
|
||||
// 加载学期下拉列表(默认选中当前学期)
|
||||
async function loadSemestersForFilter() {
|
||||
await loadSemesterOptions('historySemesterFilter', { includeAll: true });
|
||||
}
|
||||
|
||||
// 筛选学生时自动取消合并记录
|
||||
function onStudentFilterChange() {
|
||||
var studentId = document.getElementById('historyStudentId').value;
|
||||
@@ -89,6 +97,7 @@ async function loadHistory(page) {
|
||||
var startDate = document.getElementById('historyStartDate').value;
|
||||
var endDate = document.getElementById('historyEndDate').value;
|
||||
var studentId = document.getElementById('historyStudentId').value;
|
||||
var semesterId = document.getElementById('historySemesterFilter') ? document.getElementById('historySemesterFilter').value : '';
|
||||
var reasonFilter = document.getElementById('historyReasonFilter').value;
|
||||
var subjectFilter = document.getElementById('historySubjectFilter').value;
|
||||
var reasonSearch = document.getElementById('historyReasonSearch').value.trim();
|
||||
@@ -103,6 +112,7 @@ async function loadHistory(page) {
|
||||
start_date: startDate,
|
||||
end_date: endDate
|
||||
};
|
||||
if (semesterId) params.semester_id = semesterId;
|
||||
if (studentId) params.student_id = studentId;
|
||||
|
||||
// 科目筛选优先于扣分类型筛选
|
||||
@@ -123,12 +133,12 @@ async function loadHistory(page) {
|
||||
var headHtml = '';
|
||||
if (isGrouped) {
|
||||
headHtml = '<th>类型</th><th>分值</th><th>原因</th><th>学生名单</th><th' + nowrapStyle + '>操作人</th><th>时间</th>';
|
||||
if (role === '班主任' || role === '班长') {
|
||||
if (canRevoke) {
|
||||
headHtml += '<th>操作</th>';
|
||||
}
|
||||
} else {
|
||||
headHtml = '<th>类型</th><th>分值</th><th>原因</th><th>学生</th><th' + nowrapStyle + '>操作人</th><th>时间</th>';
|
||||
if (role === '班主任' || role === '班长' || role === '考勤委员') {
|
||||
if (canRevoke) {
|
||||
headHtml += '<th>操作</th>';
|
||||
}
|
||||
}
|
||||
@@ -149,17 +159,19 @@ async function loadHistory(page) {
|
||||
'<td class="history-students">' + escapeHtml(names) + '</td>' +
|
||||
'<td>' + escapeHtml(record.recorder_name || '') + '</td>' +
|
||||
'<td class="history-time">' + formatDateTime(record.created_at) + '</td>';
|
||||
if (role === '班主任' || role === '班长') {
|
||||
if (canRevoke) {
|
||||
if (allRevoked) {
|
||||
html += '<td><span class="text-muted">已撤销</span></td>';
|
||||
} else {
|
||||
} else if (canRevokeAny) {
|
||||
html += '<td><button class="btn btn-sm btn-outline" onclick="batchRevokeGrouped(\'' + escapeHtml(record.reason).replace(/'/g, "\\'") + '\',' + record.points_change + ',\'' + escapeHtml(record.recorder_name || '').replace(/'/g, "\\'") + '\',\'' + formatDateTime(record.created_at) + '\')">批量撤销</button></td>';
|
||||
} else {
|
||||
html += '<td><span class="text-muted">-</span></td>';
|
||||
}
|
||||
}
|
||||
html += '</tr>';
|
||||
});
|
||||
if (res.data.records.length === 0) {
|
||||
var colSpan = (role === '班主任' || role === '班长') ? 7 : 6;
|
||||
var colSpan = canRevoke ? 7 : 6;
|
||||
html = '<tr><td colspan="' + colSpan + '" style="text-align:center;">暂无记录</td></tr>';
|
||||
}
|
||||
} else {
|
||||
@@ -174,24 +186,15 @@ async function loadHistory(page) {
|
||||
'<td>' + escapeHtml(record.student_name) + '</td>' +
|
||||
'<td>' + escapeHtml(record.recorder_name) + '</td>' +
|
||||
'<td class="history-time">' + formatDateTime(record.created_at) + '</td>';
|
||||
if (role === '班主任') {
|
||||
if (canRevoke) {
|
||||
if (record.is_revoked == 1) {
|
||||
var revokerInfo = record.revoker_name ? '由 ' + escapeHtml(record.revoker_name) + ' 撤销' : '已撤销';
|
||||
html += '<td><span class="text-muted" style="margin-right:4px;">' + revokerInfo + '</span><button class="btn btn-sm btn-outline" onclick="restoreRecord(' + record.record_id + ')">反撤销</button></td>';
|
||||
} else {
|
||||
html += '<td><button class="btn btn-sm btn-outline" onclick="revokeRecord(' + record.record_id + ')">撤销</button></td>';
|
||||
}
|
||||
} else if (role === '班长') {
|
||||
if (record.is_revoked == 1) {
|
||||
var revokerInfo = record.revoker_name ? '由 ' + escapeHtml(record.revoker_name) + ' 撤销' : '已撤销';
|
||||
html += '<td><span class="text-muted">' + revokerInfo + '</span></td>';
|
||||
} else {
|
||||
html += '<td><button class="btn btn-sm btn-outline" onclick="revokeRecord(' + record.record_id + ')">撤销</button></td>';
|
||||
}
|
||||
} else if (role === '考勤委员') {
|
||||
if (record.is_revoked == 1) {
|
||||
html += '<td><span class="text-muted">已撤销</span></td>';
|
||||
} else if (record.recorder_id == currentUserId) {
|
||||
if (canRestore) {
|
||||
html += '<td><span class="text-muted" style="margin-right:4px;">' + revokerInfo + '</span><button class="btn btn-sm btn-outline" onclick="restoreRecord(' + record.record_id + ')">反撤销</button></td>';
|
||||
} else {
|
||||
html += '<td><span class="text-muted">' + revokerInfo + '</span></td>';
|
||||
}
|
||||
} else if (canRevokeAny || (canRevokeOwn && record.recorder_id == currentUserId)) {
|
||||
html += '<td><button class="btn btn-sm btn-outline" onclick="revokeRecord(' + record.record_id + ')">撤销</button></td>';
|
||||
} else {
|
||||
html += '<td><span class="text-muted">-</span></td>';
|
||||
@@ -201,7 +204,7 @@ async function loadHistory(page) {
|
||||
});
|
||||
|
||||
if (res.data.records.length === 0) {
|
||||
var colSpan = (role === '班主任' || role === '班长' || role === '考勤委员') ? 7 : 6;
|
||||
var colSpan = canRevoke ? 7 : 6;
|
||||
html = '<tr><td colspan="' + colSpan + '" style="text-align:center;">暂无记录</td></tr>';
|
||||
}
|
||||
}
|
||||
@@ -223,6 +226,8 @@ async function exportHistoryRecords() {
|
||||
var startDate = document.getElementById('historyStartDate').value;
|
||||
var endDate = document.getElementById('historyEndDate').value;
|
||||
var studentId = document.getElementById('historyStudentId').value;
|
||||
var semesterSelect = document.getElementById('historySemesterFilter');
|
||||
var semesterId = semesterSelect ? semesterSelect.value : '';
|
||||
|
||||
showToast('正在导出历史记录...', 'info');
|
||||
|
||||
@@ -230,10 +235,11 @@ async function exportHistoryRecords() {
|
||||
var reasonFilter = document.getElementById('historyReasonFilter').value;
|
||||
var subjectFilter = document.getElementById('historySubjectFilter').value;
|
||||
var reasonSearch = document.getElementById('historyReasonSearch').value.trim();
|
||||
var params = { page: 1, page_size: 1000 };
|
||||
var params = { is_revoked: 0 };
|
||||
if (startDate) params.start_date = startDate;
|
||||
if (endDate) params.end_date = endDate;
|
||||
if (studentId) params.student_id = studentId;
|
||||
if (semesterId) params.semester_id = semesterId;
|
||||
if (subjectFilter) {
|
||||
params.reason_prefix = '[' + subjectFilter + ']';
|
||||
} else if (reasonFilter) {
|
||||
@@ -241,35 +247,34 @@ async function exportHistoryRecords() {
|
||||
}
|
||||
if (reasonSearch) params.reason_search = reasonSearch;
|
||||
|
||||
var res = await apiGet('/api/admin/conduct/history', params);
|
||||
if (res && res.success && res.data.records) {
|
||||
var records = res.data.records;
|
||||
if (records.length === 0) {
|
||||
showToast('没有找到记录', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
var csv = '\uFEFF';
|
||||
csv += '时间,学号,姓名,分数变动,原因,操作人\n';
|
||||
records.forEach(function(r) {
|
||||
if (r.is_revoked == 1) return;
|
||||
csv += (r.created_at || '') + ',' + (r.student_no || '') + ',' + (r.student_name || '') + ',' + (r.points_change > 0 ? '+' : '') + r.points_change + ',' + (r.reason || '').replace(/,/g, ';') + ',' + (r.recorder_name || '') + '\n';
|
||||
});
|
||||
|
||||
var blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
|
||||
var url = URL.createObjectURL(blob);
|
||||
var link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = '历史记录_' + new Date().toISOString().slice(0,10) + '.csv';
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
|
||||
showToast('导出成功,共' + records.length + '条记录');
|
||||
} else {
|
||||
showToast('导出失败:' + (res && res.message || '未知错误'), 'error');
|
||||
var records = await apiGetAll('/api/admin/conduct/history', params);
|
||||
if (!records || records.length === 0) {
|
||||
showToast('没有找到记录', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
var 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, '_');
|
||||
downloadCsv('历史记录_' + safeLabel + '_' + new Date().toISOString().slice(0,10) + '.csv', csv);
|
||||
|
||||
showToast('导出成功,共' + records.length + '条记录');
|
||||
} catch (err) {
|
||||
showToast('导出失败:' + err.message, 'error');
|
||||
}
|
||||
@@ -289,6 +294,8 @@ async function batchRevokeGrouped(reason, pointsChange, recorderName, createdAt)
|
||||
reason_prefix: reason.substring(0, 4),
|
||||
grouped: false
|
||||
};
|
||||
var semesterSelect = document.getElementById('historySemesterFilter');
|
||||
if (semesterSelect && semesterSelect.value) params.semester_id = semesterSelect.value;
|
||||
|
||||
var res = await apiGet('/api/admin/conduct/history', params);
|
||||
if (!res || !res.success || !res.data.records) {
|
||||
@@ -320,8 +327,8 @@ async function batchRevokeGrouped(reason, pointsChange, recorderName, createdAt)
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化:并行加载学生和科目列表,然后加载历史记录
|
||||
Promise.all([loadStudentsForSelect(), loadSubjectsForFilter()]).then(function() {
|
||||
// 初始化:并行加载学生、科目、学期列表,然后加载历史记录
|
||||
Promise.all([loadStudentsForSelect(), loadSubjectsForFilter(), loadSemestersForFilter()]).then(function() {
|
||||
var urlParams = new URLSearchParams(window.location.search);
|
||||
var preStudentId = urlParams.get('student_id');
|
||||
if (preStudentId) {
|
||||
|
||||
@@ -10,21 +10,16 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
const hwRole = window.PAGE_CONFIG.role;
|
||||
|
||||
// 初始化扣分配置
|
||||
const hwMaxPoints = hwRole === '班主任' ? 100 : 5;
|
||||
const hwNotSubmit = window.DEDUCTION_HOMEWORK_NOT_SUBMIT || 2;
|
||||
const hwLate = window.DEDUCTION_HOMEWORK_LATE || 1;
|
||||
|
||||
// 更新页面中的配置值显示
|
||||
// 更新页面中的配置值显示(加减分上限来自权限组动态配置)
|
||||
document.querySelectorAll('.hw-not-submit').forEach(el => el.textContent = hwNotSubmit);
|
||||
document.querySelectorAll('.hw-late').forEach(el => el.textContent = hwLate);
|
||||
document.querySelectorAll('.hw-max').forEach(el => el.textContent = hwMaxPoints);
|
||||
document.querySelectorAll('.hw-max').forEach(el => el.textContent = describeScoreLimits());
|
||||
|
||||
// 更新输入框的 min/max
|
||||
document.getElementById('pointsChange').setAttribute('min', -hwMaxPoints);
|
||||
document.getElementById('pointsChange').setAttribute('max', hwMaxPoints);
|
||||
// 更新输入框的 min/max(按权限组动态上限)
|
||||
applyScoreLimits(document.getElementById('pointsChange'));
|
||||
|
||||
// 加载科目列表(学习委员)
|
||||
async function loadSubjectsForHomework() {
|
||||
@@ -71,36 +66,31 @@ function showSinglePointsModal(studentId, studentName) {
|
||||
|
||||
function handleSubmitPoints() {
|
||||
const pointsChange = parseInt(document.getElementById('pointsChange').value);
|
||||
if (isNaN(pointsChange) || pointsChange === 0) {
|
||||
showToast('请输入有效的加减分值', 'warning');
|
||||
return;
|
||||
}
|
||||
if (Math.abs(pointsChange) > hwMaxPoints) {
|
||||
showToast(`每次加减分不超过${hwMaxPoints}分`, 'warning');
|
||||
const limitError = validateScoreChange(pointsChange);
|
||||
if (limitError) {
|
||||
showToast(limitError, 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
// 学习委员附加科目前缀、具体作业和缴交时间
|
||||
if (hwRole === '学习委员' || hwRole === '班主任') {
|
||||
const subjectSelect = document.getElementById('hwSubjectSelect');
|
||||
const subjectName = subjectSelect ? subjectSelect.value : '';
|
||||
const hwTitle = document.getElementById('hwTitle').value.trim();
|
||||
const hwDeadline = document.getElementById('hwDeadline').value;
|
||||
const reasonEl = document.getElementById('pointsReason');
|
||||
|
||||
let prefix = '';
|
||||
if (subjectName) {
|
||||
prefix = `[${subjectName}]`;
|
||||
}
|
||||
if (hwTitle) {
|
||||
prefix += `[${hwTitle}]`;
|
||||
}
|
||||
if (hwDeadline) {
|
||||
prefix += ` 缴交:${hwDeadline}`;
|
||||
}
|
||||
if (prefix) {
|
||||
reasonEl.value = prefix + ' ' + reasonEl.value;
|
||||
}
|
||||
// 附加科目前缀、具体作业和缴交时间
|
||||
const subjectSelect = document.getElementById('hwSubjectSelect');
|
||||
const subjectName = subjectSelect ? subjectSelect.value : '';
|
||||
const hwTitle = document.getElementById('hwTitle').value.trim();
|
||||
const hwDeadline = document.getElementById('hwDeadline').value;
|
||||
const reasonEl = document.getElementById('pointsReason');
|
||||
|
||||
let prefix = '';
|
||||
if (subjectName) {
|
||||
prefix = `[${subjectName}]`;
|
||||
}
|
||||
if (hwTitle) {
|
||||
prefix += `[${hwTitle}]`;
|
||||
}
|
||||
if (hwDeadline) {
|
||||
prefix += ` 缴交:${hwDeadline}`;
|
||||
}
|
||||
if (prefix) {
|
||||
reasonEl.value = prefix + ' ' + reasonEl.value;
|
||||
}
|
||||
|
||||
submitBatchPoints({ related_type: 'homework' });
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
// 显示添加管理员模态框
|
||||
function showAddAdminModal() {
|
||||
document.getElementById('addAdminModal').style.display = 'flex';
|
||||
document.getElementById('addAdminForm')?.reset();
|
||||
}
|
||||
|
||||
// 提交添加管理员
|
||||
@@ -23,9 +22,9 @@
|
||||
const username = document.getElementById('adminUsername').value.trim();
|
||||
const realName = document.getElementById('adminRealName').value.trim();
|
||||
const password = document.getElementById('adminPassword').value;
|
||||
const roleType = document.getElementById('adminRole').value;
|
||||
const groupId = parseInt(document.getElementById('adminGroupId').value);
|
||||
|
||||
if (!username || !realName || !roleType) {
|
||||
if (!username || !realName || !groupId) {
|
||||
showToast('请填写完整信息', 'warning');
|
||||
return;
|
||||
}
|
||||
@@ -34,7 +33,7 @@
|
||||
username: username,
|
||||
real_name: realName,
|
||||
password: password || undefined,
|
||||
role_type: roleType
|
||||
group_id: groupId
|
||||
});
|
||||
|
||||
if (res && res.success) {
|
||||
@@ -46,6 +45,10 @@
|
||||
}
|
||||
showToast(msg);
|
||||
closeModal('addAdminModal');
|
||||
document.getElementById('adminUsername').value = '';
|
||||
document.getElementById('adminRealName').value = '';
|
||||
document.getElementById('adminPassword').value = '';
|
||||
document.getElementById('adminGroupId').value = '';
|
||||
loadAdmins();
|
||||
} else {
|
||||
showToast(res?.message || '添加失败', 'error');
|
||||
|
||||
@@ -31,16 +31,26 @@
|
||||
document.getElementById('selectedStudentsCount').innerHTML = `${selectedStudentIds.length} 人`;
|
||||
document.getElementById('pointsChange').value = '';
|
||||
document.getElementById('pointsReason').value = '';
|
||||
preparePointsLimitHint();
|
||||
document.getElementById('batchPointsModal').style.display = 'flex';
|
||||
}
|
||||
|
||||
// 应用动态加减分上限提示与输入限制
|
||||
function preparePointsLimitHint() {
|
||||
var inputEl = document.getElementById('pointsChange');
|
||||
applyScoreLimits(inputEl);
|
||||
var hintEl = document.getElementById('pointsLimitHint');
|
||||
if (hintEl) hintEl.textContent = describeScoreLimits();
|
||||
}
|
||||
|
||||
// 提交批量加减分
|
||||
async function submitBatchPoints(options = {}) {
|
||||
const pointsChange = parseInt(document.getElementById('pointsChange').value);
|
||||
const reason = document.getElementById('pointsReason').value;
|
||||
|
||||
if (isNaN(pointsChange) || pointsChange === 0) {
|
||||
showToast('分值不能为0', 'error');
|
||||
const limitError = validateScoreChange(pointsChange);
|
||||
if (limitError) {
|
||||
showToast(limitError, 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -97,6 +107,7 @@
|
||||
|
||||
window.showBatchPointsModal = showBatchPointsModal;
|
||||
window.submitBatchPoints = submitBatchPoints;
|
||||
window.preparePointsLimitHint = preparePointsLimitHint;
|
||||
window.revokeRecord = revokeRecord;
|
||||
window.restoreRecord = restoreRecord;
|
||||
})();
|
||||
@@ -0,0 +1,315 @@
|
||||
/**
|
||||
* 班级操行分管理系统 - 个人记录查询页JS
|
||||
*
|
||||
* 开发者: Canglan
|
||||
* 版权归属: Sea Network Technology Studio
|
||||
*
|
||||
* 版权所有 © Sea Network Technology Studio
|
||||
*/
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
const canRevokeAny = hasPermission('revoke_any');
|
||||
const canRevokeOwn = hasPermission('revoke_own');
|
||||
const canRestore = hasPermission('restore_records');
|
||||
const canManage = canRevokeAny || canRevokeOwn;
|
||||
let currentStudentId = null;
|
||||
let currentPage = 1;
|
||||
|
||||
function typeMap(relatedType) {
|
||||
var map = { manual: '手动', homework: '作业', attendance: '考勤' };
|
||||
return map[relatedType] || '手动';
|
||||
}
|
||||
|
||||
function monthLabel(month) {
|
||||
if (!month || month.indexOf('-') < 0) return month || '-';
|
||||
var parts = month.split('-');
|
||||
return parts[0] + '年' + parseInt(parts[1], 10) + '月';
|
||||
}
|
||||
|
||||
async function loadStudents() {
|
||||
const res = await apiGet('/api/admin/students', { page_size: 1000 });
|
||||
if (res && res.success) {
|
||||
let html = '<option value="">-- 请选择学生 --</option>';
|
||||
res.data.students.forEach(s => {
|
||||
html += '<option value="' + s.student_id + '">' + escapeHtml(s.student_no) + ' - ' + escapeHtml(s.name) + '</option>';
|
||||
});
|
||||
document.getElementById('queryStudentId').innerHTML = html;
|
||||
}
|
||||
}
|
||||
|
||||
async function queryStudentRecords(page) {
|
||||
const studentId = document.getElementById('queryStudentId').value;
|
||||
if (!studentId) {
|
||||
showToast('请先选择学生', 'warning');
|
||||
return;
|
||||
}
|
||||
currentStudentId = studentId;
|
||||
currentPage = page || 1;
|
||||
const semesterId = document.getElementById('querySemesterId').value;
|
||||
|
||||
document.getElementById('queryPlaceholder').style.display = 'none';
|
||||
document.getElementById('queryResult').style.display = 'block';
|
||||
|
||||
await Promise.all([
|
||||
loadSummary(studentId, semesterId),
|
||||
loadRecords(studentId, semesterId, currentPage)
|
||||
]);
|
||||
}
|
||||
|
||||
function onQueryStudentChange() {
|
||||
if (!document.getElementById('queryStudentId').value) {
|
||||
document.getElementById('queryResult').style.display = 'none';
|
||||
document.getElementById('queryPlaceholder').style.display = 'block';
|
||||
return;
|
||||
}
|
||||
queryStudentRecords(1);
|
||||
}
|
||||
|
||||
function onQuerySemesterChange() {
|
||||
if (document.getElementById('queryStudentId').value) {
|
||||
queryStudentRecords(1);
|
||||
}
|
||||
}
|
||||
|
||||
async function loadSummary(studentId, semesterId) {
|
||||
const params = { student_id: studentId };
|
||||
if (semesterId) params.semester_id = semesterId;
|
||||
|
||||
const res = await apiGet('/api/admin/conduct/student-summary', params);
|
||||
if (!res || !res.success) {
|
||||
showToast((res && res.message) || '获取汇总失败', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
const data = res.data;
|
||||
const semesterName = data.semester ? data.semester.semester_name : '全部学期';
|
||||
document.getElementById('queryStudentTitle').textContent =
|
||||
data.student.name + '(' + data.student.student_no + ') - ' + semesterName;
|
||||
|
||||
const s = data.summary;
|
||||
document.getElementById('querySummaryCards').innerHTML =
|
||||
'<div class="stat-card"><div class="stat-label">基础分</div><div class="stat-value">' + data.base_points + '</div></div>' +
|
||||
'<div class="stat-card"><div class="stat-label">加分合计</div><div class="stat-value plus">+' + s.bonus_total + '</div></div>' +
|
||||
'<div class="stat-card"><div class="stat-label">减分合计</div><div class="stat-value minus">' + s.deduction_total + '</div></div>' +
|
||||
'<div class="stat-card"><div class="stat-label">得分(基础分+加减分)</div><div class="stat-value">' + s.computed_total + '</div></div>' +
|
||||
'<div class="stat-card"><div class="stat-label">当前实时总分</div><div class="stat-value">' + s.current_total_points + '</div></div>';
|
||||
|
||||
document.getElementById('querySummaryHint').textContent =
|
||||
'共 ' + s.record_count + ' 条有效记录(不含已撤销)。' +
|
||||
(data.semester ? '学期得分按“基础分 + 学期内加分 - 学期内减分”计算。' : '全部学期得分按“基础分 + 全部加分 - 全部减分”计算,仅供参考。');
|
||||
|
||||
renderMonthly(data.months);
|
||||
renderReasonSummary(data.months);
|
||||
}
|
||||
|
||||
function renderMonthly(months) {
|
||||
let html = '';
|
||||
if (!months || months.length === 0) {
|
||||
html = '<tr><td colspan="6" style="text-align:center;">暂无记录</td></tr>';
|
||||
} else {
|
||||
months.forEach(m => {
|
||||
html += '<tr>' +
|
||||
'<td>' + escapeHtml(monthLabel(m.month)) + '</td>' +
|
||||
'<td>' + m.start_score + '</td>' +
|
||||
'<td class="plus">+' + m.bonus + '</td>' +
|
||||
'<td class="minus">' + m.deduction + '</td>' +
|
||||
'<td><strong>' + m.end_score + '</strong></td>' +
|
||||
'<td>' + m.record_count + '</td>' +
|
||||
'</tr>';
|
||||
});
|
||||
}
|
||||
document.getElementById('queryMonthlyList').innerHTML = html;
|
||||
}
|
||||
|
||||
function renderReasonTable(reasons, emptyText) {
|
||||
if (!reasons || reasons.length === 0) {
|
||||
return '<div style="color:var(--color-text-secondary); font-size:12px; padding:8px 0;">' + emptyText + '</div>';
|
||||
}
|
||||
let html = '<table class="table"><thead><tr><th>理由</th><th style="width:60px;">次数</th><th style="width:80px;">合计</th></tr></thead><tbody>';
|
||||
reasons.forEach(r => {
|
||||
html += '<tr>' +
|
||||
'<td>' + escapeHtml(r.reason) + '</td>' +
|
||||
'<td>' + r.count + '</td>' +
|
||||
'<td class="' + (r.points > 0 ? 'plus' : 'minus') + '">' + (r.points > 0 ? '+' : '') + r.points + '</td>' +
|
||||
'</tr>';
|
||||
});
|
||||
html += '</tbody></table>';
|
||||
return html;
|
||||
}
|
||||
|
||||
function renderReasonSummary(months) {
|
||||
const container = document.getElementById('queryReasonSummary');
|
||||
if (!months || months.length === 0) {
|
||||
container.innerHTML = '<div style="text-align:center; color:var(--color-text-secondary); padding:16px 0;">暂无记录</div>';
|
||||
return;
|
||||
}
|
||||
let html = '';
|
||||
months.forEach(m => {
|
||||
html += '<div style="margin-bottom: 20px;">' +
|
||||
'<div style="font-weight: bold; margin-bottom: 8px;">' + escapeHtml(monthLabel(m.month)) +
|
||||
' <span style="font-weight: normal; font-size: 12px; color: var(--color-text-secondary);">' +
|
||||
'加分 +' + m.bonus + ' / 减分 ' + m.deduction + '</span></div>' +
|
||||
'<div style="display:grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px;">' +
|
||||
'<div><div style="color:var(--color-success); font-size:13px; margin-bottom:4px;">加分理由</div>' + renderReasonTable(m.bonus_reasons, '本月无加分') + '</div>' +
|
||||
'<div><div style="color:var(--color-danger); font-size:13px; margin-bottom:4px;">减分理由</div>' + renderReasonTable(m.deduction_reasons, '本月无减分') + '</div>' +
|
||||
'</div></div>';
|
||||
});
|
||||
container.innerHTML = html;
|
||||
}
|
||||
|
||||
async function loadRecords(studentId, semesterId, page) {
|
||||
const params = { student_id: studentId, page: page || 1, page_size: 20 };
|
||||
if (semesterId) params.semester_id = semesterId;
|
||||
|
||||
const res = await apiGet('/api/admin/conduct/history', params);
|
||||
if (!res || !res.success) {
|
||||
showToast('获取明细记录失败', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
const records = res.data.records || [];
|
||||
let html = '';
|
||||
records.forEach(record => {
|
||||
const pointsClass = record.points_change > 0 ? 'plus' : 'minus';
|
||||
const revokedStyle = record.is_revoked == 1 ? ' style="opacity:0.5;text-decoration:line-through;"' : '';
|
||||
html += '<tr' + revokedStyle + '>' +
|
||||
'<td>' + typeMap(record.related_type) + '</td>' +
|
||||
'<td class="' + pointsClass + '">' + (record.points_change > 0 ? '+' : '') + record.points_change + '</td>' +
|
||||
'<td>' + escapeHtml(record.reason) + '</td>' +
|
||||
'<td>' + escapeHtml(record.recorder_name || '') + '</td>' +
|
||||
'<td style="white-space:nowrap;">' + formatDateTime(record.created_at) + '</td>';
|
||||
if (canManage) {
|
||||
if (record.is_revoked == 1) {
|
||||
if (canRestore) {
|
||||
html += '<td><span class="text-muted">已撤销</span> <button class="btn btn-sm btn-outline" onclick="restoreQueryRecord(' + record.record_id + ')">反撤销</button></td>';
|
||||
} else {
|
||||
html += '<td><span class="text-muted">已撤销</span></td>';
|
||||
}
|
||||
} else if (canRevokeAny || (canRevokeOwn && record.recorder_id == window.PAGE_CONFIG.userId)) {
|
||||
html += '<td><button class="btn btn-sm btn-outline" onclick="revokeQueryRecord(' + record.record_id + ')">撤销</button></td>';
|
||||
} else {
|
||||
html += '<td><span class="text-muted">-</span></td>';
|
||||
}
|
||||
}
|
||||
html += '</tr>';
|
||||
});
|
||||
|
||||
if (records.length === 0) {
|
||||
html = '<tr><td colspan="' + (canManage ? 6 : 5) + '" style="text-align:center;">暂无记录</td></tr>';
|
||||
}
|
||||
document.getElementById('queryRecordList').innerHTML = html;
|
||||
|
||||
const totalPages = res.data.total_pages || 1;
|
||||
renderSmartPagination('queryPagination', page || 1, totalPages, function(p) {
|
||||
currentPage = p;
|
||||
loadRecords(currentStudentId, document.getElementById('querySemesterId').value, p);
|
||||
});
|
||||
}
|
||||
|
||||
async function revokeQueryRecord(recordId) {
|
||||
if (!confirm('确定要撤销这条记录吗?撤销后学生分数将恢复。')) return;
|
||||
const res = await apiPost('/api/admin/conduct/revoke', { record_id: recordId });
|
||||
if (res && res.success) {
|
||||
showToast('撤销成功');
|
||||
queryStudentRecords(currentPage);
|
||||
} else {
|
||||
showToast((res && res.message) || '撤销失败', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async function restoreQueryRecord(recordId) {
|
||||
if (!confirm('确定要反撤销这条记录吗?分数变动将重新生效。')) return;
|
||||
const res = await apiPost('/api/admin/conduct/restore', { record_id: recordId });
|
||||
if (res && res.success) {
|
||||
showToast('反撤销成功');
|
||||
queryStudentRecords(currentPage);
|
||||
} else {
|
||||
showToast((res && res.message) || '反撤销失败', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async function exportStudentRecords() {
|
||||
const studentId = document.getElementById('queryStudentId').value;
|
||||
if (!studentId) {
|
||||
showToast('请先选择学生', 'warning');
|
||||
return;
|
||||
}
|
||||
const semesterSelect = document.getElementById('querySemesterId');
|
||||
const semesterId = semesterSelect.value;
|
||||
const semesterName = (semesterSelect.selectedIndex >= 0)
|
||||
? semesterSelect.options[semesterSelect.selectedIndex].textContent.replace(/((当前|已归档))$/, '')
|
||||
: '全部学期';
|
||||
const studentName = document.getElementById('queryStudentId').selectedOptions[0].textContent.trim();
|
||||
|
||||
showToast('正在导出个人记录...', 'info');
|
||||
|
||||
try {
|
||||
const params = { student_id: studentId, is_revoked: 0 };
|
||||
if (semesterId) params.semester_id = semesterId;
|
||||
const records = await apiGetAll('/api/admin/conduct/history', params);
|
||||
|
||||
let summaryLines = [];
|
||||
const summaryParams = { student_id: studentId };
|
||||
if (semesterId) summaryParams.semester_id = semesterId;
|
||||
const summaryRes = await apiGet('/api/admin/conduct/student-summary', summaryParams);
|
||||
if (summaryRes && summaryRes.success) {
|
||||
const d = summaryRes.data;
|
||||
summaryLines = [
|
||||
['学生', studentName],
|
||||
['学期', semesterName],
|
||||
['基础分', d.base_points],
|
||||
['加分合计', d.summary.bonus_total],
|
||||
['减分合计', d.summary.deduction_total],
|
||||
['得分(基础分+加减分)', d.summary.computed_total],
|
||||
['当前实时总分', d.summary.current_total_points]
|
||||
];
|
||||
}
|
||||
|
||||
let csv = '';
|
||||
summaryLines.forEach(line => {
|
||||
csv += [line[0], line[1]].map(csvEscape).join(',') + '\n';
|
||||
});
|
||||
csv += '\n时间,类型,分值,原因,操作人,状态\n';
|
||||
records.forEach(r => {
|
||||
csv += [
|
||||
r.created_at || '',
|
||||
typeMap(r.related_type),
|
||||
(r.points_change > 0 ? '+' : '') + r.points_change,
|
||||
r.reason || '',
|
||||
r.recorder_name || '',
|
||||
r.is_revoked == 1 ? '已撤销' : '正常'
|
||||
].map(csvEscape).join(',') + '\n';
|
||||
});
|
||||
|
||||
const safeLabel = (semesterName || '全部学期').replace(/[\\/:*?"<>|]/g, '_');
|
||||
downloadCsv('个人记录_' + studentName + '_' + safeLabel + '_' + new Date().toISOString().slice(0,10) + '.csv', csv);
|
||||
showToast('导出成功,共' + records.length + '条明细记录');
|
||||
} catch (err) {
|
||||
showToast('导出失败:' + err.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
(async function init() {
|
||||
await Promise.all([
|
||||
loadStudents(),
|
||||
loadSemesterOptions('querySemesterId', { includeAll: true })
|
||||
]);
|
||||
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const preStudentId = urlParams.get('student_id');
|
||||
if (preStudentId) {
|
||||
document.getElementById('queryStudentId').value = preStudentId;
|
||||
queryStudentRecords(1);
|
||||
}
|
||||
})();
|
||||
|
||||
window.queryStudentRecords = queryStudentRecords;
|
||||
window.onQueryStudentChange = onQueryStudentChange;
|
||||
window.onQuerySemesterChange = onQuerySemesterChange;
|
||||
window.exportStudentRecords = exportStudentRecords;
|
||||
window.revokeQueryRecord = revokeQueryRecord;
|
||||
window.restoreQueryRecord = restoreQueryRecord;
|
||||
|
||||
})();
|
||||
@@ -10,7 +10,10 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
const userRole = window.PAGE_CONFIG.role;
|
||||
const canViewPersonalQuery = hasPermission('view_all_records');
|
||||
const canManageStudents = hasPermission('manage_students');
|
||||
const canManageConduct = hasPermission('manage_conduct');
|
||||
const canExportStudents = hasPermission('export_students');
|
||||
let currentPage = 1;
|
||||
let totalPages = 1;
|
||||
|
||||
@@ -22,30 +25,38 @@ async function loadStudents(page = 1) {
|
||||
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}" class="link">${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>
|
||||
<div class="action-dropdown">
|
||||
<button class="btn btn-sm btn-outline" onclick="showSinglePointsModal(${student.student_id}, '${escapeHtml(student.name)}')">加减分</button>
|
||||
${userRole === '班主任' ? `<button class="btn btn-sm action-dropdown-toggle" onclick="toggleActionDropdown(this)">更多 ▼</button>
|
||||
const detailUrl = canViewPersonalQuery
|
||||
? `/admin/record_query.php?student_id=${student.student_id}`
|
||||
: `/admin/history.php?student_id=${student.student_id}`;
|
||||
const pointsButton = canManageConduct
|
||||
? `<button class="btn btn-sm btn-outline" onclick="showSinglePointsModal(${student.student_id}, '${escapeHtml(student.name)}')">加减分</button>`
|
||||
: '';
|
||||
const moreButton = canManageStudents ? `<button class="btn btn-sm action-dropdown-toggle" onclick="toggleActionDropdown(this)">更多 ▼</button>
|
||||
<div class="action-dropdown-menu">
|
||||
<a onclick="showEditStudentModal(${student.student_id}, '${escapeHtml(student.student_no)}', '${escapeHtml(student.name)}', '${escapeHtml(student.parent_phone || '')}', '${escapeHtml(student.dormitory_number || '')}')">编辑</a>
|
||||
<a onclick="showResetStudentPasswordModal(${student.student_id}, '${escapeHtml(student.name)}')">重置密码</a>
|
||||
<a onclick="unlockStudent('${escapeHtml(student.student_no)}', '${escapeHtml(student.name)}')">解锁</a>
|
||||
<a class="danger" onclick="deleteStudent(${student.student_id}, '${escapeHtml(student.name)}')">删除</a>
|
||||
</div>` : ''}
|
||||
</div>` : '';
|
||||
html += `<tr>
|
||||
<td><input type="checkbox" class="student-checkbox" data-id="${student.student_id}"></td>
|
||||
<td>${escapeHtml(student.student_no)}</td>
|
||||
<td><a href="${detailUrl}" class="link">${escapeHtml(student.name)}</a></td>
|
||||
<td>${escapeHtml(student.dormitory_number || '-')}</td>
|
||||
<td>${student.total_points}</td>
|
||||
${canManageStudents ? `<td>${student.parent_phone ? student.parent_phone.slice(0,3) + '******' + student.parent_phone.slice(-2) : '-'}</td>` : ''}
|
||||
<td>
|
||||
<div class="action-dropdown">
|
||||
${pointsButton}
|
||||
${moreButton}
|
||||
</div>
|
||||
</td>
|
||||
</tr>`;
|
||||
});
|
||||
|
||||
if (res.data.students.length === 0) {
|
||||
html = `<tr><td colspan="${userRole === '班主任' ? '7' : '6'}" style="text-align:center;">暂无学生数据</td></tr>`;
|
||||
const colCount = canManageStudents ? 7 : 6;
|
||||
html = `<tr><td colspan="${colCount}" style="text-align:center;">暂无学生数据</td></tr>`;
|
||||
}
|
||||
|
||||
document.getElementById('studentList').innerHTML = html;
|
||||
@@ -66,6 +77,7 @@ function showSinglePointsModal(studentId, studentName) {
|
||||
document.getElementById('selectedStudentsCount').innerHTML = `${studentName} (1人)`;
|
||||
document.getElementById('pointsChange').value = '';
|
||||
document.getElementById('pointsReason').value = '';
|
||||
if (typeof preparePointsLimitHint === 'function') preparePointsLimitHint();
|
||||
document.getElementById('batchPointsModal').style.display = 'flex';
|
||||
}
|
||||
|
||||
@@ -85,6 +97,83 @@ async function unlockStudent(studentNo, studentName) {
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 导出学生名单 ==========
|
||||
|
||||
const EXPORT_COLUMNS = {
|
||||
student_no: '学号',
|
||||
name: '姓名',
|
||||
dormitory_number: '宿舍号',
|
||||
total_points: '当前操行分',
|
||||
parent_phone: '家长手机号',
|
||||
status: '状态'
|
||||
};
|
||||
|
||||
function showExportStudentsModal() {
|
||||
if (!canExportStudents) {
|
||||
showToast('无导出学生名单权限', 'error');
|
||||
return;
|
||||
}
|
||||
document.getElementById('exportStudentsModal').style.display = 'flex';
|
||||
}
|
||||
|
||||
async function fetchAllStudentsForExport() {
|
||||
const allStudents = [];
|
||||
let page = 1;
|
||||
while (page <= 100) {
|
||||
const res = await apiGet('/api/admin/students', { page: page, page_size: 1000 });
|
||||
if (!res || !res.success || !Array.isArray(res.data.students)) {
|
||||
break;
|
||||
}
|
||||
allStudents.push(...res.data.students);
|
||||
const total = res.data.total || 0;
|
||||
if (allStudents.length >= total || res.data.students.length < 1000) {
|
||||
break;
|
||||
}
|
||||
page++;
|
||||
}
|
||||
return allStudents;
|
||||
}
|
||||
|
||||
async function exportStudents() {
|
||||
if (!canExportStudents) {
|
||||
showToast('无导出学生名单权限', 'error');
|
||||
return;
|
||||
}
|
||||
const checked = Array.from(document.querySelectorAll('.export-student-col:checked')).map(el => el.value);
|
||||
if (checked.length === 0) {
|
||||
showToast('请至少选择一个导出字段', 'warning');
|
||||
return;
|
||||
}
|
||||
const selected = ['student_no', 'name'].filter(v => checked.indexOf(v) === -1).concat(checked);
|
||||
|
||||
showToast('正在导出学生名单...', 'info');
|
||||
|
||||
try {
|
||||
const students = await fetchAllStudentsForExport();
|
||||
if (!students || students.length === 0) {
|
||||
showToast('没有找到学生', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
let csv = selected.map(key => EXPORT_COLUMNS[key]).join(',') + '\n';
|
||||
students.forEach(student => {
|
||||
const row = selected.map(key => {
|
||||
if (key === 'status') {
|
||||
return student.status === 1 ? '正常' : '停用';
|
||||
}
|
||||
return student[key] !== null && student[key] !== undefined ? student[key] : '';
|
||||
});
|
||||
csv += row.map(csvEscape).join(',') + '\n';
|
||||
});
|
||||
|
||||
downloadCsv('学生名单_' + new Date().toISOString().slice(0,10) + '.csv', csv);
|
||||
closeModal('exportStudentsModal');
|
||||
showToast('导出成功,共' + students.length + '名学生');
|
||||
} catch (err) {
|
||||
showToast('导出失败:' + err.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
loadStudents();
|
||||
|
||||
let searchTimeout;
|
||||
@@ -96,5 +185,7 @@ document.getElementById('searchInput').addEventListener('input', () => {
|
||||
window.loadStudents = loadStudents;
|
||||
window.showSinglePointsModal = showSinglePointsModal;
|
||||
window.unlockStudent = unlockStudent;
|
||||
window.showExportStudentsModal = showExportStudentsModal;
|
||||
window.exportStudents = exportStudents;
|
||||
|
||||
})();
|
||||
+80
-1
@@ -76,4 +76,83 @@ date_default_timezone_set('Asia/Shanghai');
|
||||
|
||||
// 生产环境关闭错误显示
|
||||
error_reporting(0);
|
||||
ini_set('display_errors', 0);
|
||||
ini_set('display_errors', 0);
|
||||
|
||||
// ========== 管理员权限(权限组)辅助 ==========
|
||||
|
||||
/**
|
||||
* 从后端同步当前管理员的权限、权限组与加减分上限
|
||||
* 权限变更后最多 60 秒内自动生效
|
||||
*/
|
||||
function refresh_admin_permissions($force = false): void {
|
||||
if (($_SESSION['user_type'] ?? '') !== 'admin') {
|
||||
return;
|
||||
}
|
||||
$lastSync = (int)($_SESSION['permissions_synced_at'] ?? 0);
|
||||
if (!$force && isset($_SESSION['permissions']) && (time() - $lastSync) < 60) {
|
||||
return;
|
||||
}
|
||||
$token = $_SESSION['jwt_token'] ?? '';
|
||||
if (empty($token)) {
|
||||
return;
|
||||
}
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_URL => API_BASE_URL . '/api/auth/me',
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_TIMEOUT => 5,
|
||||
CURLOPT_HTTPHEADER => [
|
||||
'Authorization: Bearer ' . $token,
|
||||
'Content-Type: application/json'
|
||||
],
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_SSL_VERIFYHOST => 0
|
||||
]);
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
if ($httpCode !== 200 || empty($response)) {
|
||||
return;
|
||||
}
|
||||
$data = json_decode($response, true);
|
||||
if (!is_array($data) || empty($data['success']) || empty($data['data'])) {
|
||||
return;
|
||||
}
|
||||
$info = $data['data'];
|
||||
$_SESSION['real_name'] = $info['real_name'] ?? ($_SESSION['real_name'] ?? '');
|
||||
$_SESSION['role'] = $info['role'] ?? '';
|
||||
$_SESSION['permissions'] = is_array($info['permissions'] ?? null) ? $info['permissions'] : [];
|
||||
$_SESSION['group'] = $info['group'] ?? null;
|
||||
$_SESSION['permissions_synced_at'] = time();
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前登录管理员是否拥有指定权限
|
||||
*/
|
||||
function has_perm($perm) {
|
||||
if (($_SESSION['user_type'] ?? '') !== 'admin') {
|
||||
return false;
|
||||
}
|
||||
$permissions = $_SESSION['permissions'] ?? [];
|
||||
return !empty($permissions[$perm]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面守卫:无权限时跳转管理端首页
|
||||
*/
|
||||
function require_perm($perm) {
|
||||
if (!has_perm($perm)) {
|
||||
header('Location: /admin/dashboard.php');
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前权限组名称
|
||||
*/
|
||||
function current_group_name() {
|
||||
return $_SESSION['role'] ?? '';
|
||||
}
|
||||
|
||||
// 管理员页面自动同步权限(权限组变更后自动生效)
|
||||
refresh_admin_permissions();
|
||||
@@ -76,4 +76,29 @@ $page_title = $page_title ?? '首页';
|
||||
})();
|
||||
</script>
|
||||
<script src="/assets/js/common.js"></script>
|
||||
<script src="/assets/js/modules/utils.js"></script>
|
||||
<script src="/assets/js/modules/utils.js"></script>
|
||||
<?php if ($user_type === 'admin'): ?>
|
||||
<script>
|
||||
window.USER_PERMISSIONS = <?php
|
||||
echo json_encode(
|
||||
$_SESSION['permissions'] ?? [],
|
||||
JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT
|
||||
);
|
||||
?>;
|
||||
window.USER_GROUP = <?php
|
||||
echo json_encode(
|
||||
$_SESSION['group'] ?? null,
|
||||
JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT
|
||||
);
|
||||
?>;
|
||||
window.USER_SCORE_LIMITS = <?php
|
||||
$group = $_SESSION['group'] ?? [];
|
||||
echo json_encode([
|
||||
'can_add' => !empty($group['can_add_points']),
|
||||
'max_add' => $group['max_add_points'] ?? null,
|
||||
'can_subtract' => !empty($group['can_subtract_points']),
|
||||
'max_subtract' => $group['max_subtract_points'] ?? null
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
?>;
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
@@ -1,21 +1,22 @@
|
||||
<div class="nav">
|
||||
<a href="/admin/dashboard.php" class="nav-item<?php echo $current_page === 'dashboard' ? ' active' : ''; ?>">首页</a>
|
||||
<a href="/admin/students.php" class="nav-item<?php echo $current_page === 'students' ? ' active' : ''; ?>">学生管理</a>
|
||||
<?php if ($role === '班主任' || $role === '班长' || $role === '学习委员' || $role === '考勤委员' || $role === '劳动委员' || $role === '志愿委员'): ?>
|
||||
<a href="/admin/conduct.php" class="nav-item<?php echo $current_page === 'conduct' ? ' active' : ''; ?>">操行分管理</a>
|
||||
<?php endif; ?>
|
||||
<?php if ($role === '班主任' || $role === '学习委员'): ?>
|
||||
<?php if (has_perm('manage_homework')): ?>
|
||||
<a href="/admin/homework.php" class="nav-item<?php echo $current_page === 'homework' ? ' active' : ''; ?>">作业扣分</a>
|
||||
<?php endif; ?>
|
||||
<?php if ($role === '班主任' || $role === '考勤委员'): ?>
|
||||
<?php if (has_perm('manage_attendance')): ?>
|
||||
<a href="/admin/attendance.php" class="nav-item<?php echo $current_page === 'attendance' ? ' active' : ''; ?>">考勤管理</a>
|
||||
<?php endif; ?>
|
||||
<?php if ($role === '班主任'): ?>
|
||||
<?php if (has_perm('manage_admins')): ?>
|
||||
<a href="/admin/admins.php" class="nav-item<?php echo $current_page === 'admins' ? ' active' : ''; ?>">管理员管理</a>
|
||||
<?php endif; ?>
|
||||
<?php if ($role === '班主任'): ?>
|
||||
<?php if (has_perm('manage_semesters')): ?>
|
||||
<a href="/admin/semesters.php" class="nav-item<?php echo $current_page === 'semesters' ? ' active' : ''; ?>">学期管理</a>
|
||||
<?php endif; ?>
|
||||
<a href="/admin/history.php" class="nav-item<?php echo $current_page === 'history' ? ' active' : ''; ?>">历史记录</a>
|
||||
<?php if (has_perm('view_all_records')): ?>
|
||||
<a href="/admin/record_query.php" class="nav-item<?php echo $current_page === 'record_query' ? ' active' : ''; ?>">个人查询</a>
|
||||
<?php endif; ?>
|
||||
<a href="/admin/password.php" class="nav-item<?php echo $current_page === 'password' ? ' active' : ''; ?>">修改密码</a>
|
||||
</div>
|
||||
Reference in new issue
Block a user