From 9b85fcff63fffc8be2c7502c7055c841866c9ed6 Mon Sep 17 00:00:00 2001 From: 30404 <3040471803@qq.com> Date: Wed, 26 Jun 2024 11:24:33 +0800 Subject: [PATCH 1/3] http://localhost:3000/classID/202401 --- .../TeacherPages/classlistpages/classId.jsx | 284 ++++++++++-------- .../TeacherPages/classlistpages/classid.css | 2 - .../src/TeacherPages/list_pods/List_pods.jsx | 3 +- python/app.py | 9 +- python/teacher_func.py | 2 +- 5 files changed, 168 insertions(+), 132 deletions(-) diff --git a/app-dm/src/TeacherPages/classlistpages/classId.jsx b/app-dm/src/TeacherPages/classlistpages/classId.jsx index 33f7a0d..682c15d 100644 --- a/app-dm/src/TeacherPages/classlistpages/classId.jsx +++ b/app-dm/src/TeacherPages/classlistpages/classId.jsx @@ -1,135 +1,169 @@ -import { useParams } from 'react-router-dom'; -import { Link } from 'react-router-dom'; -import React, { useEffect, useState } from 'react'; -import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip } from 'recharts'; -import axios from 'axios'; -import './classid.css' + import { useParams } from 'react-router-dom'; + import { Link } from 'react-router-dom'; + import React, { useEffect, useState } from 'react'; + import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip } from 'recharts'; + import axios from 'axios'; + import './classid.css' -function TeacherPage() { - const click=()=>{ - console.log(TestScore); - } - const teacher_ID=localStorage.getItem('islogin') - if(teacher_ID==null){ - alert('登录过期,请重新登录') - window.location.href='http://36.138.114.105:30294/' - } - const { key } = useParams(); - const [isclick,setisclick]=useState(false) - //学生表格 - const [classdata,setClassData]=useState([]) - const class_succeed = async () => { - try{ - const class_scr=await axios.post('/api/teacher/find_student',{key}) - const class_data=class_scr.data - setClassData(class_data[1]) - setisclick(true) - }catch(error){ - alert(error) + function TeacherPage() { + const [selectedSubject, setSelectedSubject] = useState(); + const [ID,setID]=useState(null) + const[TestScore,setTestScore]=useState([]) + const { key } = useParams(); + const [isclick,setisclick]=useState(false) + const [classdata,setClassData]=useState([]) + const [studentScores, setStudentScores] = useState([]) + const [name,setname]=useState('') + + const click=()=>{ + console.log(studentScores); } - } - useState(()=>{ - class_succeed(); - },[]) - - //柱形图 - const [studentScores, setStudentScores] = useState([]); - - useEffect(() => { - class_succeed().then(() => { - const scores = classdata.map(student => ({ - name: 11.26, // 学生姓名 - score:10, // 学生分数 - })); - setStudentScores(scores); - }); - }, [isclick]); - - function formatDate(dateString) { - // 将日期字符串转换为 Date 对象 - const date = new Date(dateString); - // 获取年份、月份和日期 - const year = date.getFullYear(); - const monthIndex = date.getMonth(); - const day = date.getDate(); - - // 构建格式化后的日期字符串 - const formattedDate = `${year}-${(monthIndex + 1).toString().padStart(2, '0')}-${day.toString().padStart(2, '0')}`; - return formattedDate; - } - const[TestScore,setTestScore]=useState() - const Find_details=async (ID)=>{ - try{ - const Find_details_Src=await axios.post('api/Find_details',{ - ID - }) - setTestScore(Find_details_Src.data) - }catch{ - alert('Find_details出错') + const teacher_ID=localStorage.getItem('islogin') + if(teacher_ID==null){ + alert('登录过期,请重新登录') + window.location.href='http://36.138.114.105:30294/' } - } + + //学生表格 + + const class_succeed = async () => { + try{ + const class_scr=await axios.post('/api/teacher/find_student',{key}) + const class_data=class_scr.data + setClassData(class_data[1]) + setisclick(true) + }catch(error){ + alert(error) + } + } + useState(()=>{ + class_succeed(); + },[]) - return( -
-
-

班级信息

-
-
-

- 班级 - 姓名 - 学号 - 性别 - 联系电话 - 出生日期 - 查看详情 -

