From c5b41a28920123c0158da748a1122dbc114bd8d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=9E=97?= <904079904@qq.com> Date: Sat, 31 Aug 2019 11:10:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../react/src/modules/courses/poll/PollNew.js | 10 +- .../modules/courses/poll/PollNewQuestbank.js | 1346 +++++++++-------- 2 files changed, 749 insertions(+), 607 deletions(-) diff --git a/public/react/src/modules/courses/poll/PollNew.js b/public/react/src/modules/courses/poll/PollNew.js index 091f45b94..aab316d82 100644 --- a/public/react/src/modules/courses/poll/PollNew.js +++ b/public/react/src/modules/courses/poll/PollNew.js @@ -1752,7 +1752,7 @@ class PollNew extends Component { question = {"question": questiontwo}; if (uuk !== -1) { // console.log("修改") - this.edittotheserver(object, 3, null, null, 0, 0,0); + this.edittotheserver(object, 3, null, null, 0, 0,0,0); newarrpoll.splice(uuk, 1, question); } else { // console.log("删除") @@ -1859,10 +1859,10 @@ class PollNew extends Component { max_choicess = max_choices; min_choicess = min_choices; } - console.log("createquestionsandanswers"); - console.log(max_choicess); - console.log(min_choicess); - console.log(length); + // console.log("createquestionsandanswers"); + // console.log(max_choicess); + // console.log(min_choicess); + // console.log(length); axios.put(url, { // debug: true, question_title: object.question.question_title, diff --git a/public/react/src/modules/courses/poll/PollNewQuestbank.js b/public/react/src/modules/courses/poll/PollNewQuestbank.js index 35e2a60ae..f86e8515d 100644 --- a/public/react/src/modules/courses/poll/PollNewQuestbank.js +++ b/public/react/src/modules/courses/poll/PollNewQuestbank.js @@ -13,6 +13,7 @@ import axios from 'axios' import moment from "../new/CoursesNew"; import Modals from "../../modals/Modals"; import PollListItem from "./PollListItem"; +import TPMMDEditor from '../../tpm/challengesnew/TPMMDEditor'; const TextArea = Input.TextArea const RadioGroup = Radio.Group @@ -36,12 +37,13 @@ class PollNewQuestbank extends Component { constructor(props) { super(props); + this.contentMdRef = React.createRef(); this.state = { visible: false, poll_questions: [], user_permission: "", addonAfter: 0, - addonAftertwo: 100, + addonAftertwo: 0, mysingles: 0, mydoubles: 0, mymainsint: 0, @@ -52,8 +54,8 @@ class PollNewQuestbank extends Component { polls_nametest: "", polls_description: "", polls_descriptiontest: "", - storagedesc:"", - storagedesctwo:"", + storagedesc: "", + storagedesctwo: "", coursesId: "", pollid: undefined, polls_status: undefined, @@ -67,10 +69,10 @@ class PollNewQuestbank extends Component { problemtopicbool: false, newoption: false, cancellation: false, - bindingid:undefined, - Newdisplay:false, - first_category_url:"", - left_banner_id:"", + bindingid: undefined, + Newdisplay: false, + first_category_url: "", + left_banner_id: "", } // console.log("试卷新建和编辑"); // console.log(JSON.stringify(props)); @@ -80,7 +82,7 @@ class PollNewQuestbank extends Component { changeTopicName = (e) => { // console.log("调用了changeTopicName"); let num = parseInt(e.target.value.length); - if(num>60){ + if (num > 60) { return; } this.setState({ @@ -106,7 +108,7 @@ class PollNewQuestbank extends Component { // 初始化数据 componentDidMount = () => { // console.log("componentDidMount 50") - if( this.props.isStudent() === true){ + if (this.props.isStudent() === true) { this.props.history.push("/403") @@ -122,27 +124,28 @@ class PollNewQuestbank extends Component { // cancellation: true, // }) // } else { - this.Initializatio_data(); - this.state.Newedit === false; - this.setState({ - Newedit: false, - mysave: false, - readOnlys: "readOnly", - }) - // } + + this.Initializatio_data(); + this.state.Newedit === false; + this.setState({ + Newedit: false, + mysave: false, + readOnlys: "readOnly", + }) + // } // } console.log("问卷返回"); console.log(this.props); try { - if(this.props.current_user!==undefined){ + if (this.props.current_user !== undefined) { this.setState({ - first_category_url :this.props.current_user.first_category_url, + first_category_url: this.props.current_user.first_category_url, }); console.log("======================="); console.log(this.props.current_user.first_category_url); } - }catch (e) { + } catch (e) { console.log("12312312312") console.log(e); } @@ -152,12 +155,12 @@ class PollNewQuestbank extends Component { // console.log("componentDidUpdate"); // console.log(prevProps); // console.log(this.props); - if(prevProps.current_user!=this.props.current_user){ - if(this.props.current_user!==undefined){ + if (prevProps.current_user != this.props.current_user) { + if (this.props.current_user !== undefined) { // console.log(this.props.current_user.login); // console.log(prevProps.current_user.login); this.setState({ - first_category_url :this.props.current_user.first_category_url, + first_category_url: this.props.current_user.first_category_url, }) } } @@ -243,7 +246,7 @@ class PollNewQuestbank extends Component { } else { const url = `/exercise_banks/${pollid}.json`; axios.get(url).then((result) => { - if (result){ + if (result) { console.log("247"); console.log(result); @@ -251,10 +254,10 @@ class PollNewQuestbank extends Component { } - if(result.data){ - if(result.data.poll){ - if(result.data.poll.polls_name){ - let num = parseInt(result.data.poll.polls_name.length); + if (result.data) { + if (result.data.poll) { + if (result.data.poll.polls_name) { + let num = parseInt(result.data.poll.polls_name.length); this.setState({ addonAfter: num < 0 ? 0 : num }) @@ -266,7 +269,7 @@ class PollNewQuestbank extends Component { this.setState({ projects: result.data, pollid: pollid, - polls_status: result.data.poll.is_public===false?1:2, + polls_status: result.data.poll.is_public === false ? 1 : 2, polls_name: result.data.poll.name, polls_description: result.data.poll.description, poll_questions: result.data.questions, @@ -278,16 +281,29 @@ class PollNewQuestbank extends Component { polls_nametest: result.data.poll.name, polls_descriptiontest: result.data.poll.description, questionnair: true, - left_banner_id:result.data.left_banner_id + left_banner_id: result.data.left_banner_id }) - if(result.data.poll.name){ - if(result.data.poll.name.length>0){ - this.setState({ - addonAfter:result.data.poll.name.length, - }) + if (result.data.poll.name) { + if (result.data.poll.name.length > 0) { + this.setState({ + addonAfter: result.data.poll.name.length, + }) + } + } + try { + const crumbData={ + title:'编辑', + is_public:result && result.data && result.data.is_public, + crumbArray:[ + {to:`/banks/poll/${pollid}`,content:'详情'}, + {content:'编辑'} + ] } - } + this.props.initPublic(crumbData); + }catch (e) { + + } }).catch((error) => { console.log(error) }) @@ -311,33 +327,30 @@ class PollNewQuestbank extends Component { const url = `/exercise_banks/${pollidsy}.json`; axios.get(url).then((result) => { - if (result !== undefined){ - this.setState({ - projects: result.data, - pollid: pollid, - polls_status: result.data.poll.is_public===false?1:2, - polls_name: result.data.poll.name, - polls_description: result.data.poll.description, - poll_questions: result.data.questions, - question_types: result.data.question_types, - mysingles: result.data.question_types.q_singles, - mydoubles: result.data.question_types.q_doubles, - mymainsint: result.data.question_types.q_mains, - q_counts: result.data.question_types.q_counts, - polls_nametest: result.data.poll.name, - polls_descriptiontest: result.data.poll.description, - questionnair: true, - left_banner_id:result.data.left_banner_id - }); - - - + if (result !== undefined) { + this.setState({ + projects: result.data, + pollid: pollidsy, + polls_status: result.data.poll.is_public === false ? 1 : 2, + polls_name: result.data.poll.name, + polls_description: result.data.poll.description, + poll_questions: result.data.questions, + question_types: result.data.question_types, + mysingles: result.data.question_types.q_singles, + mydoubles: result.data.question_types.q_doubles, + mymainsint: result.data.question_types.q_mains, + q_counts: result.data.question_types.q_counts, + polls_nametest: result.data.poll.name, + polls_descriptiontest: result.data.poll.description, + questionnair: true, + left_banner_id: result.data.left_banner_id + }); - if(result.data.poll.name){ - if(result.data.poll.name.length>0){ + if (result.data.poll.name) { + if (result.data.poll.name.length > 0) { this.setState({ - addonAfter:result.data.poll.name.length, + addonAfter: result.data.poll.name.length, }) } } @@ -346,7 +359,6 @@ class PollNewQuestbank extends Component { // console.log("有问卷~~~") - // } }).catch((error) => { console.log(error) @@ -384,7 +396,7 @@ class PollNewQuestbank extends Component { }) } this.setState({ - Newdisplay:true, + Newdisplay: true, }) var Insertposition = this.state.poll_questions.length; // console.log(JSON.stringify(this.state.poll_questions)); @@ -407,7 +419,7 @@ class PollNewQuestbank extends Component { }) } this.setState({ - Newdisplay:true, + Newdisplay: true, }) var Insertposition = this.state.poll_questions.length; // console.log(JSON.stringify(this.state.poll_questions)); @@ -426,7 +438,7 @@ class PollNewQuestbank extends Component { //添加主观题目 addmymainsint = () => { this.setState({ - Newdisplay:true, + Newdisplay: true, }) var Insertposition = this.state.poll_questions.length; // console.log(JSON.stringify(this.state.poll_questions)); @@ -453,7 +465,7 @@ class PollNewQuestbank extends Component { var anserbool = false; this.setState({ q_countst: 1, - bindingid:object.question.id + bindingid: object.question.id }) // window.scrollTo(0, this.refs.targetElement.offsetTops) let {adddom} = this.state; @@ -631,13 +643,13 @@ class PollNewQuestbank extends Component { var question = {} var questiontwo = { // "id": this.state.poll_questions[arr.length - 1].question.id + 1 + arrr.length, - "id": Whether=== true? id :this.state.poll_questions[newarr.length - 1].question.id, + "id": Whether === true ? id : this.state.poll_questions[newarr.length - 1].question.id, "is_necessary": 1, "question_number": 1, "question_title": "", "question_type": 1, "new": "new", - "newid":Whether=== true? id :this.state.poll_questions[newarr.length - 1].question.id + 1, + "newid": Whether === true ? id : this.state.poll_questions[newarr.length - 1].question.id + 1, "answers": [ {"answer_id": 1, "answer_position": 1, "answer_text": ""}, {"answer_id": 2, "answer_position": 2, "answer_text": ""}, @@ -659,7 +671,7 @@ class PollNewQuestbank extends Component { //插入多选题 var question = {} var questiontwo = { - "id": Whether=== true? id :this.state.poll_questions[newarr.length - 1].question.id, + "id": Whether === true ? id : this.state.poll_questions[newarr.length - 1].question.id, "is_necessary": 1, "question_number": 2, "question_title": "", @@ -667,7 +679,7 @@ class PollNewQuestbank extends Component { "max_choices": 0, "min_choices": 0, "new": "new", - "newid":Whether=== true? id :this.state.poll_questions[newarr.length - 1].question.id + 1, + "newid": Whether === true ? id : this.state.poll_questions[newarr.length - 1].question.id + 1, "answers": [ {"answer_id": 1, "answer_position": 1, "answer_text": ""}, {"answer_id": 2, "answer_position": 2, "answer_text": ""}, @@ -690,13 +702,13 @@ class PollNewQuestbank extends Component { // console.log(this.state.poll_questions[newarr.length - 1].question.id); var question = {} var questiontwo = { - "id": Whether=== true? id :this.state.poll_questions[newarr.length - 1].question.id, + "id": Whether === true ? id : this.state.poll_questions[newarr.length - 1].question.id, "is_necessary": 1, "question_number": 3, "question_title": "", "question_type": 3, "new": "new", - "newid":Whether=== true? id :this.state.poll_questions[newarr.length - 1].question.id + 1, + "newid": Whether === true ? id : this.state.poll_questions[newarr.length - 1].question.id + 1, "answers": [] }; question = {"question": questiontwo}; @@ -716,17 +728,17 @@ class PollNewQuestbank extends Component { try { ids = this.state.poll_questions[newarr.length - 1].question.id; } catch (e) { - ids= 1; + ids = 1; } var questiontwo = { // "id": this.state.poll_questions[arr.length - 1].question.id + 1 + arrr.length, - "id": Whether=== true? id :ids, + "id": Whether === true ? id : ids, "is_necessary": 1, "question_number": 1, "question_title": "", "question_type": 1, "new": "new", - "newid":Whether=== true? id :ids+ 1, + "newid": Whether === true ? id : ids + 1, "answers": [ {"answer_id": 1, "answer_position": 1, "answer_text": ""}, {"answer_id": 2, "answer_position": 2, "answer_text": ""}, @@ -753,7 +765,7 @@ class PollNewQuestbank extends Component { ids = 1; } var questiontwo = { - "id": Whether=== true? id :ids, + "id": Whether === true ? id : ids, "is_necessary": 1, "question_number": 2, "question_title": "", @@ -761,7 +773,7 @@ class PollNewQuestbank extends Component { "max_choices": 0, "min_choices": 0, "new": "new", - "newid":Whether=== true? id :ids+1, + "newid": Whether === true ? id : ids + 1, "answers": [ {"answer_id": 1, "answer_position": 1, "answer_text": ""}, {"answer_id": 2, "answer_position": 2, "answer_text": ""}, @@ -783,18 +795,18 @@ class PollNewQuestbank extends Component { //插入主观题 var ids; try { - ids= this.state.poll_questions[newarr.length - 1].question.id; + ids = this.state.poll_questions[newarr.length - 1].question.id; } catch (e) { ids = 1; } var questiontwo = { - "id":Whether=== true? id : ids, + "id": Whether === true ? id : ids, "is_necessary": 1, "question_number": 3, "question_title": "", "question_type": 3, "new": "new", - "newid":Whether=== true? id :ids + 1, + "newid": Whether === true ? id : ids + 1, "answers": [] }; question = {"question": questiontwo}; @@ -809,53 +821,55 @@ class PollNewQuestbank extends Component { } //删除指定条目 - Deleteadddom = (indexo,bool) => { + Deleteadddom = (indexo, bool) => { // console.log("deleteadddom 259") var arr = this.state.adddom; let newarr = [...arr]; newarr.splice(indexo, 1); - if(bool === true) { + if (bool === true) { this.setState({ adddom: newarr, q_countst: 0, problemtopic: null, problemtopicbool: false, - bindingid:undefined, - Newdisplay:false, + bindingid: undefined, + Newdisplay: false, newoption: false, }) - }else{ + } else { this.setState({ adddom: newarr, q_countst: 0, problemtopic: null, problemtopicbool: false, - Newdisplay:false, + Newdisplay: false, newoption: false, }) } - } //保存并继续 //保存并继续,即提交本题的新建并继续创建一个相同的题(该新题处于编辑模式,题目和选项不要清空) - Deleteadddomtwo = (indexo, object,bool) => { + Deleteadddomtwo = (indexo, object, bool) => { var thiss = this; - if(bool === true){ + if (bool === true) { this.setState({ q_countst: 1, - bindingid:undefined, - Newdisplay:false, + bindingid: undefined, + Newdisplay: false, }) - }else { + } else { this.setState({ q_countst: 1, - Newdisplay:false, + Newdisplay: false, }) } + if (object.question.question_type === 3) { + this.HandleInputTopics(this.contentMdRef.current.getValue().trim(), indexo); + } var poll_questionslength = this.state.poll_questions.length; // console.log("deleteadddomtwo|||||||||||||||||||||||||||||||||||||||||\\"); // console.log(indexo); @@ -881,10 +895,12 @@ class PollNewQuestbank extends Component { console.log(e) } } - if (newarr[indexo].question.question_title === "") { - this.props.showNotification(`题目不能为空`); + if (object.question.question_type !== 3) { + if (newarr[indexo].question.question_title === "") { + this.props.showNotification(`题目不能为空`); - return + return + } } if (max > 0) { if (object.question.question_type === 1) { @@ -912,8 +928,6 @@ class PollNewQuestbank extends Component { } - - if (object.question.question_type === 2) { if (object.question.max_choices > 0) { // if (object.question.min_choices < 2) { @@ -988,7 +1002,7 @@ class PollNewQuestbank extends Component { if (this.state.problemtopicbool === true) { insindex = this.state.problemtopic; } - this.createquestionsandanswers(object, 1, arrc, null, 0, 0, insindex); + this.createquestionsandanswers(object, 1, arrc, null, 0, 0, insindex,0); // newarrpoll.push(question); newarrpoll.splice(thiss.state.Insertposition, 0, question); @@ -1048,7 +1062,7 @@ class PollNewQuestbank extends Component { if (this.state.problemtopicbool === true) { insindex = this.state.problemtopic; } - this.createquestionsandanswers(object, 2, arrc, null, object.question.max_choices, object.question.min_choices, insindex); + this.createquestionsandanswers(object, 2, arrc, null, object.question.max_choices, object.question.min_choices, insindex,object.question.answers.length); //插入多选题 // if (object.question.max_choices > arrc.length) { // // console.log("选择题的最大可选项不能大于选项数") @@ -1066,6 +1080,7 @@ class PollNewQuestbank extends Component { // newarrpoll.push(question); newarrpoll.splice(thiss.state.Insertposition, 0, question); } else if (object.question.question_type === 3) { + // this.HandleInputTopics(this.contentMdRef.current.getValue().trim(),indexo); //插入主观题 var answers = []; var questiontwo = {}; @@ -1103,7 +1118,7 @@ class PollNewQuestbank extends Component { "id": null, "is_necessary": object.question.is_necessary, "question_number": 3, - "question_title": object.question.question_title, + "question_title": this.contentMdRef.current.getValue().trim(), "question_type": 3, "new": "", "answers": answers @@ -1118,7 +1133,7 @@ class PollNewQuestbank extends Component { if (this.state.problemtopicbool === true) { insindex = this.state.problemtopic; } - this.createquestionsandanswers(object, 3, null, null, 0, 0, insindex); + this.createquestionsandanswers(object, 3, null, null, 0, 0, insindex,0); // newarrpoll.push(question); newarrpoll.splice(thiss.state.Insertposition, 0, question); } @@ -1181,11 +1196,11 @@ class PollNewQuestbank extends Component { question = {"question": questiontwo}; if (uuk !== -1) { // console.log("修改") - this.edittotheserver(object, 1, arrc, null, 0, 0); + this.edittotheserver(object, 1, arrc, null, 0, 0,0); newarrpoll.splice(uuk, 1, question); } else { // console.log("他原来的删除掉了") - this.createquestionsandanswers(object, 1, arrc, null, 0, 0, object.question.id); + this.createquestionsandanswers(object, 1, arrc, null, 0, 0, object.question.id,0); newarrpoll.push(question); } newarr[indexo].question.new = "new" @@ -1252,16 +1267,18 @@ class PollNewQuestbank extends Component { // } if (uuk !== -1) { // console.log("修改") - this.edittotheserver(object, 2, arrc, null, object.question.max_choices, object.question.min_choices); + this.edittotheserver(object, 2, arrc, null, object.question.max_choices, object.question.min_choices,object.question.answers.length); newarrpoll.splice(uuk, 1, question); } else { // console.log("删除") - this.createquestionsandanswers(object, 2, arrc, null, object.question.max_choices, object.question.min_choices, object.question.id); + this.createquestionsandanswers(object, 2, arrc, null, object.question.max_choices, object.question.min_choices, object.question.id,object.question.answers.length); newarrpoll.push(question); } // console.log(newarrpoll) newarr[indexo].question.new = "new" } else if (object.question.question_type === 3) { + // this.HandleInputTopics(this.contentMdRef.current.getValue().trim(),indexo); + //插入主观题 var answers = []; var questiontwo = {}; @@ -1289,7 +1306,7 @@ class PollNewQuestbank extends Component { "id": object.question.id, "is_necessary": object.question.is_necessary, "question_number": 3, - "question_title": object.question.question_title, + "question_title": this.contentMdRef.current.getValue().trim(), "question_type": 3, "new": "", "answers": answers @@ -1298,11 +1315,11 @@ class PollNewQuestbank extends Component { if (uuk !== -1) { // console.log("修改") - this.edittotheserver(object, 3, null, null, 0, 0); + this.edittotheserver(object, 3, null, null, 0, 0,0); newarrpoll.splice(uuk, 1, question); } else { // console.log("删除") - this.createquestionsandanswers(object, 3, null, null, 0, 0, object.question.id); + this.createquestionsandanswers(object, 3, null, null, 0, 0, object.question.id,0); newarrpoll.push(question); } // console.log(newarrpoll) @@ -1342,15 +1359,19 @@ class PollNewQuestbank extends Component { //保存,即完成新建并退出本题编辑 // indexo 第几个数组 //object 单个数组数据 - Deleteadddomthree = (indexo, object,bool) => { - if(bool === true) { + Deleteadddomthree = (indexo, object, bool) => { + if (bool === true) { this.setState({ - bindingid:undefined, + bindingid: undefined, }) } this.setState({ - Newdisplay:false, - }) + Newdisplay: false, + }); + if (object.question.question_type === 3) { + this.HandleInputTopics(this.contentMdRef.current.getValue().trim(), indexo); + + } // console.log("deleteadddom 349") var thiss = this; let arr = this.state.adddom; @@ -1374,9 +1395,11 @@ class PollNewQuestbank extends Component { // console.log(e) } } - if (newarr[indexo].question.question_title === "") { - this.props.showNotification('题目不能为空!'); - return + if (object.question.question_type !== 3) { + if (newarr[indexo].question.question_title === "") { + this.props.showNotification('题目不能为空!'); + return + } } if (max > 0) { if (object.question.question_type === 1) { @@ -1401,7 +1424,6 @@ class PollNewQuestbank extends Component { } - if (object.question.question_type === 2) { if (object.question.max_choices > 0) { // if (object.question.min_choices < 2) { @@ -1470,7 +1492,7 @@ class PollNewQuestbank extends Component { if (this.state.problemtopicbool === true) { insindex = this.state.problemtopic; } - this.createquestionsandanswers(object, 1, arrc, null, 0, 0, insindex); + this.createquestionsandanswers(object, 1, arrc, null, 0, 0, insindex,0); newarrpoll.splice(thiss.state.Insertposition, 0, question); } else if (object.question.question_type === 2) { //插入多选题 @@ -1524,12 +1546,14 @@ class PollNewQuestbank extends Component { if (this.state.problemtopicbool === true) { insindex = this.state.problemtopic; } - this.createquestionsandanswers(object, 2, arrc, null, object.question.max_choices, object.question.min_choices, insindex); + this.createquestionsandanswers(object, 2, arrc, null, object.question.max_choices, object.question.min_choices, insindex,object.question.answers.length); //插入多选题 // if (object.question.max_choices > arrc.length) { newarrpoll.splice(thiss.state.Insertposition, 0, question); } else if (object.question.question_type === 3) { + // this.HandleInputTopics(this.contentMdRef.current.getValue().trim(),indexo); + //插入主观题 var answers = []; var questiontwo = {}; @@ -1560,7 +1584,7 @@ class PollNewQuestbank extends Component { "id": null, "is_necessary": object.question.is_necessary, "question_number": 3, - "question_title": object.question.question_title, + "question_title": this.contentMdRef.current.getValue().trim(), "question_type": 3, "new": "", "answers": answers @@ -1572,7 +1596,7 @@ class PollNewQuestbank extends Component { if (this.state.problemtopicbool === true) { insindex = this.state.problemtopic; } - this.createquestionsandanswers(object, 3, null, null, 0, 0, insindex); + this.createquestionsandanswers(object, 3, null, null, 0, 0, insindex,0); // newarrpoll.push(question); newarrpoll.splice(thiss.state.Insertposition, 0, question); } @@ -1633,11 +1657,11 @@ class PollNewQuestbank extends Component { question = {"question": questiontwo}; if (uuk !== -1) { // console.log("修改") - this.edittotheserver(object, 1, arrc, null, 0, 0); + this.edittotheserver(object, 1, arrc, null, 0, 0,0); newarrpoll.splice(uuk, 1, question); } else { // console.log("删除") - this.createquestionsandanswers(object, 1, arrc, null, 0, 0, object.question.id); + this.createquestionsandanswers(object, 1, arrc, null, 0, 0, object.question.id,0); newarrpoll.push(question); } // console.log(newarrpoll) @@ -1689,16 +1713,18 @@ class PollNewQuestbank extends Component { //插入多选题 if (uuk !== -1) { // console.log("修改") - this.edittotheserver(object, 2, arrc, null, object.question.max_choices, object.question.min_choices); + this.edittotheserver(object, 2, arrc, null, object.question.max_choices, object.question.min_choices,object.question.answers.length); newarrpoll.splice(uuk, 1, question); } else { // console.log("删除") - this.createquestionsandanswers(object, 2, arrc, null, object.question.max_choices, object.question.min_choices, object.question.id); + this.createquestionsandanswers(object, 2, arrc, null, object.question.max_choices, object.question.min_choices, object.question.id,object.question.answers.length); newarrpoll.push(question); } // console.log(newarrpoll) } else if (object.question.question_type === 3) { + // this.HandleInputTopics(this.contentMdRef.current.getValue().trim(),indexo); + //插入主观题 var answers = []; var questiontwo = {}; @@ -1726,7 +1752,7 @@ class PollNewQuestbank extends Component { "id": object.question.id, "is_necessary": object.question.is_necessary, "question_number": 3, - "question_title": object.question.question_title, + "question_title": this.contentMdRef.current.getValue().trim(), "question_type": 3, "new": "", "answers": answers @@ -1734,11 +1760,11 @@ class PollNewQuestbank extends Component { question = {"question": questiontwo}; if (uuk !== -1) { // console.log("修改") - this.edittotheserver(object, 3, null, null, 0, 0); + this.edittotheserver(object, 3, null, null, 0, 0,0); newarrpoll.splice(uuk, 1, question); } else { // console.log("删除") - this.createquestionsandanswers(object, 3, null, null, 0, 0, object.question.id); + this.createquestionsandanswers(object, 3, null, null, 0, 0, object.question.id,0); newarrpoll.push(question); } // console.log(newarrpoll) @@ -1774,7 +1800,7 @@ class PollNewQuestbank extends Component { ////新增到服务器中 - createquestionsandanswers = (object, number, option, other, max_choices, min_choices, insert_id) => { + createquestionsandanswers = (object, number, option, other, max_choices, min_choices, insert_id,length) => { var thiss = this; var poll_id = this.state.pollid; var urlly = `/poll_bank_questions.json`; @@ -1788,12 +1814,12 @@ class PollNewQuestbank extends Component { min_choicess = min_choices; } axios.post(urlly, { - exercise_bank_id:poll_id, + exercise_bank_id: poll_id, question_title: object.question.question_title, question_type: number, is_necessary: object.question.is_necessary, - max_choices: max_choicess, - min_choices: min_choicess, + max_choices: max_choicess===undefined?length:max_choicess===null?length:max_choicess===0?length:max_choicess, + min_choices: min_choicess===undefined?2:min_choicess===null?2:min_choicess===0?2:min_choicess, question_answers: option, question_other_answer: null, insert_id: insert_id @@ -1824,7 +1850,7 @@ class PollNewQuestbank extends Component { } ///编辑修改到服务器当中 - edittotheserver = (object, number, option, other, max_choices, min_choices) => { + edittotheserver = (object, number, option, other, max_choices, min_choices,length) => { // console.log("调用了edittotheserver") var url = `/poll_bank_questions/${object.question.id}.json` var thiss = this; @@ -1833,8 +1859,8 @@ class PollNewQuestbank extends Component { question_title: object.question.question_title, question_type: number, is_necessary: object.question.is_necessary, - max_choices: max_choices, - min_choices: min_choices, + max_choices: max_choicess===undefined?length:max_choicess===null?length:max_choicess===0?length:max_choicess, + min_choices: min_choicess===undefined?2:min_choicess===null?2:min_choicess===0?2:min_choicess, question_answers: option, question_other_answer: null, }).then((result) => { @@ -2111,9 +2137,9 @@ class PollNewQuestbank extends Component { //i外层数组 //k为内层数组 HandleInputChanges = (e, i, k) => { - console.log("handleInputChanges"+" "+e); - console.log("handleInputChanges"+" "+i); - console.log("handleInputChanges"+" "+k); + console.log("handleInputChanges" + " " + e); + console.log("handleInputChanges" + " " + i); + console.log("handleInputChanges" + " " + k); // console.log("handleInputChanges 612") let value = e.target.value;//取到input的数据 @@ -2144,6 +2170,19 @@ class PollNewQuestbank extends Component { }) } + HandleInputTopics = (value, i) => { + console.log("handleInputTopic 633") + console.log(value); + //取到input的数据 + // console.log("handleInputTopic value is :" + value); + // console.log(i); + let arr = this.state.adddom; + let newarr = [...arr]; + newarr[i].question.question_title = value + this.setState({ + adddom: newarr + }) + } //最小值 HandleGradationGroupChangee = (value, index, max, length) => { // console.log("最小值"); @@ -2188,7 +2227,7 @@ class PollNewQuestbank extends Component { } //最大值 - HandleGradationGroupChangeee = (value, index,minchoices,length) => { + HandleGradationGroupChangeee = (value, index, minchoices, length) => { // console.log("2112"); // console.log(value); // console.log(minchoices); @@ -2200,20 +2239,18 @@ class PollNewQuestbank extends Component { let arr = this.state.adddom; for (var i = 0; i < arr.length; i++) { if (index === i) { - if(parseInt(value)===0&&parseInt(minchoices)===0){ - arr[i].question.min_choices= parseInt(0); + if (parseInt(value) === 0 && parseInt(minchoices) === 0) { + arr[i].question.min_choices = parseInt(0); arr[i].question.max_choices = parseInt(0); - }else if(parseInt(minchoices)===0){ - arr[i].question.min_choices= parseInt(2); + } else if (parseInt(minchoices) === 0) { + arr[i].question.min_choices = parseInt(2); arr[i].question.max_choices = parseInt(value); - } - else if(parseInt(value)===0&&parseInt(minchoices)>0){ - arr[i].question.min_choices= parseInt(minchoices); + } else if (parseInt(value) === 0 && parseInt(minchoices) > 0) { + arr[i].question.min_choices = parseInt(minchoices); + arr[i].question.max_choices = parseInt(value); + } else { + arr[i].question.min_choices = minchoices === null ? 2 : minchoices === undefined ? 2 : minchoices === 0 ? 2 : parseInt(minchoices); arr[i].question.max_choices = parseInt(value); - } - else { - arr[i].question.min_choices= minchoices===null?2:minchoices===undefined?2:minchoices===0?2:parseInt(minchoices); - arr[i].question.max_choices = parseInt(value); } } } @@ -2249,7 +2286,7 @@ class PollNewQuestbank extends Component { } // if(mews ==="new"){ - if(this.state.poll_questions&&this.state.poll_questions.length===0){ + if (this.state.poll_questions && this.state.poll_questions.length === 0) { this.props.showNotification("至少创建1个题目"); return; } @@ -2330,15 +2367,15 @@ class PollNewQuestbank extends Component { this.setState({ mysave: false, readOnlys: "readOnly", - storagedesc:this.state.polls_nametest, - storagedesctwo:this.state.polls_descriptiontest, + storagedesc: this.state.polls_nametest, + storagedesctwo: this.state.polls_descriptiontest, }) } else if (this.state.mysave === false) { this.setState({ mysave: true, readOnlys: "", - storagedesc:this.state.polls_nametest, - storagedesctwo:this.state.polls_descriptiontest, + storagedesc: this.state.polls_nametest, + storagedesctwo: this.state.polls_descriptiontest, }) } } @@ -2349,16 +2386,16 @@ class PollNewQuestbank extends Component { mysave: false, Newedit: false, readOnlys: "readOnly", - polls_nametest:this.state.storagedesc, - polls_descriptiontest:this.state.storagedesctwo, + polls_nametest: this.state.storagedesc, + polls_descriptiontest: this.state.storagedesctwo, }) } else { this.setState({ mysave: false, Newedit: false, readOnlys: "readOnly", - polls_nametest:this.state.storagedesc, - polls_descriptiontest:this.state.storagedesctwo, + polls_nametest: this.state.storagedesc, + polls_descriptiontest: this.state.storagedesctwo, }) } } @@ -2399,41 +2436,41 @@ class PollNewQuestbank extends Component { // // }) // } else { - if (this.state.polls_nametest === undefined || this.state.polls_nametest === "") { - this.props.showNotification("请输入标题"); - return - } + if (this.state.polls_nametest === undefined || this.state.polls_nametest === "") { + this.props.showNotification("请输入标题"); + return + } - var pollid; - if (this.state.pollid === undefined) { - pollid = this.props.match.params.workid; - } else { - pollid = this.state.pollid; - } + var pollid; + if (this.state.pollid === undefined) { + pollid = this.props.match.params.workid; + } else { + pollid = this.state.pollid; + } - var url = `/exercise_banks/${pollid}.json`; - axios.put(url, { - exercise_name: this.state.polls_nametest, - exercise_description: this.state.polls_descriptiontest - }).then((result) => { - if (result !== undefined) { - this.props.showNotification(`问卷更新成功!`); - this.setState({ - mysave: false, - readOnlys: "readOnly", - }) - } + var url = `/exercise_banks/${pollid}.json`; + axios.put(url, { + exercise_name: this.state.polls_nametest, + exercise_description: this.state.polls_descriptiontest + }).then((result) => { + if (result !== undefined) { + this.props.showNotification(`问卷更新成功!`); + this.setState({ + mysave: false, + readOnlys: "readOnly", + }) + } - }) + }) // } } - gotohome=()=>{ + gotohome = () => { // const { current_user} = this.props - if(this.state.first_category_url){ - window.location.href=this.state.first_category_url; - }else{ + if (this.state.first_category_url) { + window.location.href = this.state.first_category_url; + } else { this.props.history.goBack(); } @@ -2461,7 +2498,8 @@ class PollNewQuestbank extends Component { readOnlys, newoption, cancellation, - left_banner_id + left_banner_id, + addonAftertwo } = this.state //获取老师权限 // console.log("[`${maps[polls_status && polls_status]}`]]"); @@ -2491,7 +2529,7 @@ class PollNewQuestbank extends Component { // console.log(this.state.projects===undefined?"":this.state.projects.poll_questions) var displaymysave = (mysave === true) ? "" : "display:none;"; return ( -
+
{/*提示*/} {Modalstype && Modalstype === true ? : ""} - -
-

- this.gotohome()}>{this.props.coursedata.name} - > +

+ {/*

*/} + {/* this.gotohome()}>{this.props.coursedata.name}*/} + {/* >*/} {/*{*/} {/* this.props.match.params.news === "new"?*/} {/* 问卷*/} {/* :*/} - 问卷 + {/*问卷*/} {/*}*/} - > + {/*>*/} {/*{this.props.match.params.news === undefined ? "新建" : this.props.match.params.news === "new" ? "新建" : "编辑"}*/} - 编辑 + {/* 编辑*/} -

-
+ {/*

*/} + {/*
*/} {/*

{this.props.match.params.news === undefined ? "新建问卷" : this.props.match.params.news === "new" ? "新建问卷" : "编辑问卷"}

*/} -

编辑

+ {/*

编辑

*/} {/*{*/} {/* this.props.match.params.news === "new" ?*/} {/* 返回*/} {/* :*/} - + {/**/} {/*}*/} -
+ {/*
*/} {/*
*/} { this.state.mysave === false ? -
+ - :"" + : "" } { this.state.mysave === true ? @@ -2574,14 +2609,14 @@ class PollNewQuestbank extends Component { { // this.props.match.params.news === undefined ? "" : this.props.match.params.news === "new" ? // ( - this.state.mysave === false ? -
+ this.state.mysave === false ? + - : "" +
+ : "" // ) - // :"" + // :"" }
@@ -2596,13 +2631,14 @@ class PollNewQuestbank extends Component { ` } -
@@ -2622,11 +2658,12 @@ class PollNewQuestbank extends Component { + maxLength={100} + autoComplete="off" addonAfter={String(addonAftertwo)} + > { this.state.Newedit === true || this.state.mysave === true ?
@@ -2655,11 +2692,10 @@ class PollNewQuestbank extends Component {
-
:"" +
: "" } -

@@ -2681,7 +2717,7 @@ class PollNewQuestbank extends Component { 合计 {this.state.q_counts === undefined ? "" :this.state.q_counts} + style={{color: "#FF6800"}}>{this.state.q_counts === undefined ? "" : this.state.q_counts} 题

} @@ -2712,11 +2748,11 @@ class PollNewQuestbank extends Component { let resultDom; resultDom =

- 第{index + 1}题: + {index + 1}、 {item.question.question_type === 1 ? "(单选题)" : item.question.question_type === 2 ? "(多选题)" : "(主观题)"} + className="color-grey-9 fl">{item.question.question_type === 1 ? "单选题" : item.question.question_type === 2 ? "多选题" : "主观题"} {item.question.is_necessary === 1 ? "必答" : item.question.question_type === 2 ? "选答" : "选答"} + className=" ml10">{item.question.is_necessary === 1 ? "(必答)" : item.question.question_type === 2 ? "(选答)" : "(选答)"} {(item.question.min_choices === undefined && item.question.max_choices === undefined ? "" : item.question.min_choices === null && item.question.max_choices === null ? "" : item.question.min_choices === 0 && item.question.max_choices === 0 ? "" : "可选" + item.question.min_choices + "-" + item.question.max_choices + "项")} { @@ -2747,7 +2783,11 @@ class PollNewQuestbank extends Component { }

-

{item.question.question_title}

+

{item.question.question_title}

{/*
{item.question.question_title}
*/} {item.question.question_type === 1 ?
@@ -2755,8 +2795,15 @@ class PollNewQuestbank extends Component { {item.question.answers === undefined ? "" : item.question.answers.map((items, i) => { return (
- - {items.answer_text} + + {items.answer_text}
) @@ -2773,7 +2820,14 @@ class PollNewQuestbank extends Component { return (
- {items.answer_text} + {items.answer_text}
) })} @@ -2783,7 +2837,8 @@ class PollNewQuestbank extends Component { : item.question.question_type === 3 ? // 主观题 - (
+ (
+
) : (
)}
@@ -2791,37 +2846,47 @@ class PollNewQuestbank extends Component {
{/*这里是编辑和新增的地方*/} { - this.state.bindingid && this.state.bindingid===item.question.id? - (this.state.Newdisplay === false? + this.state.bindingid && this.state.bindingid === item.question.id ? + (this.state.Newdisplay === false ?
-
- {this.state.adddom === undefined ? "" :this.state.adddom===undefined?"": this.state.adddom.length===0?"":item.question.id === this.state.adddom[0].question.id&&this.state.adddom.map((itemo, indexo) => { +
+ {this.state.adddom === undefined ? "" : this.state.adddom === undefined ? "" : this.state.adddom.length === 0 ? "" : item.question.id === this.state.adddom[0].question.id && this.state.adddom.map((itemo, indexo) => { let arrid = itemo.question.id; let resultDomtwo; resultDomtwo = -
- {itemo.question.question_type === 1 ? "单选题" : itemo.question.question_type === 2 ? "多选题" : "主观题"} - this.OnCheckAllChange(e, indexo)} - className="lineh-40" - style={{"marginLeft": "20px"}}>必答 +
+ {item.question.question_number}、 + {itemo.question.question_type === 1 ? "单选题" : itemo.question.question_type === 2 ? "多选题" : "主观题"} + this.OnCheckAllChange(e, indexo)} + className="lineh-40" + style={{"marginLeft": "20px"}}>必答 - - + { + itemo.question.question_type === 3 ? + + : + + + } {itemo.question.answers === undefined ? "" : itemo.question.answers.map((itemt, indext) => { return (
@@ -2837,11 +2902,11 @@ class PollNewQuestbank extends Component { placeholder='无法编辑!将由参与答题的人手动录入'> {this.state.polls_status === undefined || this.state.polls_status === 1 ? - itemo.question.question_type === 1?( - indext>1? + itemo.question.question_type === 1 ? ( + indext > 1 ? { - itemo.question.question_type === 2 ?"": + itemo.question.question_type === 2 ? "" : this.Deleteentrys(arrid, indext, true)}> + > - :"") - : "":""} + : "") + : "" : ""}

) : (

this.HandleInputChanges(e, indexo, indext)}> {this.state.polls_status === undefined || this.state.polls_status === 1 ? - indext>1? - + indext > 1 ? + this.Deleteentrys(arrid, indext, false)}> - { - itemo.question.answers[itemo.question.answers.length-1].answer_text === "其他"&&itemo.question.answers.length-2===indext? + { + itemo.question.answers[itemo.question.answers.length - 1].answer_text === "其他" && itemo.question.answers.length - 2 === indext ? - this.Ewoption(itemo.question.id, itemo)}> - : itemo.question.answers.length-1===indext? - this.Ewoption(itemo.question.id, itemo)}> - : - } + this.Ewoption(itemo.question.id, itemo)}> + : itemo.question.answers.length - 1 === indext ? + this.Ewoption(itemo.question.id, itemo)}> + : + } - :indext===1&&itemo.question.answers.length===2||indext===1&&itemo.question.answers.length===3? this.Ewoption(itemo.question.id, itemo)}> this.Ewoption(itemo.question.id, itemo)}>:"" + className="color-green font-18 iconfont icon-roundaddfill"> : "" : ""}

)}
@@ -2913,7 +2979,7 @@ class PollNewQuestbank extends Component { {/* onClick={() => this.Ewoption(itemo.question.id, itemo)}>新增选项*/}
{this.state.polls_status === undefined || this.state.polls_status === 1 ? - "" + "" : ""} {this.state.polls_status === undefined || this.state.polls_status === 1 ? @@ -2924,11 +2990,11 @@ class PollNewQuestbank extends Component { : ""} this.Deleteadddom(indexo,true)}>取消 + onClick={() => this.Deleteadddom(indexo, true)}>取消 this.Deleteadddomtwo(indexo, itemo,true)} >保存并继续 + onClick={() => this.Deleteadddomtwo(indexo, itemo, true)}>保存并继续 this.Deleteadddomthree(indexo, itemo,true)}>保存并退出 + onClick={() => this.Deleteadddomthree(indexo, itemo, true)}>保存并退出
@@ -2939,7 +3005,7 @@ class PollNewQuestbank extends Component { : itemo.question.question_type === 2 ? ( //////////////////////////////////////////// 可选 -
+
-- {itemo.question.answers === undefined ? "" : itemo.question.answers.map((itemt, indext) => { return ( - indext >= 1 ? : "" + indext >= 1 ? + : "" ) })} @@ -2977,13 +3044,14 @@ class PollNewQuestbank extends Component { className="ml10 mr10 color-grey-6 lineh-40 fl">~ {/*可选最大*/} - + { + itemo.question.question_type === 3 ? + + : + + + } {itemo.question.answers === undefined ? "" : itemo.question.answers.map((itemt, indext) => { console.log("chishiyong1"); - console.log( itemo.question.answers[itemo.question.answers.length - 1]); + console.log(itemo.question.answers[itemo.question.answers.length - 1]); return (
{itemt.answer_text === undefined ? ( @@ -3128,10 +3206,10 @@ class PollNewQuestbank extends Component { className="mr20 max1010 input-flex-40 TextAreainput" disabled placeholder='无法编辑!将由参与答题的人手动录入'> {this.state.polls_status === undefined || this.state.polls_status === 1 ? - indext>1? - + indext > 1 ? + { - itemo.question.question_type === 2?"": + itemo.question.question_type === 2 ? "" : this.Deleteentrys(arrid, indext, true)}> } - {/* {*/} - {/* itemo.question.answers.length-1=== indext?*/} - {/* this.Ewoption(itemo.question.id, itemo)}>*/} - {/*: */} - {/* }*/} + {/* {*/} + {/* itemo.question.answers.length-1=== indext?*/} + {/* this.Ewoption(itemo.question.id, itemo)}>*/} + {/*: */} + {/* }*/} - :"" + : "" : ""}

) : (

this.HandleInputChanges(e, indexo, indext)}> {this.state.polls_status === undefined || this.state.polls_status === 1 ? - indext>1? - + indext > 1 ? + this.Deleteentrys(arrid, indext, false)}> - { - itemo.question.answers[itemo.question.answers.length - 1].answer_text==="其他"&&itemo.question.answers.length - 2 === indext ? - this.Ewoption(itemo.question.id, itemo)}> - : itemo.question.answers.length - 1 === indext ? - this.Ewoption(itemo.question.id, itemo)}> - : - - } + { + itemo.question.answers[itemo.question.answers.length - 1].answer_text === "其他" && itemo.question.answers.length - 2 === indext ? + this.Ewoption(itemo.question.id, itemo)}> + : itemo.question.answers.length - 1 === indext ? + this.Ewoption(itemo.question.id, itemo)}> + : + + } - :indext===1&&itemo.question.answers.length===2||indext===1&&itemo.question.answers.length===3? this.Ewoption(itemo.question.id, itemo)}> this.Ewoption(itemo.question.id, itemo)}>:"" + className="color-green font-18 iconfont icon-roundaddfill"> : "" : ""}

)}
@@ -3221,11 +3300,11 @@ class PollNewQuestbank extends Component { : ""} this.Deleteadddom(indexo,true)}>取消 + onClick={() => this.Deleteadddom(indexo, true)}>取消 this.Deleteadddomtwo(indexo, itemo,true)}>保存并继续 + onClick={() => this.Deleteadddomtwo(indexo, itemo, true)}>保存并继续 this.Deleteadddomthree(indexo, itemo,true)}>保存并退出 + onClick={() => this.Deleteadddomthree(indexo, itemo, true)}>保存并退出
@@ -3266,7 +3345,8 @@ class PollNewQuestbank extends Component { {itemo.question.answers === undefined ? "" : itemo.question.answers.map((itemt, indext) => { return ( - indext >= 1 ? : "" + indext >= 1 ? + : "" ) })} @@ -3274,13 +3354,14 @@ class PollNewQuestbank extends Component { className="ml10 mr10 color-grey-6 lineh-40 fl">~ {/*可选最大*/} + } - {itemo.question.answers === undefined ? "" : itemo.question.answers.map((itemt, indext) => { console.log("ceshiyong2"); - console.log(itemo.question.answers.length-1); + console.log(itemo.question.answers.length - 1); return (
{itemt.answer_text === undefined ? ( @@ -3439,10 +3529,10 @@ class PollNewQuestbank extends Component { className="mr20 max1010 input-flex-40 TextAreainput" disabled placeholder='无法编辑!将由参与答题的人手动录入'> {polls_status === undefined || polls_status === 1 ? - indext>1? - + indext > 1 ? + { - itemo.question.question_type === 2?"" + itemo.question.question_type === 2 ? "" : this.Deleteentrys(arrid, indext, true)}> - :"" + : "" : ""}

) : (

this.HandleInputChanges(e, indexo, indext)}> {polls_status === undefined || polls_status === 1 ? - (indext>1? + (indext > 1 ? this.Deleteentrys(arrid, indext, false)}> { - itemo.question.answers[itemo.question.answers.length-1].answer_text==="其他"&&itemo.question.answers.length-2===indext? + itemo.question.answers[itemo.question.answers.length - 1].answer_text === "其他" && itemo.question.answers.length - 2 === indext ? this.Ewoption(itemo.question.id, itemo)}> : itemo.question.answers.length - 1 === indext ? - this.Ewoption(itemo.question.id, itemo)}> - : + this.Ewoption(itemo.question.id, itemo)}> + : - + } - :indext===1&&itemo.question.answers.length===2||indext===1&&itemo.question.answers.length===3? this.Ewoption(itemo.question.id, itemo)}>:"") + : indext === 1 && itemo.question.answers.length === 2 || indext === 1 && itemo.question.answers.length === 3 ? + this.Ewoption(itemo.question.id, itemo)}> : "") : ""}

)}
@@ -3517,7 +3608,7 @@ class PollNewQuestbank extends Component { {/* onClick={() => this.Ewoption(itemo.question.id, itemo)}>新增选项*/}
{polls_status === undefined || polls_status === 1 ? - "" + "" : ""} {polls_status === undefined || polls_status === 1 ? @@ -3531,7 +3622,7 @@ class PollNewQuestbank extends Component { onClick={() => this.Deleteadddom(indexo)}>取消 this.Deleteadddomtwo(indexo, itemo)} - > 保存并继续 + > 保存并继续 this.Deleteadddomthree(indexo, itemo)}>保存并退出 @@ -3574,7 +3665,8 @@ class PollNewQuestbank extends Component { {itemo.question.answers === undefined ? "" : itemo.question.answers.map((itemt, indext) => { return ( - indext >= 1 ? : "" + indext >= 1 ? + : "" ) })} @@ -3582,13 +3674,14 @@ class PollNewQuestbank extends Component { className="ml10 mr10 color-grey-6 lineh-40 fl">~ {/*可选最大*/}