diff --git a/app-dm/src/pages/ListPages/Subject/Exam.jsx b/app-dm/src/pages/ListPages/Subject/Exam.jsx index a23fd21..16265fd 100644 --- a/app-dm/src/pages/ListPages/Subject/Exam.jsx +++ b/app-dm/src/pages/ListPages/Subject/Exam.jsx @@ -5,267 +5,9 @@ import { useEffect, useState } from 'react'; // 首页 课程班级 function Exam(){ - const {examId} = useParams() - const student_ID=localStorage.getItem('islogin') - if(student_ID==null){ - alert('登录过期,请重新登录') - window.location.href='http://36.138.114.105:30294/' - } - // 初始化倒计时状态 - const [countdown, setCountdown] = useState(0); - const Countdown=true - - //创建答案字典,将用户填入的答案添加到答案字典 - const [choice_answer,setchoice_answer]=useState({}) - const [completion_answer,setcompletion_answer]=useState({}) - const [judge_answer,setjudge_answer]=useState({}) - - const [testdata,settestdata]=useState('') - const test_func= async()=>{ - try{ - const test_src= await axios.post('/api/student/get_test',{student_ID}) - const test_data=test_src.data['data'] - settestdata(test_data) - }catch(error){ - alert(error) - - } - } - useEffect(()=>{ - test_func() - },[]) - // 倒计时初始化 - useEffect(() => { - const examDuration = 10; - setCountdown(examDuration); - }, []); - - // 转换秒数为时分秒格式 - const formatTime = (seconds) => { - const hours = Math.floor(seconds / 3600); - const minutes = Math.floor((seconds % 3600) / 60); - const secs = seconds % 60; - return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`; - }; - - const [changetime,setchangetime]=useState(true) - - // 倒计时更新 - useEffect(() => { - let interval = setInterval(() => { - if (countdown > 0) { - setCountdown(countdown - 1); - }else{ - clearInterval(interval) - alert('时间到!已强制交卷') - //与下面点击 - let sum = 0; - for (let item of testdata[examId][0][0]) { - for (let i of item) { - if (i[6] === choice_answer[sum]) { - // 使用函数式更新 - setscore(prevscore => prevscore + 2); - }else{ - } - } - for(let item of testdata[examId][0][1]){ - for(let i of item){ - if(i[2]===completion_answer[sum]){ - setscore(prevscore => prevscore + 2); - }else{ - } - } - } - for(let item of testdata[examId][0][2]){ - for(let i of item){ - console.log(i); - if(i[2]===judge_answer[sum]){ - setscore(prevscore => prevscore + 2); - }else{ - - } - } - } - sum++; // 每次循环完一个 item 后,sum 加 1 - } - console.log(score); - } - }, 1000); - - - return () => clearInterval(interval); - }, [countdown]); - - //提交按钮按钮并进行对照批改 - //设置总分 score - const [score,setscore]=useState(0) - - // 计算成绩 - const submit = async() => { - alert('提交成功') - let sum = 0; - for (let item of testdata[examId][0][0]) { - for (let i of item) { - if (i[6] === choice_answer[sum]) { - // 使用函数式更新 - setscore(prevscore => prevscore + 2); - } - } - for(let item of testdata[examId][0][1]){ - for(let i of item){ - if(i[2]===completion_answer[sum]){ - setscore(prevscore => prevscore + 2); - } - } - } - for(let item of testdata[examId][0][2]){ - for(let i of item){ - if(i[2]===judge_answer[sum]){ - setscore(prevscore => prevscore + 2); - } - } - } - sum++; // 每次循环完一个 item 后,sum 加 1 - } - }; - const [isMounted, setIsMounted] = useState(false); - useEffect(()=>{ - if(isMounted){ - const score_func=async()=>{ - try{ - const score_entry_src=await axios.post('/api/student/score_entry',{ - student_ID, - score, - examId - }) - }catch(error){ - alert(error) - } - window.location.href='http://36.138.114.105:30294/subject' - } - score_func() - }else{ - setIsMounted(true) - } - },[score]) - - - //给选择题添加事件监听器 - 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); - }; - - //填空题 - const handleInputChange = (event) => { - const { name, value } = event.target; - setcompletion_answer({ - ...completion_answer, - [name]: value - }); - }; - - //判断题 - 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) - } - return( -
-
- {testdata&&
-

试卷ID:{examId}

-

发布人:{testdata[examId][5]}

-
- {/* 倒计时 */} -

剩余时间:{formatTime(countdown)}

-
-
} -
-
-
-

