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]}
+ 发布者:{'小陈老师'} +