diff --git a/app-dm/src/TeacherPages/Questionmanage/questionmanage.css b/app-dm/src/TeacherPages/Questionmanage/questionmanage.css index b69db30..cff3c12 100644 --- a/app-dm/src/TeacherPages/Questionmanage/questionmanage.css +++ b/app-dm/src/TeacherPages/Questionmanage/questionmanage.css @@ -8,4 +8,9 @@ border-radius: 10px; float: right; background-color: #f7f8fa; +} +.appendBox{ + width: 1200px; + height: 300px; + background-color: aqua; } \ No newline at end of file diff --git a/app-dm/src/TeacherPages/Questionmanage/questionmanage.jsx b/app-dm/src/TeacherPages/Questionmanage/questionmanage.jsx index a853e21..201cecc 100644 --- a/app-dm/src/TeacherPages/Questionmanage/questionmanage.jsx +++ b/app-dm/src/TeacherPages/Questionmanage/questionmanage.jsx @@ -1,8 +1,271 @@ +import axios, { all } from 'axios'; import './questionmanage.css' +import React, { useEffect, useState } from 'react'; function Questionmange(){ + const [isTrue,setisTrue]=useState(false) + + const [ChoiceItem, setChoiceItems] = useState([]); + const [CompleItem, setCompleItems] = useState([]); + const [JudgeItem, setJudgeItems] = useState([]); + + const [NewChoice,setNewChoice]=useState([]) + + + const [Newtype,setNewtype]=useState('选择题') + const [Newchapter,setNewchapter]=useState('第一章') + + + const [inputValue, setInputValue] = useState(''); + const [A,setA]=useState('') + const [B,setB]=useState('') + const [C,setC]=useState('') + const [D,setD]=useState('') + const [correct,setcorrect]=useState('') + const [judgeValue, setJudgeValue] = useState(''); + + const appendClick1=(event)=>{ + setNewtype(event.target.value) + } + + const appendClick2=(event)=>{ + setNewchapter(event.target.value) + } + + const handleInputChange = (event) => { + setInputValue(event.target.value); + }; + + const handleInputA=(event)=>{ + setA(event.target.value) + } + const handleInputB=(event)=>{ + setB(event.target.value) + } + const handleInputC=(event)=>{ + setC(event.target.value) + } + const handleInputD=(event)=>{ + setD(event.target.value) + } + const handleInputTrue = (event) => { + setcorrect(event.target.value); + }; + + + const handleRadioChange = (event) => { + setJudgeValue(event.target.value); + }; + + + const handChoiceChange = (event, item) => { + if (event.target.checked) { + setChoiceItems(prevItems => [...prevItems, item]); + } else { + setChoiceItems(prevItems => prevItems.filter(i => i !== item)); + } + }; + const handCompleChange = (event, item) => { + if (event.target.checked) { + setCompleItems(prevItems => [...prevItems, item]); + } else { + setCompleItems(prevItems => prevItems.filter(i => i !== item)); + } + }; + const handJudgeChange = (event, item) => { + if (event.target.checked) { + setJudgeItems(prevItems => [...prevItems, item]); + } else { + setJudgeItems(prevItems => prevItems.filter(i => i !== item)); + } + }; + + + const [type,settype]=useState('选择题') + const [chapter,setchapter]=useState('第一章') + + const Click1=(event)=>{ + console.log(event.target.value); + settype(event.target.value) + } + const Click2=(event)=>{ + console.log(event.target.value); + setchapter(event.target.value) + } + const [data,setdata]=useState() + const FindQuestion=async()=>{ + try{ + const FindQuestionSrc=await axios.post('/api/teacher/FindQuestion',{ + type, + chapter + }) + setdata(FindQuestionSrc.data['data']) + }catch{ + alert('错误') + } + } + useEffect(()=>{ + FindQuestion() + },[chapter,type]) + + const del1=()=>{ + setisTrue(true) + } + const del2=async()=>{ + try{ + const del2Src=await axios.post('/api/teacher/DelQuestion',{ + type, + chapter, + ChoiceItem, + CompleItem, + JudgeItem + }) + alert('删除成功') + window.location.reload(); + }catch{ + alert('删除功能出错') + } + } + const[append,setappend]=useState(false) + + const appendClick=()=>{ + + setappend(true) + } + + const cancellation2=()=>{ + setInputValue('') + setA('') + setB('') + setC('') + setD('') + setcorrect('') + setJudgeValue('') + setappend(false) + } + const cancellation1=()=>{ + setisTrue(!isTrue) + setChoiceItems([]) + setCompleItems([]) + setJudgeItems([]) + } + + const appendQuestion=async()=>{ + try{ + const appendQuestionSrc=await axios.post('/api/teacher/appendQuestion',{ + Newtype, + Newchapter, + inputValue, + A,B,C,D,correct, + judgeValue + }) + alert('添加成功') + window.location.reload(); + }catch{ + alert('添加题目出错') + } + } + + return ( -
+
+ {!append&&
+
+ 题目类型 + + + + 章节选择 + + +
+ +
+ {type==='选择题'&&data&& + + {isTrue&&} + + {Object.keys(data).map((key)=>( + + {isTrue&&} + + ))} + +
题目ID题目选项A选项B选项C选项D正确选项选择要删除的题目
{data[key][7]}{data[key][1]}{data[key][2]}{data[key][3]}{data[key][4]}{data[key][5]}{data[key][6]} handChoiceChange(e, data[key][7])} />
} + {type==='填空题'&&data&& + + {isTrue&&} + + {Object.keys(data).map((key)=>( + + {isTrue&&} + + ))} +
题目ID问题答案选择要删除的题目
{data[key][3]}{data[key][1]}{data[key][2]} handCompleChange(e, data[key][3])} />
} + {type==='判断题'&&data&& + + {isTrue&&} + + {Object.keys(data).map((key)=>( + + {isTrue&&} + + ))} +
题目ID题目答案选择要删除的题目
{data[key][3]}{data[key][1]}{data[key][2]} handJudgeChange(e, data[key][3])} />
} +
+ {!isTrue&&}{!isTrue&&} + {isTrue&&}{isTrue&&} +
} + {append&&
+ 请选择题目类型 + + + 请选择填入章节 + + + {Newtype==='选择题'&& + + + + + + + + +
} + {Newtype==='填空题'&& + + + + +
} + {Newtype==='判断题'&& + + + + + + + +
} + + +
} +
) } export default Questionmange \ No newline at end of file diff --git a/app-dm/src/TeacherPages/Trainmanage/TrainPods.jsx b/app-dm/src/TeacherPages/Trainmanage/TrainPods.jsx index df02232..dff8e84 100644 --- a/app-dm/src/TeacherPages/Trainmanage/TrainPods.jsx +++ b/app-dm/src/TeacherPages/Trainmanage/TrainPods.jsx @@ -22,9 +22,11 @@ function TrainPods(){ const handleDelete=async(name)=> { try{ const delPods=await axios.post('/api/teacher/DelPods',{ - name + name, }) alert('删除成功') + // eslint-disable-next-line no-restricted-globals + location.reload(); }catch{ alert('出错') } diff --git a/python/app.py b/python/app.py index 9e9e078..bc42c82 100644 --- a/python/app.py +++ b/python/app.py @@ -306,6 +306,38 @@ def FindSrc(): data=FindSrcFunc(studentID,testID) return jsonify({'data':data}) +@app.route('/api/teacher/FindQuestion',methods=["POST"]) +def FindQuestion(): + chapter=request.json['chapter'] + subject=request.json['type'] + data=FindQuestionFunc(subject,chapter) + return jsonify({'data':data}) + +@app.route('/api/teacher/DelQuestion',methods=["POST"]) +def DelQuestion(): + subject=request.json['type'] + chapter=request.json['chapter'] + ChoiceItem=request.json['ChoiceItem'] + CompleItem=request.json['CompleItem'] + JudgeItem=request.json['JudgeItem'] + DelQuestionFunc(subject,chapter,ChoiceItem,CompleItem,JudgeItem) + return '删除成功' + +@app.route('/api/teacher/appendQuestion',methods=["POST"]) +def appendQuestion(): + subject = request.json['Newtype'] + chapter=request.json['Newchapter'] + inputValue=request.json['inputValue'] + A,B,C,D=request.json['A'],request.json['B'],request.json['C'],request.json['D'] + correct=request.json['correct'] + judgeValue=request.json['judgeValue'] + appendQuestionFunc(subject,chapter,inputValue,A,B,C,D,correct,judgeValue) + return '添加成功' + + + + + @app.route("/api/teacher/list_pods",methods=['POST']) # 列出pod @@ -319,9 +351,12 @@ def teacher_list_services(): # def teacher_create_pod(): # create_pod(1, "test2") # -@app.route("/api/teacher/delete_pod",methods=['POST']) # 删除服务 +@app.route("/api/teacher/DelPods",methods=['POST']) # 删除服务 def teacher_delete_pod(): name=request.json['name'] + studentID=name[1:9] + testID=name[10:] + delDMFunc(studentID,testID) return delete_pod(name=name) @app.route("/api/student/check_pod",methods=['POST']) # 检测数据库是否安装成功 若成功,返回OK 否则返回NO diff --git a/python/teacher_func.py b/python/teacher_func.py index 6d05176..563def7 100644 --- a/python/teacher_func.py +++ b/python/teacher_func.py @@ -78,7 +78,7 @@ def find_classboss_succeed_func(teacher_id): # find_classboss_succeed_func('111111') -def find_student_succeed_func(ID): +def find_student_succeed_func(ID): cursor=db.cursor() cursor.execute(f'SELECT * FROM STUDENT WHERE ID={ID}') student_succeed=cursor.fetchall()[0] @@ -395,6 +395,62 @@ def FindSrcFunc(studentID, testID): cursor.close() return data + +def delDMFunc(studentID, testID): + cursor = db.cursor() + cursor.execute(f'DELETE FROM TRAINSCORE WHERE STUDENT_ID=? AND TEST_ID=?',(studentID,testID)) + db.commit() + cursor.close() + print('删除成功') + return 'DELETE' + + # FindSrcFunc('20240101','68') +def FindQuestionFunc(type,chapter): + cursor = db.cursor() + if type=='选择题': + cursor.execute(f'SELECT * FROM CHOICE_QUESTION_BANK WHERE SUBJECT=? AND CHAPTER=? ',('Train',chapter)) + data = cursor.fetchall() + elif type=='填空题': + cursor.execute(f'SELECT * FROM COMPLETION_QUESTION_BANK WHERE SUBJECT=? AND CHAPTER=? ',('Train',chapter)) + data = cursor.fetchall() + elif type=='判断题': + cursor.execute(f'SELECT * FROM T_OR_F_QUESTION_BANK WHERE SUBJECT=? AND CHAPTER=? ',('Train',chapter)) + data = cursor.fetchall() + print(data) + cursor.close() + return data + +# FindQuestionFunc('选择题','第一章') + + +def DelQuestionFunc(subject, chapter,ChoiceItem,CompleItem,JudgeItem): + cursor = db.cursor() + if subject=='选择题': + for i in ChoiceItem: + cursor.execute(f'DELETE FROM CHOICE_QUESTION_BANK WHERE ID=? AND CHAPTER=?',(i,chapter)) + elif subject=='填空题': + for i in CompleItem: + cursor.execute(f'DELETE FROM COMPLETION_QUESTION_BANK WHERE ID=? AND CHAPTER=? ',(i,chapter)) + elif subject=='判断题': + for i in JudgeItem: + cursor.execute(f'DELETE FROM T_OR_F_QUESTION_BANK WHERE ID=? AND CHAPTER=? ',(i,chapter)) + db.commit() + cursor.close() + print('删除成功') + return 'DELETE' + +def appendQuestionFunc(subject,chapter,inputValue,A,B,C,D,correct,judgeValue): + cursor = db.cursor() + if subject=='选择题': + cursor.execute(f'INSERT INTO CHOICE_QUESTION_BANK(SUBJECT,CHOICE,OPTION_A,OPTION_B,OPTION_C,OPTION_D,CORRECT,CHAPTER) VALUES (?,?,?,?,?,?,?,?)',('Train',inputValue,A,B,C,D,correct,chapter)) + elif subject=='填空题': + cursor.execute(f'INSERT INTO COMPLETION_QUESTION_BANK(SUBJECT,COMPLETION,CORRECT,CHAPTER) VALUES (?,?,?,?)',('Train',inputValue,correct,chapter)) + elif subject=='判断题': + cursor.execute(f'INSERT INTO T_OR_F_QUESTION_BANK(SUBJECT,T_OR_F,CORRECT,CHAPTER) VALUES (?,?,?,?)',('Train',inputValue,judgeValue,chapter)) + db.commit() + cursor.close() + print('插入成功') + return 'INSERT'