From 84e144b4694c2357c0108d0c3abe86a9d5da9677 Mon Sep 17 00:00:00 2001 From: 30404 <3040471803@qq.com> Date: Fri, 21 Jun 2024 14:40:55 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=89=E6=8B=A9=E9=A2=98=E6=81=A2=E5=A4=8D?= =?UTF-8?q?=E4=B8=8A=E6=AC=A1=E9=80=89=E6=8B=A9=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/ListPages/Training/Operation1.css | 15 ++++ .../pages/ListPages/Training/Operation1.jsx | 86 +++++++++++++++++-- .../pages/ListPages/Training/Operation2.jsx | 4 +- python/app.py | 7 ++ python/student_func.py | 51 +++++++++++ 5 files changed, 157 insertions(+), 6 deletions(-) diff --git a/app-dm/src/pages/ListPages/Training/Operation1.css b/app-dm/src/pages/ListPages/Training/Operation1.css index eaa062f..400682d 100644 --- a/app-dm/src/pages/ListPages/Training/Operation1.css +++ b/app-dm/src/pages/ListPages/Training/Operation1.css @@ -99,3 +99,18 @@ margin-left: 5px; } +.body-right1 table{ + width: 100%; +} +.optionBox{ + width: 100%; + background-color: rgb(110, 130, 130); +} +.body-right1 p{ + margin: 0px; + font-size: 20px; +} +.optionBox label{ + margin-left: 10px; +} + diff --git a/app-dm/src/pages/ListPages/Training/Operation1.jsx b/app-dm/src/pages/ListPages/Training/Operation1.jsx index 3e8dc17..7e708ed 100644 --- a/app-dm/src/pages/ListPages/Training/Operation1.jsx +++ b/app-dm/src/pages/ListPages/Training/Operation1.jsx @@ -2,21 +2,47 @@ import './Operation1.css' import { Terminal } from "@xterm/xterm"; import "@xterm/xterm/css/xterm.css" import React,{ MouseEvent, useEffect, useRef, useState } from "react"; +import { useParams } from 'react-router'; import { Link } from 'react-router-dom'; import arrow from '../img/arrow.jpg' import bottom from '../img/bottom.jpg' import top from '../img/top.jpg' +import axios from 'axios'; function Operation1() { - + const click=()=>{ + console.log(choice_answer); + } + const clear=()=>{ + setchoice_answer({}) + } + + const { operateID } = useParams(); + + //获取试卷 + const [TrainData,setTrainData]=useState() + const TrainDataFunc=async()=>{ + try{ + const TrainDataSrc=await axios.post('/api/student/TrainData',{ + operateID + }) + const returnData=TrainDataSrc.data + setTrainData(returnData) + }catch{ + alert('TrainDataFunc出错') + } + } + + useEffect(()=>{ + TrainDataFunc() + },[]) //倒计时 - // const { OperationId } = useParams(); const [test_data, setTestData] = useState(''); const [countdown, setCountdown] = useState(0); // 倒计时初始化 useEffect(() => { - const examDuration = 60 * 60; // 假设考试时长为1小时 + const examDuration = 60 * 90; // 假设考试时长为1小时 setCountdown(examDuration); }, []); @@ -44,6 +70,33 @@ function Operation1() { // 下拉菜单 const [isSubjectDropdownOpen, setIsSubjectDropdownOpen] = useState(false); + //创建答案字典,将用户填入的答案添加到答案字典 + const [choice_answer,setchoice_answer]=useState({}) + const [completion_answer,setcompletion_answer]=useState({}) + const [judge_answer,setjudge_answer]=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); + + }; + + //保存答案到 localStorage + const saveAnswers = () => { + localStorage.setItem('choice_answers', JSON.stringify(choice_answer)); + }; + + // 在组件加载时从 localStorage 中恢复答案 + useEffect(() => { + const storedAnswers = localStorage.getItem('choice_answers'); + if (storedAnswers) { + const parsedAnswers = JSON.parse(storedAnswers); + setchoice_answer(parsedAnswers); + } + }, []); return (
@@ -74,9 +127,32 @@ function Operation1() {
- 第一页(主观题)的右边页面 + {TrainData && ( + +

选择题:

+ + {Object.keys(TrainData['operateID'][0]).map((key) => ( + + {TrainData['operateID'][0][key][0][1]} +
+ +
+ +
+ +
+ +
+ + ))} + +
+ )} + + +
- +

下一页

diff --git a/app-dm/src/pages/ListPages/Training/Operation2.jsx b/app-dm/src/pages/ListPages/Training/Operation2.jsx index 1b7855f..09dd9b1 100644 --- a/app-dm/src/pages/ListPages/Training/Operation2.jsx +++ b/app-dm/src/pages/ListPages/Training/Operation2.jsx @@ -2,6 +2,7 @@ import './Operation2.css' import { Terminal } from "@xterm/xterm"; import "@xterm/xterm/css/xterm.css" import React,{ MouseEvent, useEffect, useRef, useState } from "react"; +import { useParams } from 'react-router'; import { Link } from 'react-router-dom'; import arrow from '../img/arrow.jpg' import arrow1 from '../img/left.jpg' @@ -9,6 +10,7 @@ import bottom from '../img/bottom.jpg' import top from '../img/top.jpg' function Operation2() { + const { operateID } = useParams(); //终端 const terminalObj = useRef(null); let sock = null; @@ -122,7 +124,7 @@ function Operation2() { 第二页(实训题)的右边页面
- +

上一页

diff --git a/python/app.py b/python/app.py index 450905e..fcff020 100644 --- a/python/app.py +++ b/python/app.py @@ -134,6 +134,13 @@ def FetchTrainTitle(): return jsonify({'title': title}) +@app.route('/api/student/TrainData',methods=['POST']) +def TrainData(): + examID=request.json['operateID'] + result=FetchTrainTestFunc(examID) + return result + + # 以下为教师功能————————————————————————————————————————————————————————————————————— @app.route('/api/teacher/return_question', methods=['POST']) diff --git a/python/student_func.py b/python/student_func.py index a76c6fc..392d7c1 100644 --- a/python/student_func.py +++ b/python/student_func.py @@ -221,5 +221,56 @@ def FetchTrainTitleFunc(ID): +def FetchTrainTestFunc(operateID): + cursor = db.cursor() + cursor.execute("SELECT * FROM TRAINTEST WHERE ID=?",(operateID)) + TrainID=cursor.fetchall()[0] + #获取题目 + CHOICEID=json.loads(TrainID[0]) + COMPLEID=json.loads(TrainID[1]) + JUDGEID=json.loads(TrainID[2]) + Train=json.loads(TrainID[11]) + + CHOICELIST=[] + COMPLELIST=[] + JUDGELIST=[] + + CHOICE=[str(x) for x in CHOICEID] + COMPLE=[str(x) for x in COMPLEID] + JUDGE=[str(x) for x in JUDGEID] + + for i in CHOICE: + cursor.execute('SELECT * FROM CHOICE_QUESTION_BANK WHERE ID=(?)',(i)) + CHOICELIST.append(cursor.fetchall()) + + for i in COMPLE: + cursor.execute('SELECT * FROM COMPLETION_QUESTION_BANK WHERE ID=(?)',(i)) + COMPLELIST.append(cursor.fetchall()) + + for i in JUDGE: + cursor.execute('SELECT * FROM T_OR_F_QUESTION_BANK WHERE ID=(?)',(i)) + JUDGELIST.append(cursor.fetchall()) + + HOUR=TrainID[3] + MIN=TrainID[4] + if int(HOUR)==0: + time=int(MIN) + elif int(MIN)==0: + time=int(HOUR)*60 + else: + time=int(HOUR)*60+int(MIN) + + + dic={'operateID':[CHOICELIST,COMPLELIST,JUDGELIST,Train,time]} + + return dic + + + + +# FetchTrainTestFunc('3') + + +