123
This commit is contained in:
parent
c1a414e712
commit
4e5014a921
|
@ -9,3 +9,8 @@
|
||||||
float: right;
|
float: right;
|
||||||
background-color: #f7f8fa;
|
background-color: #f7f8fa;
|
||||||
}
|
}
|
||||||
|
.appendBox{
|
||||||
|
width: 1200px;
|
||||||
|
height: 300px;
|
||||||
|
background-color: aqua;
|
||||||
|
}
|
|
@ -1,8 +1,271 @@
|
||||||
|
import axios, { all } from 'axios';
|
||||||
import './questionmanage.css'
|
import './questionmanage.css'
|
||||||
|
import React, { useEffect, useState } from 'react';
|
||||||
|
|
||||||
function Questionmange(){
|
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 (
|
return (
|
||||||
<div className="body-right-question"></div>
|
<div className="body-right-question">
|
||||||
|
{!append&&<div>
|
||||||
|
<div>
|
||||||
|
<span>题目类型</span>
|
||||||
|
<select onChange={Click1}>
|
||||||
|
<option value="选择题">选择题</option>
|
||||||
|
<option value='填空题'>填空题</option>
|
||||||
|
<option value='判断题'>判断题</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<span>
|
||||||
|
章节选择
|
||||||
|
<select onChange={Click2}>
|
||||||
|
<option value="第一章">第一章</option>
|
||||||
|
<option value='第二章'>第二章</option>
|
||||||
|
</select>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='ku'>
|
||||||
|
{type==='选择题'&&data&&<table>
|
||||||
|
<tr>
|
||||||
|
<th>题目ID</th><th>题目</th><th>选项A</th><th>选项B</th><th>选项C</th><th>选项D</th><th>正确选项</th>{isTrue&&<th style={{color:'red'}}>选择要删除的题目</th>}
|
||||||
|
</tr>
|
||||||
|
{Object.keys(data).map((key)=>(
|
||||||
|
<tr key={key}>
|
||||||
|
<td>{data[key][7]}</td><td>{data[key][1]}</td><td>{data[key][2]}</td><td>{data[key][3]}</td><td>{data[key][4]}</td><td>{data[key][5]}</td><td>{data[key][6]}</td>{isTrue&&<td><input type="checkbox" onChange={(e) => handChoiceChange(e, data[key][7])} /></td>}
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
|
||||||
|
</table>}
|
||||||
|
{type==='填空题'&&data&&<table>
|
||||||
|
<tr>
|
||||||
|
<th>题目ID</th><th>问题</th><th>答案</th>{isTrue&&<th style={{color:'red'}}>选择要删除的题目</th>}
|
||||||
|
</tr>
|
||||||
|
{Object.keys(data).map((key)=>(
|
||||||
|
<tr key={key}>
|
||||||
|
<td>{data[key][3]}</td><td>{data[key][1]}</td><td>{data[key][2]}</td>{isTrue&&<td><input type="checkbox" onChange={(e) => handCompleChange(e, data[key][3])} /></td>}
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</table>}
|
||||||
|
{type==='判断题'&&data&&<table>
|
||||||
|
<tr>
|
||||||
|
<th>题目ID</th><th>题目</th><th>答案</th>{isTrue&&<th style={{color:'red'}}>选择要删除的题目</th>}
|
||||||
|
</tr>
|
||||||
|
{Object.keys(data).map((key)=>(
|
||||||
|
<tr key={key}>
|
||||||
|
<td>{data[key][3]}</td><td>{data[key][1]}</td><td>{data[key][2]}</td>{isTrue&&<td><input type="checkbox" onChange={(e) => handJudgeChange(e, data[key][3])} /></td>}
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</table>}
|
||||||
|
</div>
|
||||||
|
{!isTrue&&<button onClick={appendClick}>添加题目</button>}{!isTrue&&<button onClick={del1}>删除</button>}
|
||||||
|
{isTrue&&<button onClick={del2}>确定</button>}{isTrue&&<button onClick={cancellation1}>取消</button>}
|
||||||
|
</div>}
|
||||||
|
{append&&<div className='appendBox'>
|
||||||
|
<span>请选择题目类型</span>
|
||||||
|
<select onChange={appendClick1}>
|
||||||
|
<option value="选择题">选择题</option>
|
||||||
|
<option value='填空题'>填空题</option>
|
||||||
|
<option value='判断题'>判断题</option>
|
||||||
|
</select>
|
||||||
|
<span>
|
||||||
|
<span>请选择填入章节</span>
|
||||||
|
<select onChange={appendClick2}>
|
||||||
|
<option value="第一章">第一章</option>
|
||||||
|
<option value='第二章'>第二章</option>
|
||||||
|
</select>
|
||||||
|
</span>
|
||||||
|
{Newtype==='选择题'&&<table>
|
||||||
|
<tr>
|
||||||
|
<td><input type="text" value={inputValue} onChange={handleInputChange} placeholder='请填入选择题题目'/></td>
|
||||||
|
<td><input type="text" value={A} onChange={handleInputA} placeholder='请填入A选项'/></td>
|
||||||
|
<td><input type="text" value={B} onChange={handleInputB} placeholder='请填入B选项'/></td>
|
||||||
|
<td><input type="text" value={C} onChange={handleInputC} placeholder='请填入C选项'/></td>
|
||||||
|
<td><input type="text" value={D} onChange={handleInputD} placeholder='请填入D选项'/></td>
|
||||||
|
<td><input type="text" value={correct} onChange={handleInputTrue} placeholder='请填入正确答案'/></td>
|
||||||
|
</tr>
|
||||||
|
</table>}
|
||||||
|
{Newtype==='填空题'&&<table>
|
||||||
|
<tr>
|
||||||
|
<td><input type="text" value={inputValue} onChange={handleInputChange} placeholder='请填入填空题目'/></td>
|
||||||
|
<td><input type="text" value={correct} onChange={handleInputTrue} placeholder='请填入正确答案'/></td>
|
||||||
|
</tr>
|
||||||
|
</table>}
|
||||||
|
{Newtype==='判断题'&&<table>
|
||||||
|
<tr>
|
||||||
|
<td><input type="text" value={inputValue} onChange={handleInputChange} placeholder='请填入判断题题目'/></td>
|
||||||
|
<tr>
|
||||||
|
<label><input type="radio" name={`Judge`} onChange={handleRadioChange} value={true} />True</label>
|
||||||
|
<label><input type="radio" name={`Judge`} onChange={handleRadioChange} value={false} />False</label>
|
||||||
|
</tr>
|
||||||
|
</tr>
|
||||||
|
</table>}
|
||||||
|
<button onClick={appendQuestion}>添加</button>
|
||||||
|
<button onClick={cancellation2}>取消</button>
|
||||||
|
</div>}
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
export default Questionmange
|
export default Questionmange
|
|
@ -22,9 +22,11 @@ function TrainPods(){
|
||||||
const handleDelete=async(name)=> {
|
const handleDelete=async(name)=> {
|
||||||
try{
|
try{
|
||||||
const delPods=await axios.post('/api/teacher/DelPods',{
|
const delPods=await axios.post('/api/teacher/DelPods',{
|
||||||
name
|
name,
|
||||||
})
|
})
|
||||||
alert('删除成功')
|
alert('删除成功')
|
||||||
|
// eslint-disable-next-line no-restricted-globals
|
||||||
|
location.reload();
|
||||||
}catch{
|
}catch{
|
||||||
alert('出错')
|
alert('出错')
|
||||||
}
|
}
|
||||||
|
|
|
@ -306,6 +306,38 @@ def FindSrc():
|
||||||
data=FindSrcFunc(studentID,testID)
|
data=FindSrcFunc(studentID,testID)
|
||||||
return jsonify({'data':data})
|
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
|
@app.route("/api/teacher/list_pods",methods=['POST']) # 列出pod
|
||||||
|
@ -319,9 +351,12 @@ def teacher_list_services():
|
||||||
# def teacher_create_pod():
|
# def teacher_create_pod():
|
||||||
# create_pod(1, "test2")
|
# create_pod(1, "test2")
|
||||||
#
|
#
|
||||||
@app.route("/api/teacher/delete_pod",methods=['POST']) # 删除服务
|
@app.route("/api/teacher/DelPods",methods=['POST']) # 删除服务
|
||||||
def teacher_delete_pod():
|
def teacher_delete_pod():
|
||||||
name=request.json['name']
|
name=request.json['name']
|
||||||
|
studentID=name[1:9]
|
||||||
|
testID=name[10:]
|
||||||
|
delDMFunc(studentID,testID)
|
||||||
return delete_pod(name=name)
|
return delete_pod(name=name)
|
||||||
|
|
||||||
@app.route("/api/student/check_pod",methods=['POST']) # 检测数据库是否安装成功 若成功,返回OK 否则返回NO
|
@app.route("/api/student/check_pod",methods=['POST']) # 检测数据库是否安装成功 若成功,返回OK 否则返回NO
|
||||||
|
|
|
@ -395,6 +395,62 @@ def FindSrcFunc(studentID, testID):
|
||||||
cursor.close()
|
cursor.close()
|
||||||
return data
|
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')
|
# 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'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue