This commit is contained in:
30404 2024-06-29 22:05:53 +08:00
parent 933069a600
commit 5c5803e819
5 changed files with 119 additions and 35 deletions

View File

@ -11,11 +11,10 @@ import { max, min } from 'lodash';
// //
function Home(){ function Home(){
const [isChecked,setisChecked]=useState(false)
const student_ID=localStorage.getItem('islogin') const student_ID=localStorage.getItem('islogin')
if(student_ID==null){ if(student_ID==null){
window.location.href='http://localhost:3000/signin'
alert('未登录,请先前往登录') alert('未登录,请先前往登录')
window.location.href='http://36.138.114.105:30294/'
} }
// //
const [lesson, setLesson] = useState([]); const [lesson, setLesson] = useState([]);

View File

@ -13,6 +13,8 @@ function Exam() {
// //
const [countdown, setCountdown] = useState(null); const [countdown, setCountdown] = useState(null);
const {examId}=useParams() const {examId}=useParams()
const student_ID=localStorage.getItem('islogin')
const [score,setscore]=useState(0)
// //
const [TestData,setTestData]=useState() const [TestData,setTestData]=useState()
@ -32,6 +34,40 @@ function Exam() {
TestFunc() 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(() => { useEffect(() => {
let interval = setInterval(() => { let interval = setInterval(() => {
@ -41,15 +77,22 @@ function Exam() {
} else { } else {
clearInterval(interval); clearInterval(interval);
alert('考试时间到!'); alert('考试时间到!');
correct()
window.location.href='http://localhost:3000/subject'
} }
}, 1000); }, 1000);
return () => clearInterval(interval); return () => clearInterval(interval);
}, [countdown]); }, [countdown]);
useEffect(()=>{
if(countdown<0){
setCountdown(60 * parseInt(TestData['examID'][3]))
localStorage.removeItem('time')
}
},[TestData])
// //
const formatTime = (seconds) => { const formatTime = (seconds) => {
const hours = Math.floor(seconds / 3600); 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() {
</div> </div>
</div> </div>
<div className='body-right1-exam'> <div className='body-right1'>
{TestData&&<table> {TestData&&<table>
<p>选择题</p> <p>选择题</p>
<tbody> <tbody>
{Object.keys(TestData['examID'][0]).map((key,index) => ( {Object.keys(TestData['examID'][0]).map((key,index) => (
<tr key={key}> <tr key={key}>
<tr className='test-title'>{index+1}.{TestData['examID'][key][0][0][1]}</tr> <tr className='test-title'>{index+1}.{TestData['examID'][0][key][0][1]}</tr>
<div className='optionBox'> <div className='optionBox'>
<label> <label>
<input type="radio" value={TestData['examID'][0][key][0][2]} checked={choice_answer[key] === TestData['examID'][0][key][0][2]} onChange={handleOptionChange} name={`group${key}`}/> <input type="radio" value={TestData['examID'][0][key][0][2]} checked={choice_answer[key] === TestData['examID'][0][key][0][2]} onChange={handleOptionChange} name={`group${key}`}/>
@ -248,9 +311,23 @@ function Exam() {
</table> </table>
)} )}
<button onClick={()=>{ {TestData&&(
console.log(TestData); <table>
}}>这是测试按钮</button> <tbody>
<p>判断题</p>
{Object.keys(TestData['examID'][2]).map((key,index)=>(
<tr key={key} className='panduan-box'>
<tr>{index+1}.{TestData['examID'][2][key][0][1]}</tr>
<tr>
<label><input type="radio" name={`judge${key}`} checked={judge_answer[key] === 'true'} onChange={handleJudgeOption} value={true} />T</label>
<label><input type="radio" name={`judge${key}`} checked={judge_answer[key] === 'false'} onChange={handleJudgeOption} value={false} />F</label>
</tr>
</tr>
))}
</tbody>
</table>
)}
<button onClick={submit}>提交</button>
</div> </div>
</div> </div>
</div> </div>

View File

@ -57,19 +57,18 @@ function SubjectPage(){
))} ))}
</div>} </div>}
<h3>已结束或完成的试卷与练习</h3> <h3>已结束或完成的试卷与练习</h3>
{ testdata&& result&&<div className='test-subject'> <div className='test-subject'>
{Object.keys(testdata).map((key)=>{ { Object.keys(testdata).slice(-3).reverse().map((key) => (
return( <div className='test-box' key={key}>
<div className='test-box' key={key}> <p>试卷ID:{testdata[key][0][3]}</p>
<p>试卷ID:{testdata[key][0][3]}</p> <span>发布者:{'小陈老师'}</span>
<span>发布者:{'小陈老师'}</span> <div>发布时间:{testdata[key][1][0][5]}</div>
<div>发布时间:{testdata[key][1][0][5]}</div> <div>截至时间:{testdata[key][1][0][6]}</div>
<div>截至时间:{testdata[key][1][0][6]}</div> <div id='score'>{testdata[key][0][5]}</div>
<div id='score'>{testdata[key][0][5]}</div>
</div> </div>
) ))}
})} </div>
</div>} <button>更多历史</button>
{ NotFalse&& result&&<div className='test-subject'> { NotFalse&& result&&<div className='test-subject'>
{Object.keys(NotFalse).map((key)=>{ {Object.keys(NotFalse).map((key)=>{
return( return(

View File

@ -75,7 +75,6 @@ function Operation1() {
useEffect(()=>{ useEffect(()=>{
if(countdown<0){ if(countdown<0){
console.log('c');
setCountdown(60 * parseInt(TrainData['operateID'][4])) setCountdown(60 * parseInt(TrainData['operateID'][4]))
localStorage.removeItem('time') localStorage.removeItem('time')
} }

View File

@ -127,17 +127,27 @@ def student_succeed_func(ID):
# fetch_testID('20240101') # fetch_testID('20240101')
def fetch_test_func(ID):#获取试卷 def fetch_test_func(ID):#获取试卷
cursor = db.cursor() cursor = db.cursor()
correct=[]
TrueTestDic={} TrueTestDic={}
TruetestID=[] TruetestID=[]
cursor.execute(f"SELECT * FROM STUDENT_TEST WHERE STUDENT_ID=? AND TF='true'",(ID)) cursor.execute(f"SELECT * FROM STUDENT_TEST WHERE STUDENT_ID=? AND TF='true'",(ID))
for i in cursor.fetchall(): for i in cursor.fetchall():
correct.append(i)
correct=correct[::-1][:3]
for i in correct:
TruetestID.append(i[3]) TruetestID.append(i[3])
TrueTestDic[i[3]]=i TrueTestDic[i[3]]=i
TruetestID=TruetestID[::-1][:3]
for index in TruetestID: for index in TruetestID:
cursor.execute(f"SELECT * FROM TEST_BANK WHERE ID=?",(index)) cursor.execute(f"SELECT * FROM TEST_BANK WHERE ID=?",(index))
TrueTestDic[index]=TrueTestDic[index],cursor.fetchall() TrueTestDic[index]=TrueTestDic[index],cursor.fetchall()
# print(TrueTestDic) # print(TrueTestDic)
return TrueTestDic return TrueTestDic
# fetch_test_func('20240101') # fetch_test_func('20240101')