feat: 增加学生信息管理功能,优化操行分历史记录展示并更新使用文档
This commit is contained in:
9
.gitignore
vendored
9
.gitignore
vendored
@@ -43,4 +43,11 @@ Thumbs.db
|
||||
*.bak
|
||||
|
||||
# CoStrict
|
||||
.cospec/
|
||||
.cospec/
|
||||
|
||||
# PDF
|
||||
docs/guide/cadre.pdf
|
||||
docs/guide/parent.pdf
|
||||
docs/guide/student.pdf
|
||||
docs/guide/teacher.pdf
|
||||
qrcode.png
|
||||
@@ -81,7 +81,8 @@ class ConductModel:
|
||||
limit: int = 100,
|
||||
offset: int = 0,
|
||||
start_date: str = None,
|
||||
end_date: str = None
|
||||
end_date: str = None,
|
||||
student_id: int = None
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""获取所有记录(班主任/班长专用)"""
|
||||
# 空字符串转为None
|
||||
@@ -99,7 +100,9 @@ class ConductModel:
|
||||
"""
|
||||
params = []
|
||||
|
||||
# 单班级系统,无需 class_id 过滤
|
||||
if student_id:
|
||||
sql += " AND cr.student_id = %s"
|
||||
params.append(student_id)
|
||||
|
||||
if start_date:
|
||||
sql += " AND DATE(cr.created_at) >= %s"
|
||||
@@ -114,6 +117,73 @@ class ConductModel:
|
||||
|
||||
return await execute_query(sql, tuple(params))
|
||||
|
||||
@staticmethod
|
||||
async def get_grouped_records(
|
||||
student_id: int = None,
|
||||
start_date: str = None,
|
||||
end_date: str = None,
|
||||
page: int = 1,
|
||||
page_size: int = 20
|
||||
) -> Dict[str, Any]:
|
||||
"""获取分组后的操行分记录(同批次合并)"""
|
||||
if start_date == "":
|
||||
start_date = None
|
||||
if end_date == "":
|
||||
end_date = None
|
||||
|
||||
conditions = ["cr.is_revoked = 0"]
|
||||
params = []
|
||||
|
||||
if student_id:
|
||||
conditions.append("cr.student_id = %s")
|
||||
params.append(student_id)
|
||||
if start_date:
|
||||
conditions.append("cr.created_at >= %s")
|
||||
params.append(start_date)
|
||||
if end_date:
|
||||
conditions.append("cr.created_at <= %s")
|
||||
params.append(end_date + ' 23:59:59')
|
||||
|
||||
where_clause = " AND ".join(conditions)
|
||||
|
||||
count_sql = f"""
|
||||
SELECT COUNT(DISTINCT CONCAT(cr.points_change, '|', cr.reason, '|', cr.recorder_id, '|', DATE_FORMAT(cr.created_at, '%Y-%m-%d %H:%i'))) as total
|
||||
FROM conduct_records cr
|
||||
WHERE {where_clause}
|
||||
"""
|
||||
|
||||
data_sql = f"""
|
||||
SELECT
|
||||
cr.points_change,
|
||||
cr.reason,
|
||||
cr.recorder_name,
|
||||
DATE_FORMAT(MIN(cr.created_at), '%Y-%m-%d %H:%i:%s') as created_at,
|
||||
GROUP_CONCAT(s.name ORDER BY s.student_id SEPARATOR ', ') as student_names,
|
||||
COUNT(*) as student_count
|
||||
FROM conduct_records cr
|
||||
JOIN students s ON cr.student_id = s.student_id
|
||||
WHERE {where_clause}
|
||||
GROUP BY cr.points_change, cr.reason, cr.recorder_id, DATE_FORMAT(cr.created_at, '%Y-%m-%d %H:%i')
|
||||
ORDER BY MIN(cr.created_at) DESC
|
||||
LIMIT %s OFFSET %s
|
||||
"""
|
||||
|
||||
params_for_count = list(params)
|
||||
params_for_data = list(params) + [page_size, (page - 1) * page_size]
|
||||
|
||||
total_result = await execute_one(count_sql, tuple(params_for_count))
|
||||
total = total_result['total'] if total_result else 0
|
||||
|
||||
records = await execute_query(data_sql, tuple(params_for_data))
|
||||
|
||||
return {
|
||||
"records": records,
|
||||
"total": total,
|
||||
"page": page,
|
||||
"page_size": page_size,
|
||||
"total_pages": (total + page_size - 1) // page_size
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
async def get_record_by_id(record_id: int) -> Optional[Dict[str, Any]]:
|
||||
"""根据ID获取记录"""
|
||||
|
||||
@@ -25,7 +25,7 @@ from services.attendance_service import AttendanceService
|
||||
from services.log_service import LogService
|
||||
from schemas.admin import (
|
||||
AddPointsRequest, RevokeRequest, AddAdminRequest,
|
||||
AddStudentRequest,
|
||||
AddStudentRequest, UpdateStudentRequest,
|
||||
UpdateHomeworkStatusRequest, AddAttendanceRequest,
|
||||
UpdateAdminRequest, DeleteAdminRequest, ResetPasswordRequest
|
||||
)
|
||||
@@ -124,6 +124,58 @@ async def add_student(request: Request, req: AddStudentRequest):
|
||||
return error_response(message=result["message"])
|
||||
|
||||
|
||||
@router.put("/students/{student_id}")
|
||||
async def update_student(request: Request, student_id: int, req: UpdateStudentRequest):
|
||||
"""编辑学生信息(班主任)"""
|
||||
user = await get_current_user(request)
|
||||
is_teacher = await PermissionChecker.check_is_teacher(user["user_id"])
|
||||
if not is_teacher:
|
||||
return error_response(message="仅班主任可编辑学生信息", code=403)
|
||||
|
||||
result = await AdminService.update_student(
|
||||
student_id=student_id,
|
||||
name=req.name,
|
||||
parent_phone=req.parent_phone
|
||||
)
|
||||
if result["success"]:
|
||||
return success_response(message=result["message"])
|
||||
else:
|
||||
return error_response(message=result["message"])
|
||||
|
||||
|
||||
@router.delete("/students/{student_id}")
|
||||
async def delete_student(request: Request, student_id: int):
|
||||
"""删除学生(班主任)"""
|
||||
user = await get_current_user(request)
|
||||
is_teacher = await PermissionChecker.check_is_teacher(user["user_id"])
|
||||
if not is_teacher:
|
||||
return error_response(message="仅班主任可删除学生", code=403)
|
||||
|
||||
result = await AdminService.delete_student(student_id=student_id)
|
||||
if result["success"]:
|
||||
return success_response(message=result["message"])
|
||||
else:
|
||||
return error_response(message=result["message"])
|
||||
|
||||
|
||||
@router.post("/students/reset-password/{student_id}")
|
||||
async def reset_student_password(request: Request, student_id: int, req: ResetPasswordRequest):
|
||||
"""重置学生密码(班主任)"""
|
||||
user = await get_current_user(request)
|
||||
is_teacher = await PermissionChecker.check_is_teacher(user["user_id"])
|
||||
if not is_teacher:
|
||||
return error_response(message="仅班主任可重置学生密码", code=403)
|
||||
|
||||
result = await AdminService.reset_student_password(
|
||||
student_id=student_id,
|
||||
new_password=req.new_password
|
||||
)
|
||||
if result["success"]:
|
||||
return success_response(message=result["message"])
|
||||
else:
|
||||
return error_response(message=result["message"])
|
||||
|
||||
|
||||
# ========== 操行分管理 ==========
|
||||
|
||||
@router.post("/conduct/add")
|
||||
@@ -186,7 +238,8 @@ async def get_conduct_history(
|
||||
page: int = Query(1, ge=1),
|
||||
page_size: int = Query(20, ge=1, le=1000),
|
||||
start_date: Optional[str] = None,
|
||||
end_date: Optional[str] = None
|
||||
end_date: Optional[str] = None,
|
||||
grouped: bool = Query(False)
|
||||
):
|
||||
"""获取操行分历史记录"""
|
||||
try:
|
||||
@@ -197,7 +250,8 @@ async def get_conduct_history(
|
||||
page=page,
|
||||
page_size=page_size,
|
||||
start_date=start_date,
|
||||
end_date=end_date
|
||||
end_date=end_date,
|
||||
grouped=grouped
|
||||
)
|
||||
return success_response(data=result)
|
||||
except Exception as e:
|
||||
|
||||
@@ -102,4 +102,10 @@ class DeleteAdminRequest(BaseModel):
|
||||
|
||||
class ResetPasswordRequest(BaseModel):
|
||||
"""重置密码请求"""
|
||||
new_password: str = Field(..., min_length=6, max_length=50, description="新密码")
|
||||
new_password: str = Field(..., min_length=6, max_length=50, description="新密码")
|
||||
|
||||
|
||||
class UpdateStudentRequest(BaseModel):
|
||||
"""更新学生请求"""
|
||||
name: Optional[str] = Field(None, min_length=1, max_length=50, description="姓名")
|
||||
parent_phone: Optional[str] = Field(None, max_length=20, description="家长手机号")
|
||||
@@ -10,7 +10,7 @@
|
||||
# ===========================================
|
||||
|
||||
from typing import Dict, Any, List, Optional
|
||||
from utils.database import execute_query, execute_one
|
||||
from utils.database import execute_query, execute_one, execute_update
|
||||
from models.user import UserModel
|
||||
from models.student import StudentModel
|
||||
from models.admin_role import AdminRoleModel
|
||||
@@ -245,4 +245,67 @@ class AdminService:
|
||||
async def get_admins() -> Dict[str, Any]:
|
||||
"""获取管理员列表"""
|
||||
admins = await AdminRoleModel.get_all()
|
||||
return {"admins": admins}
|
||||
return {"admins": admins}
|
||||
|
||||
@staticmethod
|
||||
async def update_student(student_id: int, name: str = None, parent_phone: str = None) -> Dict[str, Any]:
|
||||
"""编辑学生信息"""
|
||||
try:
|
||||
student = await StudentModel.get_by_id(student_id)
|
||||
if not student:
|
||||
return {"success": False, "message": "学生不存在"}
|
||||
|
||||
result = await StudentModel.update(student_id, name=name, parent_phone=parent_phone)
|
||||
if result:
|
||||
return {"success": True, "message": "学生信息更新成功"}
|
||||
return {"success": False, "message": "更新失败"}
|
||||
except Exception as e:
|
||||
logger.error(f"更新学生信息失败: {e}")
|
||||
return {"success": False, "message": f"更新失败: {str(e)}"}
|
||||
|
||||
@staticmethod
|
||||
async def delete_student(student_id: int) -> Dict[str, Any]:
|
||||
"""删除学生(软删除)"""
|
||||
try:
|
||||
student = await StudentModel.get_by_id(student_id)
|
||||
if not student:
|
||||
return {"success": False, "message": "学生不存在"}
|
||||
|
||||
result = await StudentModel.delete(student_id)
|
||||
if result:
|
||||
user = await execute_one(
|
||||
"SELECT user_id FROM users WHERE student_id = %s AND user_type = 'student'",
|
||||
(student_id,)
|
||||
)
|
||||
if user:
|
||||
await UserModel.update_status(user['user_id'], 0)
|
||||
return {"success": True, "message": "学生删除成功"}
|
||||
return {"success": False, "message": "删除失败"}
|
||||
except Exception as e:
|
||||
logger.error(f"删除学生失败: {e}")
|
||||
return {"success": False, "message": f"删除失败: {str(e)}"}
|
||||
|
||||
@staticmethod
|
||||
async def reset_student_password(student_id: int, new_password: str) -> Dict[str, Any]:
|
||||
"""重置学生密码"""
|
||||
try:
|
||||
user = await execute_one(
|
||||
"SELECT user_id FROM users WHERE student_id = %s AND user_type = 'student'",
|
||||
(student_id,)
|
||||
)
|
||||
if not user:
|
||||
return {"success": False, "message": "未找到对应的用户账号"}
|
||||
|
||||
password_hash = security.sha1_md5_password(new_password)
|
||||
|
||||
result = await UserModel.update_password(user['user_id'], password_hash)
|
||||
if result:
|
||||
await execute_update(
|
||||
"UPDATE users SET need_change_password = 1 WHERE user_id = %s",
|
||||
(user['user_id'],)
|
||||
)
|
||||
return {"success": True, "message": "密码重置成功"}
|
||||
return {"success": False, "message": "密码重置失败"}
|
||||
except Exception as e:
|
||||
logger.error(f"重置学生密码失败: {e}")
|
||||
return {"success": False, "message": f"重置失败: {str(e)}"}
|
||||
@@ -159,7 +159,8 @@ class ConductService:
|
||||
page: int = 1,
|
||||
page_size: int = 20,
|
||||
start_date: Optional[str] = None,
|
||||
end_date: Optional[str] = None
|
||||
end_date: Optional[str] = None,
|
||||
grouped: bool = False
|
||||
) -> Dict[str, Any]:
|
||||
"""获取历史记录"""
|
||||
# 空字符串转为None
|
||||
@@ -173,21 +174,43 @@ class ConductService:
|
||||
|
||||
# 班主任/班长/志愿委员可查看全班
|
||||
if role in ["班主任", "班长", "志愿委员"]:
|
||||
if grouped:
|
||||
return await ConductModel.get_grouped_records(
|
||||
student_id=student_id,
|
||||
start_date=start_date,
|
||||
end_date=end_date,
|
||||
page=page,
|
||||
page_size=page_size
|
||||
)
|
||||
|
||||
records = await ConductModel.get_all_records(
|
||||
limit=page_size,
|
||||
offset=offset,
|
||||
start_date=start_date,
|
||||
end_date=end_date
|
||||
end_date=end_date,
|
||||
student_id=student_id
|
||||
)
|
||||
|
||||
# 获取总数
|
||||
from utils.database import execute_one
|
||||
count_sql = """
|
||||
count_conditions = ["cr.is_revoked = 0"]
|
||||
count_params = []
|
||||
if student_id:
|
||||
count_conditions.append("cr.student_id = %s")
|
||||
count_params.append(student_id)
|
||||
if start_date:
|
||||
count_conditions.append("DATE(cr.created_at) >= %s")
|
||||
count_params.append(start_date)
|
||||
if end_date:
|
||||
count_conditions.append("DATE(cr.created_at) <= %s")
|
||||
count_params.append(end_date)
|
||||
count_where = " AND ".join(count_conditions)
|
||||
count_sql = f"""
|
||||
SELECT COUNT(*) as total FROM conduct_records cr
|
||||
JOIN students s ON cr.student_id = s.student_id
|
||||
WHERE cr.is_revoked = 0
|
||||
WHERE {count_where}
|
||||
"""
|
||||
total_result = await execute_one(count_sql)
|
||||
total_result = await execute_one(count_sql, tuple(count_params))
|
||||
total = total_result["total"] if total_result else 0
|
||||
|
||||
elif student_id:
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# 班干部使用说明
|
||||
|
||||
## 登录网址
|
||||
|
||||

|
||||
|
||||
### 或访问https://class.sea-studio.top/
|
||||
|
||||
## 登录
|
||||
|
||||
输入**用户名**和**密码**登录。首次登录需强制修改密码。
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# 家长端使用说明
|
||||
|
||||
## 登录网址
|
||||
|
||||

|
||||
|
||||
### 或访问https://class.sea-studio.top/
|
||||
|
||||
## 登录
|
||||
|
||||
输入**手机号**和**密码**登录。账号由系统自动创建,与子女信息关联。
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# 学生端使用说明
|
||||
|
||||
## 登录网址
|
||||
|
||||

|
||||
|
||||
### 或访问https://class.sea-studio.top/
|
||||
|
||||
## 登录
|
||||
|
||||
输入**长学号**和**密码**登录。首次登录需强制修改密码。
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# 班主任使用说明
|
||||
|
||||
## 登录网址
|
||||
|
||||

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