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() { -
+
{TestData&&

选择题

{Object.keys(TestData['examID'][0]).map((key,index) => ( - {index+1}.{TestData['examID'][key][0][0][1]} + {index+1}.{TestData['examID'][0][key][0][1]}
)} - + {TestData&&( + + +

判断题

+ {Object.keys(TestData['examID'][2]).map((key,index)=>( + + {index+1}.{TestData['examID'][2][key][0][1]} + + + + + + ))} + +
+ )} +
diff --git a/app-dm/src/pages/ListPages/Subject/SubjectPage.jsx b/app-dm/src/pages/ListPages/Subject/SubjectPage.jsx index 89a99ef..6544e5f 100644 --- a/app-dm/src/pages/ListPages/Subject/SubjectPage.jsx +++ b/app-dm/src/pages/ListPages/Subject/SubjectPage.jsx @@ -57,19 +57,18 @@ function SubjectPage(){ ))} }

已结束或完成的试卷与练习

- { testdata&& result&&
- {Object.keys(testdata).map((key)=>{ - return( -
-

试卷ID:{testdata[key][0][3]}

- 发布者:{'小陈老师'} -
发布时间:{testdata[key][1][0][5]}
-
截至时间:{testdata[key][1][0][6]}
-
{testdata[key][0][5]}
+
+ { Object.keys(testdata).slice(-3).reverse().map((key) => ( +
+

试卷ID:{testdata[key][0][3]}

+ 发布者:{'小陈老师'} +
发布时间:{testdata[key][1][0][5]}
+
截至时间:{testdata[key][1][0][6]}
+
{testdata[key][0][5]}
- ) - })} -
} + ))} +
+ { NotFalse&& result&&
{Object.keys(NotFalse).map((key)=>{ return( diff --git a/app-dm/src/pages/ListPages/Training/Operation1.jsx b/app-dm/src/pages/ListPages/Training/Operation1.jsx index d9ad6ac..d88685b 100644 --- a/app-dm/src/pages/ListPages/Training/Operation1.jsx +++ b/app-dm/src/pages/ListPages/Training/Operation1.jsx @@ -75,7 +75,6 @@ function Operation1() { useEffect(()=>{ if(countdown<0){ - console.log('c'); setCountdown(60 * parseInt(TrainData['operateID'][4])) localStorage.removeItem('time') } diff --git a/python/student_func.py b/python/student_func.py index e8f6b74..beab01e 100644 --- a/python/student_func.py +++ b/python/student_func.py @@ -127,17 +127,27 @@ def student_succeed_func(ID): # fetch_testID('20240101') def fetch_test_func(ID):#获取试卷 cursor = db.cursor() + correct=[] TrueTestDic={} TruetestID=[] cursor.execute(f"SELECT * FROM STUDENT_TEST WHERE STUDENT_ID=? AND TF='true'",(ID)) for i in cursor.fetchall(): + correct.append(i) + + correct=correct[::-1][:3] + + for i in correct: TruetestID.append(i[3]) TrueTestDic[i[3]]=i + TruetestID=TruetestID[::-1][:3] + for index in TruetestID: cursor.execute(f"SELECT * FROM TEST_BANK WHERE ID=?",(index)) TrueTestDic[index]=TrueTestDic[index],cursor.fetchall() + # print(TrueTestDic) + return TrueTestDic # fetch_test_func('20240101')