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(){
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([]);

View File

@ -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,13 +77,20 @@ 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])
//
@ -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 className='body-right1-exam'>
<div className='body-right1'>
{TestData&&<table>
<p>选择题</p>
<tbody>
{Object.keys(TestData['examID'][0]).map((key,index) => (
<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'>
<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}`}/>
@ -248,9 +311,23 @@ function Exam() {
</table>
)}
<button onClick={()=>{
console.log(TestData);
}}>这是测试按钮</button>
{TestData&&(
<table>
<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>

View File

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

View File

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

View File

@ -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')