From 9347c049fd432254fa61f7554bf7fe618ebf8460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=9E=97?= <904079904@qq.com> Date: Wed, 25 Dec 2019 16:49:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=A2=98=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/question/Questionitem_banks.js | 139 ++++++++++++++---- .../question/component/Itembankstop.js | 23 +-- .../question/component/JudquestionEditor.js | 84 ++++++++++- .../question/component/SingleEditor.js | 32 ++++ 4 files changed, 231 insertions(+), 47 deletions(-) diff --git a/public/react/src/modules/question/Questionitem_banks.js b/public/react/src/modules/question/Questionitem_banks.js index c2c0d2a07..b8b19ae4f 100644 --- a/public/react/src/modules/question/Questionitem_banks.js +++ b/public/react/src/modules/question/Questionitem_banks.js @@ -33,7 +33,9 @@ class Questionitem_banks extends Component { this.Judquestio= React.createRef(); this.state = { item_type:null, - item_banksedit:[] + item_banksedit:[], + myquestion_choicesco:[], + } } @@ -80,9 +82,30 @@ class Questionitem_banks extends Component { ////console.log("item_banks"); console.log("Questionitem_banks"); console.log(response.data); - this.setState({ - item_banksedit:response.data, - }) + var choicescomy=[]; + try { + if(this.props.item_banksedit){ + if(this.props.item_banksedit.choices){ + for(var p=0;p { + choicescomy.push({ + choice_text:item.choice_text, + standard_boolean:item.is_answer, + }) + }) + } + + } + }catch (e) { + + } + this.setState({ + item_banksedit:response.data, + myquestion_choicesco:choicescomy, + }) }).catch((error) => { ////console.log(error) @@ -124,7 +147,6 @@ class Questionitem_banks extends Component { } getJudquestio=(Ref)=>{ - debugger this.Judquestio=Ref; } @@ -139,7 +161,20 @@ class Questionitem_banks extends Component { ////console.log(this.contentMdRef.Getdatas()); ////console.log("preservation3333"); ////console.log(this.answerMdRef.onSave()); - var url="/item_banks.json"; + 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()); } @@ -185,16 +220,30 @@ class Questionitem_banks extends Component { 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); + }) } - axios.post(url, data) - .then((result) => { - if (result.data.status == 0) { - this.props.showNotification(`新增单选题成功`); - } - }).catch((error) => { - console.log(error); - }) } @@ -230,15 +279,29 @@ class Questionitem_banks extends Component { analysis:anserdata[3], choices:choices, } - axios.post(url, data) - .then((result) => { - if (result.data.status == 0) { - this.props.showNotification(`新增多选题成功`); + 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); + }) + } - } - }).catch((error) => { - console.log(error); - }) @@ -278,14 +341,28 @@ class Questionitem_banks extends Component { analysis:anserdata[2], choices:choices, } - axios.post(url, data) - .then((result) => { - if (result.data.status == 0) { - this.props.showNotification(`新增判断题成功`); - } - }).catch((error) => { - console.log(error); - }) + + 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); + }) + } + @@ -363,6 +440,7 @@ class Questionitem_banks extends Component { this.getanswerMdRef(ref)} > @@ -385,6 +463,7 @@ class Questionitem_banks extends Component { this.getJudquestio(ref)} > diff --git a/public/react/src/modules/question/component/Itembankstop.js b/public/react/src/modules/question/component/Itembankstop.js index f0400986a..36d75f57b 100644 --- a/public/react/src/modules/question/component/Itembankstop.js +++ b/public/react/src/modules/question/component/Itembankstop.js @@ -88,12 +88,11 @@ class Itembankstop extends Component { } componentDidUpdate(prevProps) { - console.log("componentDidUpdate"); - console.log(prevProps); - console.log(this.props.item_banksedit); + // console.log("componentDidUpdate"); + // console.log(prevProps); + // console.log(this.props.item_banksedit); if(prevProps.item_banksedit !== this.props.item_banksedit){ - debugger this.handleFormtixing(this.props.item_banksedit.item_type); this.handleFormLayoutChange(this.props.item_banksedit.difficulty); } @@ -136,10 +135,10 @@ class Itembankstop extends Component { //console.log("难度塞选"); //console.log(value); this.props.form.setFieldsValue({ - rbnd:value, + rbnd:value+"", }); this.setState({ - rbnd:value, + rbnd:value+"", }) } @@ -169,12 +168,12 @@ class Itembankstop extends Component { //题型 console.log("题型"); console.log(value); - this.props.form.setFieldsValue({ - rbtx:value, - }); this.setState({ - rbtx:value, + rbtx:value+"", }) + this.props.form.setFieldsValue({ + rbtx:value+"", + }); this.props.setitem_type(value); } preventDefault=(e)=> { @@ -212,6 +211,8 @@ class Itembankstop extends Component { const { getFieldDecorator } = this.props.form; console.log("renderrenderrender"); console.log(this.props.item_banksedit); + console.log("renderrenderrendersssss"); + console.log(this.state.rbtx); return (
@@ -310,7 +311,7 @@ class Itembankstop extends Component { } )( - diff --git a/public/react/src/modules/question/component/JudquestionEditor.js b/public/react/src/modules/question/component/JudquestionEditor.js index 28922eafc..a1f618151 100644 --- a/public/react/src/modules/question/component/JudquestionEditor.js +++ b/public/react/src/modules/question/component/JudquestionEditor.js @@ -50,7 +50,9 @@ class JudquestionEditor extends Component{ question_type: this.props.question_type || 0, question_score: this.props.question_score || this.props.init_question_score, question_titles:this.props.question_titles||'', - zqda:null + zqda:null, + item_banksedit:[], + mychoicess:[], } } addOption = () => { @@ -150,6 +152,74 @@ class JudquestionEditor extends Component{ this.props.getanswerMdRef(this); }catch (e) { + } + try { + this.setState({ + item_banksedit:this.props.item_banksedit, + question_title:this.props.item_banksedit.name, + question_titles:this.props.item_banksedit.analysis, + mychoicess:this.props.item_banksedit.choices, + + }) + if(this.props.item_banksedit){ + if(this.props.item_banksedit.choices){ + for(var ik=0;ik { @@ -201,7 +271,9 @@ class JudquestionEditor extends Component{ ////console.log(value); this.setState({ zqda:e.target.value, + }) + } render() { let { question_title, question_score, question_type, question_choices, standard_answers,question_titles} = this.state; @@ -225,7 +297,7 @@ class JudquestionEditor extends Component{ // ////console.log("xuanzheshijuan"); // ////console.log(answerTagArray); // ////console.log(!exerciseIsPublish); - + const params= this.props&&this.props.match&&this.props.match.params; return(