From 3a9abf83b8786fa0db676db8b47a7ae7a56c0a2b Mon Sep 17 00:00:00 2001 From: canglan Date: Mon, 20 Apr 2026 09:54:26 +0800 Subject: [PATCH] =?UTF-8?q?v1.1=E6=9B=B4=E6=96=B0=E5=AE=B6=E9=95=BF?= =?UTF-8?q?=E7=AB=AF=E5=8F=AF=E6=9F=A5=E7=9C=8B=E5=8E=86=E5=8F=B2=E8=AE=B0?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +- backend/routes/parent.py | 44 +++++++++++ backend/services/parent_service.py | 66 +++++++++++++++- docs/parent.md | 26 +++++-- frontend/.env.example | 5 +- frontend/config.php | 3 + frontend/includes/footer.php | 2 +- frontend/includes/header.php | 1 + frontend/parent/attendance.php | 1 + frontend/parent/dashboard.php | 33 ++++++-- frontend/parent/history.php | 118 +++++++++++++++++++++++++++++ 11 files changed, 289 insertions(+), 16 deletions(-) create mode 100644 frontend/parent/history.php diff --git a/README.md b/README.md index 2c6b83e..2518d6b 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,8 @@ - 修改个人登录密码(首次登录强制修改) ### 家长端 -- 查询子女当前操行总分 +- 查询子女当前操行总分和班级排名 +- 查看子女操行分历史记录(加分/减分明细) - 查看子女考勤记录 ### 管理端 @@ -169,7 +170,8 @@ classmanager/ │ │ │ ├── parent/ # 家长端 │ │ ├── attendance.php # 考勤记录 -│ │ └── dashboard.php # 家长端首页 +│ │ ├── dashboard.php # 家长端首页 +│ │ └── history.php # 历史记录 │ │ │ └── student/ # 学生端 │ ├── attendance.php # 考勤记录 diff --git a/backend/routes/parent.py b/backend/routes/parent.py index 6074c7e..f1598e0 100644 --- a/backend/routes/parent.py +++ b/backend/routes/parent.py @@ -63,4 +63,48 @@ async def get_child_attendance(request: Request): result = await ParentService.get_child_attendance(user["user_id"]) + return success_response(data=result) + + +@router.get("/child/ranking") +async def get_child_ranking(request: Request): + """ + 获取子女排名信息 + """ + user = await get_current_user(request) + + if user["user_type"] != "parent": + return error_response(message="仅限家长访问", code=403) + + result = await ParentService.get_child_ranking(user["user_id"]) + + if "error" in result: + return error_response(message=result["error"], code=400) + + return success_response(data=result) + + +@router.get("/child/history") +async def get_child_history( + request: Request, + page: int = Query(1, ge=1), + page_size: int = Query(20, ge=1, le=100) +): + """ + 获取子女操行分历史记录 + """ + user = await get_current_user(request) + + if user["user_type"] != "parent": + return error_response(message="仅限家长访问", code=403) + + result = await ParentService.get_child_history( + parent_id=user["user_id"], + page=page, + page_size=page_size + ) + + if "error" in result: + return error_response(message=result["error"], code=400) + return success_response(data=result) \ No newline at end of file diff --git a/backend/services/parent_service.py b/backend/services/parent_service.py index 48c1013..1e01a13 100644 --- a/backend/services/parent_service.py +++ b/backend/services/parent_service.py @@ -9,7 +9,7 @@ # 版权所有 © Sea Network Technology Studio # =========================================== -from typing import Dict, Any, Optional +from typing import Dict, Any, Optional, List from models.user import UserModel from models.student import StudentModel @@ -61,7 +61,6 @@ class ParentService: "student_name": student["name"], "homework": homework } - @staticmethod async def get_child_attendance(parent_id: int) -> Dict[str, Any]: """获取子女考勤记录""" @@ -79,4 +78,67 @@ class ParentService: "student_id": student["student_id"], "student_name": student["name"], "records": records + } + + @staticmethod + async def get_child_ranking(parent_id: int) -> Dict[str, Any]: + """获取子女排名信息""" + user = await UserModel.get_by_user_id(parent_id) + if not user or not user["student_id"]: + return {"error": "未关联学生"} + + student = await StudentModel.get_by_id(user["student_id"]) + if not student: + return {"error": "学生不存在"} + + # 获取全班排名 + ranking = await StudentModel.get_ranking(limit=1000) + + # 查找当前学生排名 + student_rank = None + total_students = 0 + for r in ranking: + total_students += 1 + if r["student_id"] == user["student_id"]: + student_rank = r["rank"] + + return { + "student_id": student["student_id"], + "student_name": student["name"], + "student_no": student["student_no"], + "total_points": student["total_points"], + "rank": student_rank, + "total_students": total_students + } + + @staticmethod + async def get_child_history(parent_id: int, page: int = 1, page_size: int = 20) -> Dict[str, Any]: + """获取子女操行分历史记录""" + user = await UserModel.get_by_user_id(parent_id) + if not user or not user["student_id"]: + return {"error": "未关联学生"} + + student = await StudentModel.get_by_id(user["student_id"]) + if not student: + return {"error": "学生不存在"} + + offset = (page - 1) * page_size + records = await ConductModel.get_student_records( + student_id=user["student_id"], + limit=page_size, + offset=offset + ) + + # 获取总数 + all_records = await ConductModel.get_student_records(user["student_id"], limit=10000) + total = len(all_records) + + return { + "student_id": student["student_id"], + "student_name": student["name"], + "total_points": student["total_points"], + "records": records, + "total": total, + "page": page, + "page_size": page_size } \ No newline at end of file diff --git a/docs/parent.md b/docs/parent.md index e886a9d..6b31173 100644 --- a/docs/parent.md +++ b/docs/parent.md @@ -24,13 +24,28 @@ | 子女姓名 | 显示关联学生的姓名 | | 学号 | 显示关联学生的学号 | | 当前操行分 | 显示子女当前的总操行分 | +| 班级排名 | 显示子女在全班的排名 | -页面顶部以紫色渐变卡片展示子女基本信息,下方大字号显示当前操行分。 +页面顶部以紫色渐变卡片展示子女基本信息,下方以统计卡片形式展示操行分和班级排名,底部提示初始操行分值。 -### 2. 考勤记录 +### 2. 历史记录 + +查看子女的操行分历史明细: + +- 按时间显示操行分变动记录 +- 每条记录包含: + - 日期时间 + - 类型(手动/考勤/作业等) + - 原因 + - 分值变动(加分绿色、减分红色) + - 记录人 +- 支持分页浏览 + +### 3. 考勤记录 查看子女的考勤记录: +- 顶部统计卡片显示出勤、缺勤、迟到、请假次数 - 按日期显示考勤记录列表 - 每条记录包含: - 日期 @@ -45,7 +60,8 @@ | 导航项 | 页面 | 说明 | |-------|------|------| -| 首页 | /parent/dashboard.php | 子女信息和操行分概览 | +| 首页 | /parent/dashboard.php | 子女信息、操行分和排名概览 | +| 历史记录 | /parent/history.php | 子女操行分变动历史明细 | | 考勤记录 | /parent/attendance.php | 子女考勤记录明细 | --- @@ -55,5 +71,5 @@ ### Q: 忘记密码怎么办? 请联系班主任重置密码。 -### Q: 为什么只能看到总分,看不到加减分详情? -家长端目前仅展示子女的总操行分,如需了解详细加减分情况,请联系班主任或通过学生端查看。 +### Q: 初始操行分是多少? +学生初始操行分默认为60分,可在系统配置中调整。首页底部会显示当前系统的初始分设定值。 diff --git a/frontend/.env.example b/frontend/.env.example index 9c8c244..1d76873 100644 --- a/frontend/.env.example +++ b/frontend/.env.example @@ -49,4 +49,7 @@ DEDUCTION_ATTENDANCE_ABSENT=5 # 考勤-迟到扣分 DEDUCTION_ATTENDANCE_LATE=2 # 考勤-请假扣分 -DEDUCTION_ATTENDANCE_LEAVE=1 \ No newline at end of file +DEDUCTION_ATTENDANCE_LEAVE=1 + +# 学生初始操行分 +STUDENT_INITIAL_POINTS=60 \ No newline at end of file diff --git a/frontend/config.php b/frontend/config.php index 0345fc8..6b7ec58 100644 --- a/frontend/config.php +++ b/frontend/config.php @@ -69,6 +69,9 @@ define('DEDUCTION_ATTENDANCE_ABSENT', (int)($config['DEDUCTION_ATTENDANCE_ABSENT define('DEDUCTION_ATTENDANCE_LATE', (int)($config['DEDUCTION_ATTENDANCE_LATE'] ?? 2)); define('DEDUCTION_ATTENDANCE_LEAVE', (int)($config['DEDUCTION_ATTENDANCE_LEAVE'] ?? 1)); +// 学生初始操行分 +define('STUDENT_INITIAL_POINTS', (int)($config['STUDENT_INITIAL_POINTS'] ?? 60)); + // 会话配置 ini_set('session.cookie_httponly', 1); ini_set('session.use_only_cookies', 1); diff --git a/frontend/includes/footer.php b/frontend/includes/footer.php index b439e77..cc46a9e 100644 --- a/frontend/includes/footer.php +++ b/frontend/includes/footer.php @@ -11,7 +11,7 @@ */ ?> \ No newline at end of file diff --git a/frontend/includes/header.php b/frontend/includes/header.php index c5d819b..8181285 100644 --- a/frontend/includes/header.php +++ b/frontend/includes/header.php @@ -51,5 +51,6 @@ $page_title = $page_title ?? '首页'; window.DEDUCTION_ATTENDANCE_ABSENT = ; window.DEDUCTION_ATTENDANCE_LATE = ; window.DEDUCTION_ATTENDANCE_LEAVE = ; + window.STUDENT_INITIAL_POINTS = ; \ No newline at end of file diff --git a/frontend/parent/attendance.php b/frontend/parent/attendance.php index 60abc3a..78bd1af 100644 --- a/frontend/parent/attendance.php +++ b/frontend/parent/attendance.php @@ -23,6 +23,7 @@ include __DIR__ . '/../includes/header.php'; diff --git a/frontend/parent/dashboard.php b/frontend/parent/dashboard.php index 7b8a90d..ad8f071 100644 --- a/frontend/parent/dashboard.php +++ b/frontend/parent/dashboard.php @@ -23,6 +23,7 @@ include __DIR__ . '/../includes/header.php'; @@ -31,12 +32,17 @@ include __DIR__ . '/../includes/header.php';
--
--
-
-
-
--
-
当前操行分
+
+
+
当前操行分
+
--
+
+
+
班级排名
+
--
+
diff --git a/frontend/parent/history.php b/frontend/parent/history.php new file mode 100644 index 0000000..94778b8 --- /dev/null +++ b/frontend/parent/history.php @@ -0,0 +1,118 @@ + + + + +
+
+
操行分历史记录
+
+ + + + + + + + + + + + + +
日期类型原因分值记录人
加载中...
+
+ +
+
+ + + + + + +