From 8abf333e1312114d0cc758a445b63d37c9510779 Mon Sep 17 00:00:00 2001 From: 30404 <3040471803@qq.com> Date: Sat, 29 Jun 2024 17:07:59 +0800 Subject: [PATCH 1/9] 1 --- app-dm/src/pages/ListPages/Subject/Exam.css | 9 + app-dm/src/pages/ListPages/Subject/Exam.jsx | 184 ++++++++++++++++-- .../pages/ListPages/Training/Operation1.jsx | 16 +- .../pages/ListPages/Training/Operation2.jsx | 12 +- app-dm/src/router/index.jsx | 4 +- python/app.py | 15 +- python/student_func.py | 48 ++++- 7 files changed, 243 insertions(+), 45 deletions(-) diff --git a/app-dm/src/pages/ListPages/Subject/Exam.css b/app-dm/src/pages/ListPages/Subject/Exam.css index 247fb2f..5751808 100644 --- a/app-dm/src/pages/ListPages/Subject/Exam.css +++ b/app-dm/src/pages/ListPages/Subject/Exam.css @@ -119,4 +119,13 @@ margin-left: 5px; margin-top: 5px; cursor: pointer; +} +.body-right1-exam{ + width: 1414px; + height: 1540px; + position: absolute; + top: 64px; + left: 230px; + border-radius: 10px; + background-color: #f7f8fa; } \ No newline at end of file diff --git a/app-dm/src/pages/ListPages/Subject/Exam.jsx b/app-dm/src/pages/ListPages/Subject/Exam.jsx index 17f52a8..b968908 100644 --- a/app-dm/src/pages/ListPages/Subject/Exam.jsx +++ b/app-dm/src/pages/ListPages/Subject/Exam.jsx @@ -10,10 +10,27 @@ import top from '../img/top.jpg' import axios from 'axios'; function Exam() { - - //倒计时 const [countdown, setCountdown] = useState(null); + const {examId}=useParams() + + //获取题目 + const [TestData,setTestData]=useState() + const TestFunc=async ()=>{ + try{ + const TestSrc=await axios.post('/api/student/TestData',{ + examId + }) + const data=TestSrc.data + setTestData(data) + }catch{ + alert('TestSrc出错') + } + } + + useEffect(()=>{ + TestFunc() + },[]) // 倒计时更新 useEffect(() => { @@ -29,13 +46,9 @@ function Exam() { return () => clearInterval(interval); }, [countdown]); - // useEffect(()=>{ - // if(countdown<0){ - // console.log('c'); - // setCountdown(60 * parseInt(TrainData['operateID'][4])) - // localStorage.removeItem('time') - // } - // },[TrainData]) + + + // 转换秒数为时分秒格式 const formatTime = (seconds) => { @@ -48,6 +61,88 @@ function Exam() { // 下拉菜单 const [isSubjectDropdownOpen, setIsSubjectDropdownOpen] = useState(false); + //创建答案字典,将用户填入的答案添加到答案字典 + const [choice_answer,setchoice_answer]=useState({}) + const [completion_answer,setcompletion_answer]=useState({}) + const [judge_answer,setjudge_answer]=useState({}) + //选中反馈 + const [answeredChoice, setAnsweredChoice] = useState([]); + const [answeredComple, setAnsweredComple] = useState([]); + const [answeredJudge, setAnsweredJudge] = useState([]); + + //给选择题添加事件监听器 + const handleOptionChange = (event) => { + const selectedValue = event.target.value; + const key = parseInt(event.target.name.replace('group', '')); + const updatedChoiceAnswer = { ...choice_answer, [key]: selectedValue }; + setchoice_answer(updatedChoiceAnswer); + // 更新已做题目的状态 + if (!answeredChoice.includes(key)) { + setAnsweredChoice([...answeredChoice, key]); + } + }; + //填空题 + const handleInputChange = (event) => { + const { name, value } = event.target; + setcompletion_answer({ + ...completion_answer, + [name]: value + }); + if (!answeredComple.includes(parseInt(name))) { + setAnsweredComple([...answeredComple, parseInt(name)]); + } + + }; + + //判断题 + const handleJudgeOption=(event)=>{ + const judgeoption=event.target.value; + const key=parseInt(event.target.name.replace('judge','')) + const updatedJudgeAnswer={ ...judge_answer,[key]:judgeoption} + setjudge_answer(updatedJudgeAnswer) + if (!answeredJudge.includes(key)) { + setAnsweredJudge([...answeredJudge, key]); + } + } + + + + + + + + + + + + + + + + + + // 题目预览框 + const [isFixed,setIsFixed]=useState(false) + // 创建一个函数来处理滚动逻辑 + const handleScroll = () => { + const scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0; + const fixedThreshold = 100; // 滚动到100px后固定 + + if (scrollTop > fixedThreshold) { + setIsFixed(true); + } else { + setIsFixed(false); + } + }; + // 在组件挂载后添加滚动事件监听器,并在卸载时移除 + useEffect(() => { + window.addEventListener('scroll', handleScroll); + + return () => { + window.removeEventListener('scroll', handleScroll); + }; + }, []); + return (
{index+1} | ))}
{index+1} | ))}
{index+1} | ))}
{TrainData['operateID'][3][0]}
diff --git a/app-dm/src/router/index.jsx b/app-dm/src/router/index.jsx index a2c4596..b5e2aa3 100755 --- a/app-dm/src/router/index.jsx +++ b/app-dm/src/router/index.jsx @@ -23,8 +23,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'; diff --git a/python/app.py b/python/app.py index f8825ef..26960f9 100644 --- a/python/app.py +++ b/python/app.py @@ -103,10 +103,11 @@ def get_test(): # 获取试卷以及历史试卷 result2=falseTest_func(ID) return jsonify({"True":result1,'FalseTest':result2}) -@app.route('/api/student/get_testID',methods=['POST']) -def get_testID(): # 获取试卷ID - ID=request.json['student_ID'] - return jsonify({'data': 'a'}) +@app.route('/api/student/TestData',methods=['POST']) +def TestData(): # 获取试卷ID + examID=request.json['examId'] + result=TestDataFunc(examID) + return result @app.route('/api/student/fetch_result', methods=['POST']) # 查找成绩 @@ -115,11 +116,7 @@ def fetch_result(): ID = data['student_ID'] return jsonify({'result': fetch_result_func(ID)}) -@app.route('/api/student/get_end_student', methods=['POST']) -def get_end_student(): - data = request.json - ID = data['student_ID'] - return jsonify({'result': find_end_test(ID)}) + @app.route('/api/student/score_entry', methods=['POST']) diff --git a/python/student_func.py b/python/student_func.py index e1f72d0..e8f6b74 100644 --- a/python/student_func.py +++ b/python/student_func.py @@ -120,7 +120,6 @@ def student_succeed_func(ID): cursor.execute(f'SELECT * FROM STUDENT WHERE ID={ID}') student_succeed = cursor.fetchall()[0] student_succeeds = student_succeed[0], student_succeed[1], student_succeed[3], student_succeed[4] - print(student_succeeds) cursor.close() return student_succeeds @@ -166,6 +165,53 @@ def falseTest_func(ID): # falseTest_func('20240101') + +def TestDataFunc(examID): + cursor = db.cursor() + cursor.execute(f"SELECT * FROM TEST_BANK WHERE ID=?",(examID,)) + TestID=cursor.fetchall()[0] + ChoiceList=json.loads(TestID[0]) + CompleList=json.loads(TestID[1]) + JudgeList=json.loads(TestID[2]) + + Choice=[] + Comple=[] + Judge=[] + + CHOICE=[str(x) for x in ChoiceList] + COMPLE=[str(x) for x in CompleList] + JUDGE=[str(x) for x in JudgeList] + + for i in CHOICE: + cursor.execute(f"SELECT * FROM CHOICE_QUESTION_BANK WHERE ID=?",(i)) + Choice.append(cursor.fetchall()) + + for i in COMPLE: + cursor.execute(f"SELECT * FROM COMPLETION_QUESTION_BANK WHERE ID=?",(i)) + Comple.append(cursor.fetchall()) + + for i in JUDGE: + cursor.execute(f"SELECT * FROM T_OR_F_QUESTION_BANK WHERE ID=?",(i)) + Judge.append(cursor.fetchall()) + + + HOUR=TestID[3] + MIN=TestID[4] + if int(HOUR)==0: + time=int(MIN) + elif int(MIN)==0: + time=int(HOUR)*60 + else: + time=int(HOUR)*60+int(MIN) + + dic={'examID':[Choice,Comple,Judge,time]} + + # print(dic) + + return dic + +# TestDataFunc('35') + # 查找学生已经完成的记录 def find_end_test(ID): cursor = db.cursor() From 5c5803e819435e9f904a3cef47583ac58cb44d61 Mon Sep 17 00:00:00 2001 From: 30404 <3040471803@qq.com> Date: Sat, 29 Jun 2024 22:05:53 +0800 Subject: [PATCH 2/9] 1 --- app-dm/src/pages/Home/Home.jsx | 3 +- app-dm/src/pages/ListPages/Subject/Exam.jsx | 117 +++++++++++++++--- .../pages/ListPages/Subject/SubjectPage.jsx | 23 ++-- .../pages/ListPages/Training/Operation1.jsx | 1 - python/student_func.py | 10 ++ 5 files changed, 119 insertions(+), 35 deletions(-) diff --git a/app-dm/src/pages/Home/Home.jsx b/app-dm/src/pages/Home/Home.jsx index bb83281..3368983 100644 --- a/app-dm/src/pages/Home/Home.jsx +++ b/app-dm/src/pages/Home/Home.jsx @@ -11,11 +11,10 @@ import { max, min } from 'lodash'; // 首页 function Home(){ - const [isChecked,setisChecked]=useState(false) const student_ID=localStorage.getItem('islogin') if(student_ID==null){ + window.location.href='http://localhost:3000/signin' alert('未登录,请先前往登录') - window.location.href='http://36.138.114.105:30294/' } //课表数据 const [lesson, setLesson] = useState([]); diff --git a/app-dm/src/pages/ListPages/Subject/Exam.jsx b/app-dm/src/pages/ListPages/Subject/Exam.jsx index b968908..59a35e1 100644 --- a/app-dm/src/pages/ListPages/Subject/Exam.jsx +++ b/app-dm/src/pages/ListPages/Subject/Exam.jsx @@ -13,6 +13,8 @@ function Exam() { //倒计时 const [countdown, setCountdown] = useState(null); const {examId}=useParams() + const student_ID=localStorage.getItem('islogin') + const [score,setscore]=useState(0) //获取题目 const [TestData,setTestData]=useState() @@ -32,6 +34,40 @@ function Exam() { TestFunc() },[]) + + //添加成绩 + const scoreEntry=async()=>{ + try{ + const scoreEntrySrc=await axios.post('/api/student/score_entry',{ + student_ID, + examId, + score + }) + }catch{ + alert('scoreEntry出错') + } + } + + useEffect(()=>{ + scoreEntry() + },[score]) + + function daojishi(){ + if(localStorage.getItem('time')){ + setCountdown(localStorage.getItem('time')) + }else{ + if(TestData){ + setCountdown(60 * parseInt(TestData['examID'][3])) + } + } + } + + useEffect(()=>{ + daojishi() + console.log('a'); + },[]) + + // 倒计时更新 useEffect(() => { let interval = setInterval(() => { @@ -41,15 +77,22 @@ function Exam() { } else { clearInterval(interval); alert('考试时间到!'); + correct() + + window.location.href='http://localhost:3000/subject' } }, 1000); return () => clearInterval(interval); }, [countdown]); - + useEffect(()=>{ + if(countdown<0){ + setCountdown(60 * parseInt(TestData['examID'][3])) + localStorage.removeItem('time') + } + },[TestData]) - // 转换秒数为时分秒格式 const formatTime = (seconds) => { const hours = Math.floor(seconds / 3600); @@ -105,20 +148,40 @@ function Exam() { } } + //批改 + const correct=()=>{ + let CHO_sum=0; + let COM_sum=0; + let JUD_sum=0; + for(let item of TestData['examID'][0]){ + if(item[0][6]===choice_answer[CHO_sum]){ + setscore(prevscore=>prevscore+5) + } + CHO_sum++ + } + for(let item of TestData['examID'][1]){ + if (item[0][2]===completion_answer[COM_sum]) { + setscore(prevscore=>prevscore+5) + } + COM_sum++ + } + for(let item of TestData['examID'][2]){ + if (item[0][2]===judge_answer[JUD_sum]) { + setscore(prevscore=>prevscore+5) + } + JUD_sum++ + } + } - - - - - - - - - - - - - + + const submit=()=>{ + correct() + setCountdown(0) + localStorage.removeItem('time') + alert('提交成功') + window.location.href='http://localhost:3000/subject' + + } // 题目预览框 @@ -197,13 +260,13 @@ function Exam() {试卷ID:{testdata[key][0][3]}
- 发布者:{'小陈老师'} -试卷ID:{testdata[key][0][3]}
+ 发布者:{'小陈老师'} +-
{item.class}
- {item.time} - -+
{eval(MarkData[key][0][11])}
+ {} + +题目选择
- {