You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/public/react/src/modules/question/Questionitem_banks.js

507 lines
11 KiB

import React, {Component} from "react";
import {Link, NavLink} from 'react-router-dom';
import {WordsBtn, ActionBtn,SnackbarHOC,getImageUrl} from 'educoder';
import axios from 'axios';
import {
notification,
Spin,
Table,
Pagination,
Drawer,
Input,
Button,
Breadcrumb
} from "antd";
import {TPMIndexHOC} from "../tpm/TPMIndexHOC";
import Itembankstop from "./component/Itembankstop";
import NoneData from './component/NoneData';
import './questioncss/questioncom.css';
import Choicequestion from './component/Choicequestion';
import SingleEditor from "./component/SingleEditor";
import ChoquesEditor from "./component/ChoquesEditor"
import JudquestionEditor from "./component/JudquestionEditor";
// var itembankstop=null;
// var singleEditor=null;
// var Judquestio=null;
// var Choques=null;
class Questionitem_banks extends Component {
constructor(props) {
super(props);
this.contentMdRef = React.createRef();
this.answerMdRef = React.createRef();
this.Choques= React.createRef();
this.Judquestio= React.createRef();
this.state = {
item_type:null,
item_banksedit:[],
myquestion_choicesco:[],
}
}
//初始化
componentDidMount(){
// let {defaultActiveKey}= this.state;
// var data={
// public:defaultActiveKey
// };
// this.getdata(data);
//
// let url=`/users/get_navigation_info.json`;
// axios.get(url, {
//
// }).then((response) => {
// // ////console.log("开始请求/get_navigation_info.json");
// // ////console.log(response);
// if(response!=undefined){
// if(response.status===200){
// this.setState({
// Headertop:response.data.top,
// Footerdown:response.data.down
// })
// }
// }
// });
const params= this.props&&this.props.match&&this.props.match.params;
if(JSON.stringify(params)==="{}"){
//新增
}else{
//编辑
const url=`/item_banks/${this.props.match.params.id}/edit.json`;
axios.get((url)).then((response) => {
if(response===null||response===undefined){
return
}
if (response.data.status === 403||response.data.status === 401||response.data.status === 500) {
}else{
}
////console.log("item_banks");
console.log("Questionitem_banks");
console.log(response.data);
this.setState({
item_banksedit:response.data,
})
}).catch((error) => {
////console.log(error)
});
}
}
getdata =(data)=>{
// const url=`/item_banks.json`;
// axios.get((url),{params:data}).then((response) => {
// if(response===null||response===undefined){
//
// return
// }
// if (response.data.status === 403||response.data.status === 401||response.data.status === 500) {
//
// }else{
//
// }
// ////console.log("item_banks");
// ////console.log(response);
// }).catch((error) => {
// ////console.log(error)
//
// });
}
getcontentMdRef=(Ref)=>{
this.contentMdRef=Ref;
}
getanswerMdRef=(Ref)=>{
this.answerMdRef=Ref;
}
getJudquestio=(Ref)=>{
this.Judquestio=Ref;
}
getChoquesEditor=(Ref)=>{
this.Choques=Ref;
}
preservation=()=>{
////console.log("preservation");
// ////console.log(this.contentMdRef);
// ////console.log(this.answerMdRef);
////console.log("preservation222");
////console.log(this.contentMdRef.Getdatas());
////console.log("preservation3333");
////console.log(this.answerMdRef.onSave());
const params= this.props&&this.props.match&&this.props.match.params;
var url="";
var boolnew=true;
if(JSON.stringify(params)==="{}"){
// "新增"
url="/item_banks.json";
boolnew=true;
}else{
url=`/item_banks/${params.id}.json`;
boolnew=false;
// "编辑"
}
if(this.contentMdRef !=null){
console.log(this.contentMdRef.Getdatas());
}
if(this.contentMdRef.Getdatas().length===0){
return;
}
if(this.state.item_type===null ||this.state.item_type==="PROGRAM"){
return
}
if(this.state.item_type==="SINGLE"){
if( this.answerMdRef!=null){
//单选题
// console.log(this.answerMdRef.onSave());
if(this.answerMdRef.onSave().length===0){
return;
}
var anserdata=this.answerMdRef.onSave();
const choices=[];
// 1: [3]
// 2: (4) ["1", "2", "3", "4"]
for(var k=0;k<anserdata[2].length;k++){
const choicesdata={
choice_text:anserdata[2][k],
is_answer:anserdata[1][0]===(k+1)?1:0,
}
choices.push(choicesdata);
}
var data={
repertoire_id:1,
sub_repertoire_id:1,
tag_repertoire_id:[1,3],
name:anserdata[0],
item_type:"SINGLE",
difficulty:2,
analysis:anserdata[3],
choices:choices,
};
if(boolnew===true){
axios.post(url, data)
.then((result) => {
if (result.data.status == 0) {
this.props.showNotification(`新增单选题成功`);
}
}).catch((error) => {
console.log(error);
})
}else{
axios.put(url, data)
.then((result) => {
if (result.data.status == 0) {
this.props.showNotification(`编辑单选题成功`);
}
}).catch((error) => {
console.log(error);
})
}
}
}
if(this.state.item_type==="MULTIPLE"){
if(this.Choques!=null){
//多选题
// console.log(this.Choques.onSave());
if(this.Choques.onSave().length===0){
return;
}
var anserdata=this.Choques.onSave();
const choices=[];
// 1: [3]
// 2: (4) ["1", "2", "3", "4"]
console.log("MULTIPLE");
console.log(anserdata);
for(var k=0;k<anserdata[2].length;k++){
var bool =false
for(var y=0;y<anserdata[1].length;y++){
if(anserdata[1][y]===(k+1)){
bool=true
}
}
const choicesdata={
choice_text:anserdata[2][k],
is_answer:bool===true?1:0,
}
choices.push(choicesdata);
}
var data={
repertoire_id:1,
sub_repertoire_id:1,
tag_repertoire_id:[1,3],
name:anserdata[0],
item_type:"MULTIPLE",
difficulty:2,
analysis:anserdata[3],
choices:choices,
}
if(boolnew===true) {
axios.post(url, data)
.then((result) => {
if (result.data.status == 0) {
this.props.showNotification(`新增多选题成功`);
}
}).catch((error) => {
console.log(error);
})
}else{
axios.put(url, data)
.then((result) => {
if (result.data.status == 0) {
this.props.showNotification(`编辑多选题成功`);
}
}).catch((error) => {
console.log(error);
})
}
}
}
if(this.state.item_type==="JUDGMENT"){
if( this.Judquestio !=null){
//判断题
// console.log(this.Judquestio.onSave());
if(this.Judquestio.onSave().length===0){
return;
}
var anserdata=this.Judquestio.onSave();
const choices=[];
const choicesdata={
choice_text:"正确",
is_answer:anserdata[1]==="0"?1:0,
}
choices.push(choicesdata);
const choicesdatas={
choice_text:"错误",
is_answer:anserdata[1]==="1"?1:0,
}
choices.push(choicesdatas);
var data={
repertoire_id:1,
sub_repertoire_id:1,
tag_repertoire_id:[1,3],
name:anserdata[0],
item_type:"JUDGMENT",
difficulty:2,
analysis:anserdata[2],
choices:choices,
}
if(boolnew===true) {
axios.post(url, data)
.then((result) => {
if (result.data.status == 0) {
this.props.showNotification(`新增判断题成功`);
}
}).catch((error) => {
console.log(error);
})
}else{
axios.put(url, data)
.then((result) => {
if (result.data.status == 0) {
this.props.showNotification(`编辑判断题成功`);
}
}).catch((error) => {
console.log(error);
})
}
}
}
}
setitem_type=(item_type)=>{
this.setState({
item_type:item_type
})
}
render() {
let {page,limit,count,Headertop,visible,placement,modalsType,item_type}=this.state;
{/*<Option value="SINGLE">单选题</Option>*/}
{/*<Option value="MULTIPLE">多选题</Option>*/}
{/*<Option value="JUDGMENT">判断题</Option>*/}
{/*<Option value="PROGRAM">编程题</Option>*/}
////console.log("塞选的数据");
////console.log(item_type);
const params= this.props&&this.props.match&&this.props.match.params;
// console.log(params);
return (
<div className="newMain clearfix intermediatecenter "
style={{
}}
>
<style>
{
`
.newFooter{
display: none;
}
`
}
</style>
<div className="w1200mss">
<div className="w100s mt30">
<Breadcrumb separator=">">
<Breadcrumb.Item href="/question">试题库</Breadcrumb.Item>
<Breadcrumb.Item >{JSON.stringify(params)==="{}"?"新增":"编辑"}试题</Breadcrumb.Item>
</Breadcrumb>
</div>
<Itembankstop
{...this.state}
{...this.props}
getcontentMdRef={(ref)=>this.getcontentMdRef(ref)}
setitem_type={(item)=>this.setitem_type(item)}
>
</Itembankstop>
{
item_type&&item_type==="SINGLE"?
<div className=" clearfix educontent Contentquestionbankstyle w100s w1200fpx mt19" >
<SingleEditor
{...this.state}
{...this.props}
getanswerMdRef={(ref)=>this.getanswerMdRef(ref)}
>
</SingleEditor>
</div>
:item_type&&item_type==="MULTIPLE"?
<div className=" clearfix educontent Contentquestionbankstyle w100s w1200fpx mt19" >
<ChoquesEditor
{...this.state}
{...this.props}
getanswerMdRef={(ref)=>this.getChoquesEditor(ref)}
>
</ChoquesEditor>
</div>
:item_type&&item_type==="JUDGMENT"?
<div className=" clearfix educontent Contentquestionbankstyle w100s w1200fpx mt19" >
<JudquestionEditor
{...this.state}
{...this.props}
item_banksedit={this.state.item_banksedit}
getanswerMdRef={(ref)=>this.getJudquestio(ref)}
>
</JudquestionEditor>
</div>
:item_type&&item_type==="PROGRAM"?
<div className="programcss">
</div>
:""
}
</div>
{
item_type===null?
""
:
<div className=" clearfix bor-bottom-greyE edu-back-white orderingbox newshixunbottombtn bottomdivs sortinxdirection intermediatecenter mt50" style={{
position:"absolute",
bottom: "0px",
}} >
<a href={'/question'}>
<div className="divquxiao mr20 xiaoshou">
<p className="divquxiaotest" >取消</p>
</div>
</a>
<div className="divbaocun xiaoshou"><p className="divbaocuntests" onClick={()=>this.preservation()}>保存</p></div>
</div>
}
</div>
)
}
}
export default SnackbarHOC() (TPMIndexHOC ( Questionitem_banks ));