This commit is contained in:
30404 2024-07-10 13:32:18 +08:00
parent 0dc1bba456
commit 69ebafcceb
4 changed files with 67 additions and 50 deletions

View File

@ -113,3 +113,17 @@
font-size: 14px; font-size: 14px;
margin-left: 52px; margin-left: 52px;
} }
.TrainBox{
width: 1000px;
height: 500px;
background-color: aqua;
}
.TrainBox table{
margin-top: 200px;
margin-left: 400px;
width: 500px;
text-align: center;
border: 1px solid black;
}
.TrainBox th{
}

View File

@ -6,8 +6,9 @@ import React, { useEffect, useState } from 'react';
function TrainManage(){ function TrainManage(){
const teacher_ID=localStorage.getItem('islogin') const teacher_ID=localStorage.getItem('islogin')
const [isTrue,setisTrue]=useState(false)
const [Data,setData]=useState([]) const [Data,setData]=useState([])
const [showModal, setShowModal] = useState(false); const [showModal, setShowModal] = useState(true);
const [selectedTrain, setSelectedTrain] = useState(null); const [selectedTrain, setSelectedTrain] = useState(null);
const [testID,settestID]=useState() const [testID,settestID]=useState()
const [TrainData,setTrainData]=useState() const [TrainData,setTrainData]=useState()
@ -39,16 +40,19 @@ function TrainManage(){
} }
useEffect(()=>{ useEffect(()=>{
getTrainData() if(isTrue){
getTrainData()
}else{
setisTrue(true)
}
},[testID]) },[testID])
const Click=(testID,train)=>{
settestID(testID)
setSelectedTrain(train)
}
const handleTrainClick = (train) => {
setSelectedTrain(train);
setShowModal(true);
};
return( return(
<div className='body-trainmanage'> <div className='body-trainmanage'>
<p className='title'>已结束的实训</p> <p className='title'>已结束的实训</p>
@ -56,7 +60,7 @@ function TrainManage(){
{Data&&<div className='train-list-trainmanage'> {Data&&<div className='train-list-trainmanage'>
<ul className="ul-trainmanage"> <ul className="ul-trainmanage">
{Object.keys(Data).map((key)=>( {Object.keys(Data).map((key)=>(
<li key={key} onClick={() => handleTrainClick(key)}> <li key={key} onClick={()=>Click(Data[key][10],eval(Data[key][11]))}>
<span>实训ID:{Data[key][10]}</span> <span>实训ID:{Data[key][10]}</span>
<h6 className='TrainTitle'>实训名称:{eval(Data[key][11])}</h6> <h6 className='TrainTitle'>实训名称:{eval(Data[key][11])}</h6>
<p>关闭时间{Data[key][6]}</p> <p>关闭时间{Data[key][6]}</p>
@ -66,42 +70,33 @@ function TrainManage(){
<Link to='/teacher/trainmanage/TrainPods' className='ManagePods' >管理实训</Link> <Link to='/teacher/trainmanage/TrainPods' className='ManagePods' >管理实训</Link>
<Link to='/teacher/SendTrain' className='sendtestpage'>发布实训</Link> <Link to='/teacher/SendTrain' className='sendtestpage'>发布实训</Link>
</div>} </div>}
<div className='TrainBox'>
<table>
{/* 弹窗组件 */} <thead>
{showModal && ( <tr>
<div className='modal'> <th>姓名</th>
<div className='modal-content'> <th>ID</th>
<span className='close' onClick={() => setShowModal(false)}>&times;</span> <th>基础成绩</th>
<h2>实训信息</h2> <th>实训成绩</th>
<table> <th>总成绩</th>
<thead> </tr>
<tr> </thead>
<th>实训ID</th> <tbody>
<th>实训名称</th> {Object.keys(TrainData).map((key)=>(
<th>学号</th> <tr key={key}>
<th>基础成绩</th> <td>{key}</td>
<th>实训成绩</th> <td>{TrainData[key][0]}</td>
<th>总成绩</th> <td>{TrainData[key][4]}</td>
</tr> <td>{TrainData[key][5]}</td>
</thead> <td>{parseInt(TrainData[key][4])+parseInt(TrainData[key][5])}</td>
<tbody> </tr>
{selectedTrain && selectedTrain.students.map((student, index) => ( ))}
<tr key={index}> </tbody>
<td>{selectedTrain[10]}</td> </table>
<td>{eval(selectedTrain[11])}</td> </div>
<td>{student.studentID}</td> <button onClick={()=>{
<td>{student.baseScore}</td> console.log(TrainData);
<td>{student.trainScore}</td> }}></button>
<td>{student.totalScore}</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
)}
</div> </div>
) )
} }

View File

@ -342,11 +342,9 @@ def appendQuestion():
def getTrainData(): def getTrainData():
testID=request.json['testID'] testID=request.json['testID']
print(testID) print(testID)
if testID: data = getTrainDataFunc(testID)
data = getTrainDataFunc(testID) return jsonify({'data': data})
return jsonify({'data': data})
else:
pass

View File

@ -456,10 +456,20 @@ def appendQuestionFunc(subject,chapter,inputValue,A,B,C,D,correct,judgeValue):
return 'INSERT' return 'INSERT'
def getTrainDataFunc(testID): def getTrainDataFunc(testID):
dic={}
cursor = db.cursor() cursor = db.cursor()
cursor.execute(f'SELECT * FROM TRAINSCORE WHERE TEST_ID=? ',(testID,)) cursor.execute(f'SELECT * FROM TRAINSCORE WHERE TEST_ID=? ',(testID,))
data = cursor.fetchall() data = cursor.fetchall()
for i in data:
cursor.execute(f'SELECT NAME FROM STUDENT WHERE ID=? ', (i[0],))
name=cursor.fetchall()[0][0]
dic[name]=i
print(dic)
cursor.close() cursor.close()
return data return dic
# getTrainDataFunc('71')