+ useEffect(() => { + class_succeed().then(() => { + const scores = []; + // 遍历 TestScore 对象的每个值 + for (const studentId in TestScore) { + // 如果当前学生的信息数组没有被跳过,则对其做进一步处理 + if (TestScore.hasOwnProperty(studentId)) { + const studentInfo = TestScore[studentId]; + // 检查当前学生的信息数组是否符合特定的科目要求 + if (studentInfo[2] === selectedSubject) { + // 只有当学生信息数组的第3个元素(科目)等于"Chinese"时,才添加到 scores 数组中 + scores.push({ + name: studentInfo[3], // 假设姓名总是位于数组的第4个位置 + score: studentInfo[5], // 假设分数总是位于数组的第6个位置 + }); + } + } + } + setStudentScores(scores); + }); + }, [selectedSubject]); + + function formatDate(dateString) { + // 将日期字符串转换为 Date 对象 + const date = new Date(dateString); + // 获取年份、月份和日期 + const year = date.getFullYear(); + const monthIndex = date.getMonth(); + const day = date.getDate(); + + // 构建格式化后的日期字符串 + const formattedDate = `${year}-${(monthIndex + 1).toString().padStart(2, '0')}-${day.toString().padStart(2, '0')}`; + return formattedDate; + } + + const Find_details= async ()=>{ + if(ID!==null){ + try{ + const Find_details_Src = await axios.post('/api/teacher/Find_details',{ + ID + }) + setTestScore(Find_details_Src.data['TestScore']) + setStudentScores([]) + }catch{ + alert('Find_details') + } + } + } + useEffect(()=>{ + Find_details() + const sltvalue=document.getElementById('selectvalue') + sltvalue.value='' + },[ID]) + + function handleSubjectChange(event) { + setSelectedSubject(event.target.value); + } + + const handleClick = (item) => { + setID(classdata[item][1]); + setname(classdata[item][0]); + }; + + return( +
+
+

班级信息

+
+
+

+ 班级 + 姓名 + 学号 + 性别 + 联系电话 + 出生日期 + 查看详情 +

+
+
+ + + {Object.keys(classdata).map((item)=>( + + + + + + + + + + ))} + +
{classdata[item][2]}{classdata[item][0]}{classdata[item][1]}{classdata[item][3]}{classdata[item][5]}{formatDate(classdata[item][4])}
+
-
- - - {Object.keys(classdata).map((item)=>( - - - - - - - - - - ))} - -
{classdata[item][2]}{classdata[item][0]}{classdata[item][1]}{classdata[item][3]}{classdata[item][5]}{formatDate(classdata[item][4])}
+
+
+

成绩

+
+ {name&&
已选中{name}
} + + +
+ + + + + + + +
-
-

成绩

-
-
名字
- - -
- - - - - - - -
-
-
-
- ) -} -export default TeacherPage; \ No newline at end of file + ) + } + export default TeacherPage; \ No newline at end of file diff --git a/app-dm/src/TeacherPages/classlistpages/classid.css b/app-dm/src/TeacherPages/classlistpages/classid.css index 6b95246..10f0a82 100644 --- a/app-dm/src/TeacherPages/classlistpages/classid.css +++ b/app-dm/src/TeacherPages/classlistpages/classid.css @@ -102,7 +102,5 @@ .studentName{ margin-top: 20px; font-size: 18px; - width: 72px; margin-left: 50px; - border: 1px solid black; } \ No newline at end of file diff --git a/app-dm/src/TeacherPages/list_pods/List_pods.jsx b/app-dm/src/TeacherPages/list_pods/List_pods.jsx index 9822453..7588fba 100644 --- a/app-dm/src/TeacherPages/list_pods/List_pods.jsx +++ b/app-dm/src/TeacherPages/list_pods/List_pods.jsx @@ -2,4 +2,5 @@ function List_pods(){ return(
) -} \ No newline at end of file +} +export default List_pods \ No newline at end of file diff --git a/python/app.py b/python/app.py index 4dedab1..1b9c438 100644 --- a/python/app.py +++ b/python/app.py @@ -231,10 +231,13 @@ def SendTrainTest(): return '发布成功' -@app.route('/api/Find_details',methods=["POST"]) +@app.route('/api/teacher/Find_details',methods=["POST"]) def Find_details(): - id=request.json['student_ID'] - return Find_details(id) + data=request.json + ID=data['ID'] + result=Find_details_Func(ID) + print(result) + return jsonify({'TestScore':result}) @app.route('/') diff --git a/python/teacher_func.py b/python/teacher_func.py index 10e6516..567a9fc 100644 --- a/python/teacher_func.py +++ b/python/teacher_func.py @@ -269,7 +269,7 @@ def SendTrainTestFunc(TrainChoice,TrainCompletion,TrainJudge,Hour,Min,StopTime,C # return dic_last_three # 返回一个新字典,该字典仅包含排序后的最后三个键及其对应的值 -def Find_details(ID): +def Find_details_Func(ID): dic = {} cursor = db.cursor() cursor.execute(f"SELECT * FROM STUDENT_TEST WHERE STUDENT_ID=? AND TF='true' ", (ID)) From f32368661bdf8c1b498f3bf8cf877be4f959f744 Mon Sep 17 00:00:00 2001 From: 30404 <3040471803@qq.com> Date: Wed, 26 Jun 2024 14:20:24 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=B7=AF=E7=94=B1=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app-dm/src/TeacherPages/Trainmanage/Trainmanage.jsx | 2 +- app-dm/src/router/index.jsx | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app-dm/src/TeacherPages/Trainmanage/Trainmanage.jsx b/app-dm/src/TeacherPages/Trainmanage/Trainmanage.jsx index 710e03f..ba9bb51 100644 --- a/app-dm/src/TeacherPages/Trainmanage/Trainmanage.jsx +++ b/app-dm/src/TeacherPages/Trainmanage/Trainmanage.jsx @@ -1,4 +1,4 @@ -import './trainmanage.css' +import './Trainmanage.css' import { Link } from 'react-router-dom'; // import React, { useEffect, useState } from 'react'; // import axios from 'axios'; diff --git a/app-dm/src/router/index.jsx b/app-dm/src/router/index.jsx index f5b8a62..2e7bf53 100755 --- a/app-dm/src/router/index.jsx +++ b/app-dm/src/router/index.jsx @@ -21,8 +21,8 @@ import ClassID from '../TeacherPages/classlistpages/classId'; import ManageTest from '../TeacherPages/TestManage/ManageTest'; import SendTest from '../TeacherPages/TestManage/SendTest'; import Marking from '../TeacherPages/MarkingPages/Marking'; -import SendTrain from '../TeacherPages/TrainManage/SendTrain'; -import TrainManage from '../TeacherPages/TrainManage/trainmanage'; +import SendTrain from '../TeacherPages/Trainmanage/SendTrain'; +import TrainManage from '../TeacherPages/Trainmanage/Trainmanage'; import StudentLink from '../TeacherPages/MarkingPages/StudentLink'; // 定义一个组件来包裹除了特定页面(exam)外的所有页面使其有导航 @@ -70,7 +70,7 @@ function App() { {/* 页面使用单独的布局,不包含HeaderNav和HeaderNavTeacher */} } />{/* 练习-考试页面 */} }/> {/* 考试管理-发布试卷 */} - }/> {/* 实训管理-发布实训 */} + }/> {/*实训管理-发布实训*/} }/> {/* 实训页面1 */} }/> {/* 实训页面2 */} {/* 独立的顶级路由,如登录页面,也不包含HeaderNav */} From 17bd97c9dcd0c91f18973445c87d9171e9ada7ac Mon Sep 17 00:00:00 2001 From: 30404 <3040471803@qq.com> Date: Wed, 26 Jun 2024 14:27:21 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E7=8F=AD=E7=BA=A7=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=9F=B1=E7=8A=B6=E5=9B=BE90%=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app-dm/src/TeacherPages/classlistpages/classId.jsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app-dm/src/TeacherPages/classlistpages/classId.jsx b/app-dm/src/TeacherPages/classlistpages/classId.jsx index 682c15d..e3969d2 100644 --- a/app-dm/src/TeacherPages/classlistpages/classId.jsx +++ b/app-dm/src/TeacherPages/classlistpages/classId.jsx @@ -18,6 +18,8 @@ const [name,setname]=useState('') const click=()=>{ + console.log(selectedSubject); + console.log(ID); console.log(studentScores); } const teacher_ID=localStorage.getItem('islogin') @@ -57,10 +59,15 @@ name: studentInfo[3], // 假设姓名总是位于数组的第4个位置 score: studentInfo[5], // 假设分数总是位于数组的第6个位置 }); + // 如果 scores 数组已经有三个或更多项目,则移除数组的第一个项目 + if (scores.length > 3) { + scores.shift(); + } } } } - setStudentScores(scores); + + setStudentScores(scores); }); }, [selectedSubject]); @@ -85,6 +92,7 @@ }) setTestScore(Find_details_Src.data['TestScore']) setStudentScores([]) + setSelectedSubject() }catch{ alert('Find_details') }