题目

-
    -
  • 判断题
  • -
  • 选择题
  • -
  • 解答题
  • -
-
-
- {/* 右边的题目 */} +
+ ) +} -
- 选择题 - - {testdata&& - {Object.keys(testdata[examId][0][0]).map((key)=>( - - - - ))} - } -
- {parseInt(key,10)+1}:{testdata[examId][0][0][key][0][1]} -
- -
- -
- -
- -
-
-
- {/* */} -
- 填空题 - - { testdata&& - {Object.keys(testdata[examId][0][1]).map((key)=>( - - - - ))} - } -
-
-

{parseInt(key,10)+1}:{testdata[examId][0][1][key][0][1]} - -

-
-
-
-
- 判断题 - { testdata&& - - {Object.keys(testdata[examId][0][2]).map((key)=>( - - - - ))} - -
-
-

{parseInt(key,10)+1}:{testdata[examId][0][2][key][0][1]}

- - -
-
} - -
-
- -
-
-
-
-)}; - -export default Exam; \ No newline at end of file +export default Exam \ No newline at end of file diff --git a/app-dm/src/pages/ListPages/Subject/SubjectPage.css b/app-dm/src/pages/ListPages/Subject/SubjectPage.css index cdca848..13122ae 100644 --- a/app-dm/src/pages/ListPages/Subject/SubjectPage.css +++ b/app-dm/src/pages/ListPages/Subject/SubjectPage.css @@ -1,4 +1,4 @@ -@import url('https://fonts.font.im/css?family=Caveat'); + /* 右侧页面 */ .body-right-subject{ @@ -81,7 +81,6 @@ font-size: 45px; /* color: #ff6666; */ color: rgb(252, 102, 102); - font-family: 'Caveat', cursive; } diff --git a/app-dm/src/pages/ListPages/Subject/SubjectPage.jsx b/app-dm/src/pages/ListPages/Subject/SubjectPage.jsx index f846468..bc203f8 100644 --- a/app-dm/src/pages/ListPages/Subject/SubjectPage.jsx +++ b/app-dm/src/pages/ListPages/Subject/SubjectPage.jsx @@ -13,6 +13,8 @@ function SubjectPage(){ window.location.href='http://36.138.114.105:30294/' } const [testdata,settestdata]=useState('') + const [FalseData,setFalseData]=useState('') + const [NotFalse,setNotFalse]=useState('') const [time,settime]=useState(moment().format('YYYY-MM-DD HH:mm:ss')) const [result,setresult]=useState({}) @@ -20,7 +22,9 @@ function SubjectPage(){ const test=async()=>{ try{ const test_src= await axios.post('/api/student/get_test',{student_ID}) - settestdata(test_src.data['data']) + settestdata(test_src.data['True']) + setFalseData(test_src.data['FalseTest'][1]) + setNotFalse(test_src.data['FalseTest'][2]) }catch(error){ alert('test出错') } @@ -28,88 +32,59 @@ function SubjectPage(){ useEffect(()=>{ test() },[]) - - const [EndTestList,setEndTestList]=useState([]) - //获取他已经做过的试卷 - const end_test=async()=>{ - try{ - const end_test_src=await axios.post('/api/student/get_end_student',{student_ID}) - const obj=end_test_src.data['result'] - setEndTestList(obj) - }catch(error){ - alert(error) - } + + const click=()=>{ + console.log(testdata); + console.log(FalseData); + console.log(NotFalse); } - - useEffect(()=>{ - end_test() - },[]) - - //过期试卷 - const [outtest,setouttest]=useState({}) - //分过期试卷⬇ - useEffect(()=>{ - let test_list= [] - for (const key in testdata) { - if(testdata[key][4]