This commit is contained in:
30404 2024-06-29 17:07:59 +08:00
parent f062dfb337
commit 8abf333e13
7 changed files with 243 additions and 45 deletions

View File

@ -120,3 +120,12 @@
margin-top: 5px;
cursor: pointer;
}
.body-right1-exam{
width: 1414px;
height: 1540px;
position: absolute;
top: 64px;
left: 230px;
border-radius: 10px;
background-color: #f7f8fa;
}

View File

@ -10,10 +10,27 @@ import top from '../img/top.jpg'
import axios from 'axios';
function Exam() {
//
const [countdown, setCountdown] = useState(null);
const {examId}=useParams()
//
const [TestData,setTestData]=useState()
const TestFunc=async ()=>{
try{
const TestSrc=await axios.post('/api/student/TestData',{
examId
})
const data=TestSrc.data
setTestData(data)
}catch{
alert('TestSrc出错')
}
}
useEffect(()=>{
TestFunc()
},[])
//
useEffect(() => {
@ -29,13 +46,9 @@ function Exam() {
return () => clearInterval(interval);
}, [countdown]);
// useEffect(()=>{
// if(countdown<0){
// console.log('c');
// setCountdown(60 * parseInt(TrainData['operateID'][4]))
// localStorage.removeItem('time')
// }
// },[TrainData])
//
const formatTime = (seconds) => {
@ -48,6 +61,88 @@ function Exam() {
//
const [isSubjectDropdownOpen, setIsSubjectDropdownOpen] = useState(false);
//
const [choice_answer,setchoice_answer]=useState({})
const [completion_answer,setcompletion_answer]=useState({})
const [judge_answer,setjudge_answer]=useState({})
//
const [answeredChoice, setAnsweredChoice] = useState([]);
const [answeredComple, setAnsweredComple] = useState([]);
const [answeredJudge, setAnsweredJudge] = useState([]);
//
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);
//
if (!answeredChoice.includes(key)) {
setAnsweredChoice([...answeredChoice, key]);
}
};
//
const handleInputChange = (event) => {
const { name, value } = event.target;
setcompletion_answer({
...completion_answer,
[name]: value
});
if (!answeredComple.includes(parseInt(name))) {
setAnsweredComple([...answeredComple, parseInt(name)]);
}
};
//
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)
if (!answeredJudge.includes(key)) {
setAnsweredJudge([...answeredJudge, key]);
}
}
//
const [isFixed,setIsFixed]=useState(false)
//
const handleScroll = () => {
const scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
const fixedThreshold = 100; // 100px
if (scrollTop > fixedThreshold) {
setIsFixed(true);
} else {
setIsFixed(false);
}
};
//
useEffect(() => {
window.addEventListener('scroll', handleScroll);
return () => {
window.removeEventListener('scroll', handleScroll);
};
}, []);
return (
<div>
<div className='nav-exam'>
@ -78,32 +173,85 @@ function Exam() {
</ul>
{/* 题目预览框 */}
{/* 根据isFixed状态来设置countBox的类 */}
{/* <div className={`countBox ${isFixed ? 'fixed-count-box' : ''}`}>
{TrainData&&<table>
<div className={`countBox ${isFixed ? 'fixed-count-box' : ''}`}> {/* 根据isFixed状态来设置countBox的类 */}
{TestData&&<table>
<tr>选择题:</tr>
<div>
{Object.keys(TrainData['operateID'][0]).map((key,index)=>(
{Object.keys(TestData['examID'][0]).map((key,index)=>(
<td key={key} className={answeredChoice.includes(index) ? 'answered' : ''}>{index+1}</td>
))}
</div>
<tr>填空题</tr>
<div>
{Object.keys(TrainData['operateID'][1]).map((key,index)=>(
{Object.keys(TestData['examID'][1]).map((key,index)=>(
<td key={key} className={answeredComple.includes(index) ? 'answered' : ''}>{index+1}</td>
))}
</div>
<tr>判断题</tr>
<div>
{Object.keys(TrainData['operateID'][2]).map((key,index)=>(
{Object.keys(TestData['examID'][2]).map((key,index)=>(
<td key={key} className={answeredJudge.includes(index) ? 'answered' : ''}>{index+1}</td>
))}
</div>
</table>}
</div> */}
</div>
{/* <div className='body-right1-exam'>
</div> */}
</div>
<div className='body-right1-exam'>
{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>
<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}`}/>
<span>A.{TestData['examID'][0][key][0][2]}</span>
</label>
<br />
<label>
<input type="radio" value={TestData['examID'][0][key][0][3]} checked={choice_answer[key] === TestData['examID'][0][key][0][3]} onChange={handleOptionChange} name={`group${key}`}/>
<span>B.{TestData['examID'][0][key][0][3]}</span>
</label>
<br />
<label>
<input type="radio" value={TestData['examID'][0][key][0][4]} checked={choice_answer[key] === TestData['examID'][0][key][0][4]} onChange={handleOptionChange} name={`group${key}`}/>
<span>C.{TestData['examID'][0][key][0][4]}</span>
</label>
<br />
<label>
<input type="radio" value={TestData['examID'][0][key][0][5]} checked={choice_answer[key] === TestData['examID'][0][key][0][5]} onChange={handleOptionChange} name={`group${key}`}/>
<span>D.{TestData['examID'][0][key][0][5]}</span>
</label>
</div>
</tr>
))}
</tbody>
</table>}
{TestData&&(
<table className='body-right1-comple'>
<tbody>
<p>填空题</p>
{Object.keys(TestData['examID'][1]).map((key,index)=>(
<tr key={key}>
<tr className='test-title1'>{index+1}.{TestData['examID'][1][key][0][1]}</tr>
{/* <br /> */}
<div className='input-box'>
<span>请填入你的答案</span>
<input type="text" onChange={handleInputChange} name={key} value={completion_answer[key]||''}/>
</div>
</tr>
))}
</tbody>
</table>
)}
<button onClick={()=>{
console.log(TestData);
}}>这是测试按钮</button>
</div>
</div>
</div>
)

View File

@ -16,19 +16,9 @@ function Operation1() {
console.log(60 * parseInt(TrainData['operateID'][4]));
}
const clear=()=>{
localStorage.removeItem('choice_answers');
setchoice_answer({})
localStorage.removeItem('completion_answer')
setcompletion_answer({})
localStorage.removeItem('judge_answer')
setjudge_answer({})
localStorage.removeItem('answeredChoice')
setAnsweredChoice([])
localStorage.removeItem('answeredComple')
setAnsweredComple([])
localStorage.removeItem('answeredJudge')
setAnsweredJudge([])
localStorage.removeItem('RemainingTime')
['time', 'choice_answers', 'completion_answer', 'judge_answer',
'answeredChoice', 'answeredComple', 'answeredJudge', 'RemainingTime', 'TrainData']
.forEach(item => localStorage.removeItem(item));
}
const { operateID } = useParams();

View File

@ -146,8 +146,16 @@ function Operation2() {
const tijiao = ()=>{
setCountdown(0)
localStorage.removeItem('time')
localStorage.removeItem('choice_answers');
localStorage.removeItem('completion_answer')
localStorage.removeItem('judge_answer')
localStorage.removeItem('answeredChoice')
localStorage.removeItem('answeredComple')
localStorage.removeItem('answeredJudge')
localStorage.removeItem('RemainingTime')
alert('提交成功')
window.location.href='http://localhost:3000/train'
localStorage.removeItem('TrainData')
}
return (
@ -184,7 +192,7 @@ function Operation2() {
<button onClick={click}>测试按钮</button>
{/* 前端连接数据库⬇ */}
{ !isTrue&&<div>
{ !isTrue&&TrainData&&<div>
<Link to={Src}>{TrainData['operateID'][3][0]}</Link>
<br />
点击以上链接前往实训
@ -192,7 +200,7 @@ function Operation2() {
{/* 前端连接数据库 ⬆*/}
{/* 达梦数据库连接 ⬇*/}
{ isTrue&&
{ isTrue&&TrainData&&
<div>
<p>{TrainData['operateID'][3][0]}</p>
<div style={{width: "1430px",position:'absolute',right:'0'}} ref={terminalObj} onContextMenu={pasteContent}></div>

View File

@ -23,8 +23,8 @@ import ClassID from '../TeacherPages/classlistpages/classId';
import ManageTest from '../TeacherPages/TestManage/ManageTest';
import SendTest from '../TeacherPages/TestManage/SendTest';
import Marking from '../TeacherPages/MarkingPages/Marking';
import SendTrain from '../TeacherPages/TrainManage/SendTrain'
import TrainManage from '../TeacherPages/TrainManage/Trainmanage'
import SendTrain from '../TeacherPages/Trainmanage/SendTrain'
import TrainManage from '../TeacherPages/Trainmanage/Trainmanage'
import StudentLink from '../TeacherPages/MarkingPages/StudentLink';

View File

@ -103,10 +103,11 @@ def get_test(): # 获取试卷以及历史试卷
result2=falseTest_func(ID)
return jsonify({"True":result1,'FalseTest':result2})
@app.route('/api/student/get_testID',methods=['POST'])
def get_testID(): # 获取试卷ID
ID=request.json['student_ID']
return jsonify({'data': 'a'})
@app.route('/api/student/TestData',methods=['POST'])
def TestData(): # 获取试卷ID
examID=request.json['examId']
result=TestDataFunc(examID)
return result
@app.route('/api/student/fetch_result', methods=['POST']) # 查找成绩
@ -115,11 +116,7 @@ def fetch_result():
ID = data['student_ID']
return jsonify({'result': fetch_result_func(ID)})
@app.route('/api/student/get_end_student', methods=['POST'])
def get_end_student():
data = request.json
ID = data['student_ID']
return jsonify({'result': find_end_test(ID)})
@app.route('/api/student/score_entry', methods=['POST'])

View File

@ -120,7 +120,6 @@ def student_succeed_func(ID):
cursor.execute(f'SELECT * FROM STUDENT WHERE ID={ID}')
student_succeed = cursor.fetchall()[0]
student_succeeds = student_succeed[0], student_succeed[1], student_succeed[3], student_succeed[4]
print(student_succeeds)
cursor.close()
return student_succeeds
@ -166,6 +165,53 @@ def falseTest_func(ID):
# falseTest_func('20240101')
def TestDataFunc(examID):
cursor = db.cursor()
cursor.execute(f"SELECT * FROM TEST_BANK WHERE ID=?",(examID,))
TestID=cursor.fetchall()[0]
ChoiceList=json.loads(TestID[0])
CompleList=json.loads(TestID[1])
JudgeList=json.loads(TestID[2])
Choice=[]
Comple=[]
Judge=[]
CHOICE=[str(x) for x in ChoiceList]
COMPLE=[str(x) for x in CompleList]
JUDGE=[str(x) for x in JudgeList]
for i in CHOICE:
cursor.execute(f"SELECT * FROM CHOICE_QUESTION_BANK WHERE ID=?",(i))
Choice.append(cursor.fetchall())
for i in COMPLE:
cursor.execute(f"SELECT * FROM COMPLETION_QUESTION_BANK WHERE ID=?",(i))
Comple.append(cursor.fetchall())
for i in JUDGE:
cursor.execute(f"SELECT * FROM T_OR_F_QUESTION_BANK WHERE ID=?",(i))
Judge.append(cursor.fetchall())
HOUR=TestID[3]
MIN=TestID[4]
if int(HOUR)==0:
time=int(MIN)
elif int(MIN)==0:
time=int(HOUR)*60
else:
time=int(HOUR)*60+int(MIN)
dic={'examID':[Choice,Comple,Judge,time]}
# print(dic)
return dic
# TestDataFunc('35')
# 查找学生已经完成的记录
def find_end_test(ID):
cursor = db.cursor()