From d56e75324b95d98a14256be1e3aad48f309d61c5 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, 8 Jan 2020 11:28:55 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=98=E5=BA=93=E6=96=B0=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../react/src/common/quillForEditor/README.md | 1 + public/react/src/modules/question/Question.js | 23 ++ .../question/component/ChoquesEditor.js | 158 ++++++---- .../modules/question/component/Contentpart.js | 13 +- .../question/component/JudquestionEditor.js | 181 ++++++----- .../modules/question/component/Listjihe.js | 287 ++++++++++++------ .../question/component/SingleEditor.js | 194 +++++++----- .../question/questioncss/questioncom.css | 9 + 8 files changed, 562 insertions(+), 304 deletions(-) diff --git a/public/react/src/common/quillForEditor/README.md b/public/react/src/common/quillForEditor/README.md index 0369164c7..eea4de5cc 100644 --- a/public/react/src/common/quillForEditor/README.md +++ b/public/react/src/common/quillForEditor/README.md @@ -61,6 +61,7 @@ ### 使用 ```` + 编辑模式是放不大图片的 import QuillForEditor from 'xxx'; // 指定需要显示的工具栏信息, 不指定加载全部 diff --git a/public/react/src/modules/question/Question.js b/public/react/src/modules/question/Question.js index 171a2f2d7..0d51f4972 100644 --- a/public/react/src/modules/question/Question.js +++ b/public/react/src/modules/question/Question.js @@ -66,9 +66,28 @@ class Question extends Component { oj_status:null, isVisible: false, selectionbools:false, + chakanjiexiboolindex:"无", } } + + chakanjiexibool=(index)=>{ + debugger + if(this.state.chakanjiexiboolindex===index){ + this.setState({ + chakanjiexiboolindex:"无", + }) + return + } + this.setState({ + chakanjiexiboolindex:index, + }) + } + setmychakanjiexibool=(str)=>{ + this.setState({ + chakanjiexiboolindex:str, + }) + } setdiscipline_id=(discipline_id)=>{ this.setState({ discipline_id:discipline_id, @@ -338,6 +357,8 @@ class Question extends Component { oj_status:this.state.oj_status }; this.getdata(data); + this.setmychakanjiexibool("无") + } showDrawer = () => { if(this.state.visible===true){ @@ -882,6 +903,8 @@ class Question extends Component { /> {/*头部*/} this.chakanjiexibool(e)} getitem_basketss={(id)=>this.getitem_basketss(id)} selectallquestionsonthispage={()=>this.selectallquestionsonthispage()} getitem_baskets={(e)=>this.getitem_baskets(e)} diff --git a/public/react/src/modules/question/component/ChoquesEditor.js b/public/react/src/modules/question/component/ChoquesEditor.js index 99a713d7f..e31e4b41a 100644 --- a/public/react/src/modules/question/component/ChoquesEditor.js +++ b/public/react/src/modules/question/component/ChoquesEditor.js @@ -10,6 +10,7 @@ import axios from 'axios' import update from 'immutability-helper' import './../questioncss/questioncom.css'; import {getUrl, ActionBtn, DMDEditor, ConditionToolTip} from 'educoder'; +import QuillForEditor from '../../../common/quillForEditor'; const { TextArea } = Input; const confirm = Modal.confirm; const $ = window.$ @@ -70,10 +71,13 @@ class ChoquesEditor extends Component{ this.state = { question_choices: _question_choices || ['', '', '', ''], standard_answers: _standard_answers || [false, false, false, false], - question_title: this.props.question_title || '', + question_title: this.props.question_title!==undefined?JSON.parse(this.props.question_title):"", question_type: this.props.question_type || 0, question_score: this.props.question_score || this.props.init_question_score, - question_titles:this.props.question_titles||'', + question_titles: this.props.question_titles!==undefined?JSON.parse(this.props.question_titles):"", + question_titlesysl:this.props.question_titlesysl||'', + question_titleysl:this.props.question_title || '', + item_banksedit:[], } } addOption = () => { @@ -122,12 +126,11 @@ class ChoquesEditor extends Component{ } onSave = () => { var editordata=[]; - const {question_title, question_score, question_type,question_titles, question_choices, standard_answers } = this.state; + const {question_title, question_score,question_titleysl,question_titlesysl, question_type,question_titles, question_choices, standard_answers } = this.state; const { question_id_to_insert_after, question_id } = this.props // TODO check const answerArray = standard_answers.map((item, index) => { return item == true ? index+1 : -1 }).filter(item => item != -1); - if(!question_title) { - this.refs['titleEditor'].showError() + if(!question_titleysl) { this.props.showNotification('请您输入题干'); return editordata; } @@ -143,14 +146,12 @@ class ChoquesEditor extends Component{ for(let i = 0; i < question_choices.length; i++) { if (!question_choices[i]) { - this.refs[`optionEditor${i}`].showError() this.props.showNotification(`请先输入 ${tagArray[i]} 选项的内容`); return editordata; } } - if(!question_titles) { - this.refs['titleEditor2'].showError() + if(!question_titlesysl) { this.props.showNotification('请您输入题目解析'); return editordata; } @@ -162,7 +163,7 @@ class ChoquesEditor extends Component{ "question_choices":["a答案","b答案","c答案","d答案"], "standard_answers":[1] }*/ - editordata=[question_title,answerArray,question_choices,question_titles]; + editordata=[question_titleysl,answerArray,question_choices,question_titlesysl]; // question_title, // question_type: answerArray.length > 1 ? 1 : 0, // question_score, @@ -186,8 +187,10 @@ class ChoquesEditor extends Component{ try { this.setState({ item_banksedit:this.props.item_banksedit, - question_title:this.props.item_banksedit.name, - question_titles:this.props.item_banksedit.analysis, + question_title: this.props.item_banksedit.name!==undefined?JSON.parse(this.props.item_banksedit.name):"", + question_titleysl:this.props.item_banksedit.name|| '', + question_titles: this.props.item_banksedit.analysis!==undefined?JSON.parse(this.props.item_banksedit.analysis):"", + question_titlesysl:this.props.item_banksedit.analysis||'', mychoicess:this.props.item_banksedit.choices, }) @@ -205,8 +208,10 @@ class ChoquesEditor extends Component{ if(prevProps.item_banksedit !== this.props.item_banksedit) { this.setState({ item_banksedit: this.props.item_banksedit, - question_title: this.props.item_banksedit.name, - question_titles: this.props.item_banksedit.analysis, + question_title: this.props.item_banksedit.name!==undefined?JSON.parse(this.props.item_banksedit.name):"", + question_titleysl:this.props.item_banksedit.name|| '', + question_titles: this.props.item_banksedit.analysis!==undefined?JSON.parse(this.props.item_banksedit.analysis):"", + question_titlesysl:this.props.item_banksedit.analysis||'', mychoicess: this.props.item_banksedit.choices, }) @@ -217,15 +222,28 @@ class ChoquesEditor extends Component{ standard_answers[index] = !standard_answers[index] this.setState({ standard_answers }) } - onOptionContentChange = (value, index) => { + onOptionContentChange = (value,quill,index) => { if (index >= this.state.question_choices.length) { // TODO 新建,然后删除CD选项,再输入题干,会调用到这里,且index是3 return; } + var texts; + const _text = quill.getText(); + const reg = /^[\s\S]*.*[^\s][\s\S]*$/; + if (!reg.test(_text)) { + // 处理编辑器内容为空 + texts=""; + } else { + // 提交到后台的内容需要处理一下; + value = JSON.stringify(value) + texts=value; + } let question_choices = this.state.question_choices.slice(0); - question_choices[index] = value; - this.setState({ question_choices }) + question_choices[index] = texts; + console.log(question_choices); + this.setState({ question_choices }); } + on_question_score_change = (e) => { this.setState({ question_score: e }) } @@ -241,6 +259,41 @@ class ChoquesEditor extends Component{ toShowMode = () => { } + + onContentChange=(value,quill)=>{ + const _text = quill.getText(); + const reg = /^[\s\S]*.*[^\s][\s\S]*$/; + if (!reg.test(_text)) { + // 处理编辑器内容为空 + this.setState({ + question_titleysl:"" + }) + } else { + // 提交到后台的内容需要处理一下; + value = JSON.stringify(value) + this.setState({ + question_titleysl:value + }) + } + } + onContentChanges=(value,quill)=>{ + const _text = quill.getText(); + const reg = /^[\s\S]*.*[^\s][\s\S]*$/; + if (!reg.test(_text)) { + // 处理编辑器内容为空 + this.setState({ + question_titlesysl:"" + }) + } else { + // 提交到后台的内容需要处理一下; + value = JSON.stringify(value) + this.setState({ + question_titlesysl:value + }) + } + } + + render() { let { question_title, question_score, question_type, question_choices, standard_answers,question_titles} = this.state; let { question_id, index, exerciseIsPublish, @@ -271,7 +324,7 @@ class ChoquesEditor extends Component{ flex:1 } .optionRow { - margin:0px!important; + /* margin:0px!important; */ /* margin-bottom: 20px!important; */ } .signleEditor .content_editorMd_show{ @@ -291,11 +344,14 @@ class ChoquesEditor extends Component{ 题干:

- this.setState({ question_title: val})} - ref="titleEditor" + + />
{/* {!question_id ? '新建' : '编辑'} */} @@ -305,7 +361,7 @@ class ChoquesEditor extends Component{ {question_choices.map( (item, index) => { const bg = standard_answers[index] ? 'check-option-bg' : '' - return
+ return
0?"df optionRow mt15": "df optionRow"} > {/* 点击设置答案 */} {/* TODO 加了tooltip后,会丢失掉span的class */} {/* */} @@ -317,13 +373,26 @@ class ChoquesEditor extends Component{ {/* */}
- this.onOptionContentChange(value, index)} - initValue={item} - > + + { + item===undefined||item===null||item===""? + this.onOptionContentChange(value,quill,index)} + /> + : + this.onOptionContentChange(value,quill,index)} + /> + + }
{exerciseIsPublish || index<=2? @@ -346,32 +415,19 @@ class ChoquesEditor extends Component{ -

+

{/* {!question_id ? '新建' : '编辑'} */} * 题目解析:

- - this.setState({ question_titles: val})} - ref="titleEditor2" - - > +
+
diff --git a/public/react/src/modules/question/component/Contentpart.js b/public/react/src/modules/question/component/Contentpart.js index 0768c86b6..5ed610920 100644 --- a/public/react/src/modules/question/component/Contentpart.js +++ b/public/react/src/modules/question/component/Contentpart.js @@ -25,7 +25,6 @@ class Contentpart extends Component { this.state = { page:1, chakanjiexibool:false, - chakanjiexiboolindex:"无", } } //初始化 @@ -35,16 +34,7 @@ class Contentpart extends Component { } chakanjiexibool=(index)=>{ - debugger - if(this.state.chakanjiexiboolindex===index){ - this.setState({ - chakanjiexiboolindex:"无", - }) - return - } - this.setState({ - chakanjiexiboolindex:index, - }) + this.props.chakanjiexibool(index); } render() { @@ -230,6 +220,7 @@ class Contentpart extends Component { : this.props.Contentdata.items.map((object, index) => { return ( this.chakanjiexibool(keindex)} listjihe={index+1} keindex={index} diff --git a/public/react/src/modules/question/component/JudquestionEditor.js b/public/react/src/modules/question/component/JudquestionEditor.js index ff491125c..eb68308db 100644 --- a/public/react/src/modules/question/component/JudquestionEditor.js +++ b/public/react/src/modules/question/component/JudquestionEditor.js @@ -10,6 +10,8 @@ import axios from 'axios' import update from 'immutability-helper' import './../questioncss/questioncom.css'; import {getUrl, ActionBtn, DMDEditor, ConditionToolTip} from 'educoder'; +import QuillForEditor from '../../../common/quillForEditor'; + const { TextArea } = Input; const confirm = Modal.confirm; const $ = window.$ @@ -46,10 +48,12 @@ class JudquestionEditor extends Component{ this.state = { question_choices: _question_choices || ['', '', '', ''], standard_answers: _standard_answers || [false, false, false, false], - question_title: this.props.question_title || '', + question_title: this.props.question_title!==undefined?JSON.parse(this.props.question_title):"", question_type: this.props.question_type || 0, question_score: this.props.question_score || this.props.init_question_score, - question_titles:this.props.question_titles||'', + question_titles: this.props.question_titles!==undefined?JSON.parse(this.props.question_titles):"", + question_titlesysl:this.props.question_titlesysl||'', + question_titleysl:this.props.question_title || '', zqda:null, item_banksedit:[], mychoicess:[], @@ -99,12 +103,11 @@ class JudquestionEditor extends Component{ } onSave = () => { var editordata=[]; - const {question_title, question_score, question_type,question_titles, zqda,question_choices, standard_answers } = this.state; + const {question_title, question_score,question_titleysl,question_titlesysl, question_type,question_titles, zqda,question_choices, standard_answers } = this.state; const { question_id_to_insert_after, question_id } = this.props // TODO check const answerArray = standard_answers.map((item, index) => { return item == true ? index+1 : -1 }).filter(item => item != -1); - if(!question_title) { - this.refs['titleEditor'].showError() + if(!question_titleysl) { this.props.showNotification('请您输入题干'); return editordata; } @@ -117,8 +120,7 @@ class JudquestionEditor extends Component{ - if(!question_titles) { - this.refs['titleEditor2'].showError() + if(!question_titlesysl) { this.props.showNotification('请您输入题目解析'); return editordata; } @@ -132,7 +134,7 @@ class JudquestionEditor extends Component{ }*/ - editordata=[question_title,zqda,question_titles]; + editordata=[question_titleysl,zqda,question_titlesysl]; // question_title, // question_type: answerArray.length > 1 ? 1 : 0, // question_score, @@ -156,31 +158,31 @@ class JudquestionEditor extends Component{ try { this.setState({ item_banksedit:this.props.item_banksedit, - question_title:this.props.item_banksedit.name, - question_titles:this.props.item_banksedit.analysis, + question_title: this.props.item_banksedit.name!==undefined?JSON.parse(this.props.item_banksedit.name):"", + question_titles: this.props.item_banksedit.analysis!==undefined?JSON.parse(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{ + const _text = quill.getText(); + const reg = /^[\s\S]*.*[^\s][\s\S]*$/; + if (!reg.test(_text)) { + // 处理编辑器内容为空 + this.setState({ + question_titleysl:"" + }) + } else { + // 提交到后台的内容需要处理一下; + value = JSON.stringify(value) + this.setState({ + question_titleysl:value + }) + } + } + onContentChanges=(value,quill)=>{ + const _text = quill.getText(); + const reg = /^[\s\S]*.*[^\s][\s\S]*$/; + if (!reg.test(_text)) { + // 处理编辑器内容为空 + this.setState({ + question_titlesysl:"" + }) + } else { + // 提交到后台的内容需要处理一下; + value = JSON.stringify(value) + this.setState({ + question_titlesysl:value + }) + } + } render() { let { question_title, question_score, question_type, question_choices, standard_answers,question_titles} = this.state; let { question_id, index, exerciseIsPublish, @@ -325,11 +360,14 @@ class JudquestionEditor extends Component{ 题干:

- this.setState({ question_title: val})} - ref="titleEditor" + + />
{/* {!question_id ? '新建' : '编辑'} */} @@ -363,36 +401,23 @@ class JudquestionEditor extends Component{
- +

{/* {!question_id ? '新建' : '编辑'} */} * 题目解析:

- - this.setState({ question_titles: val})} - ref="titleEditor2" - > +
- +
) diff --git a/public/react/src/modules/question/component/Listjihe.js b/public/react/src/modules/question/component/Listjihe.js index f796a3f45..e793859cd 100644 --- a/public/react/src/modules/question/component/Listjihe.js +++ b/public/react/src/modules/question/component/Listjihe.js @@ -1,6 +1,6 @@ import React, {Component} from "react"; import {Link, NavLink} from 'react-router-dom'; -import {WordsBtn, ActionBtn,SnackbarHOC,getImageUrl,markdownToHTML} from 'educoder'; +import {WordsBtn, ActionBtn, SnackbarHOC, getImageUrl, markdownToHTML} from 'educoder'; import axios from 'axios'; import { notification, @@ -10,6 +10,8 @@ import { Radio } from "antd"; import './../questioncss/questioncom.css'; +import QuillForEditor from "../../../common/quillForEditor"; + const tagArray = [ 'A.', 'B.', 'C.', 'D.', 'E.', 'F.', 'G.', 'H.', 'I.', 'J.', 'K.', 'L.', 'M.', 'N.', 'O.', 'P.', 'Q.', 'R.', @@ -20,74 +22,73 @@ const tagArrays = [ 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' ] + class Listjihe extends Component { constructor(props) { super(props); this.state = { - page:1, - name:"单选题", - nd:"简单", + page: 1, + name: "单选题", + nd: "简单", } } + //初始化 - componentDidMount(){ + componentDidMount() { } //选用 - Selectingpracticaltraining=(id)=>{ - let data={} - if(this.props.exam_id===undefined){ - data={ - item_ids:[id] + Selectingpracticaltraining = (id) => { + let data = {} + if (this.props.exam_id === undefined) { + data = { + item_ids: [id] } - }else{ - data={ - item_ids:[id], - exam_id:this.props.exam_id===undefined?"":parseInt(this.props.exam_id), + } else { + data = { + item_ids: [id], + exam_id: this.props.exam_id === undefined ? "" : parseInt(this.props.exam_id), } - } + } this.props.getitem_baskets(data); } //撤销 - Selectingpracticaltrainings=(id)=>{ + Selectingpracticaltrainings = (id) => { this.props.getitem_basketss(id); } - - - render() { - let {page,name,nd}=this.state; - let {defaultActiveKey,items,listjihe,chakanjiexiboolindex,keindex}=this.props; + let {page, name, nd} = this.state; + let {defaultActiveKey, items, listjihe, chakanjiexiboolindex, keindex} = this.props; // 编程答案 - var rightkey=null + var rightkey = null - if(items){ - if(items.item_type){ - if(items.item_type==="PROGRAM"){ + if (items) { + if (items.item_type) { + if (items.item_type === "PROGRAM") { - }else{ - if(items.item_type==="JUDGMENT") { + } else { + if (items.item_type === "JUDGMENT") { - if(items.choices){ - if(items.choices.length>0){ - var arr= items.choices; - for(let data of arr) { - if(data.is_answer===true){ - rightkey=data.choice_text; + if (items.choices) { + if (items.choices.length > 0) { + var arr = items.choices; + for (let data of arr) { + if (data.is_answer === true) { + rightkey = data.choice_text; break; } } } } - }else { + } else { if (items.choices) { if (items.choices.length > 0) { var arr = items.choices; @@ -106,11 +107,41 @@ class Listjihe extends Component { } } - + var itemssname=""; + try { + itemssname= JSON.parse(items.name); + }catch (e) { + } + if(itemssname===undefined){ + itemssname=items.name + } return ( -
+
{/*顶部*/} +
{ @@ -120,17 +151,36 @@ class Listjihe extends Component {
.
-
-
+ { + items.item_type==="PROGRAM"? + +
+ + : +
+ { items===undefined||items===null||items===""?"": + items.name === undefined || items.name === null || items.name === "" ? + "" + : + items.name.length>0? + + :"" + } +
+ } +
{/*内容*/}
- {items.item_type==="JUDGMENT"? -

+ {items.item_type === "JUDGMENT" ? +

{ - items === undefined ||items === null? "" : items.choices.map((object, index) => { + items === undefined || items === null ? "" : items.choices.map((object, index) => { return ( -

+

{object.choice_text} @@ -138,21 +188,52 @@ class Listjihe extends Component { ) }) } -

: - items.item_type==="PROGRAM"? +

: + items.item_type === "PROGRAM" ?

-

-

+

+ { + items&&items.program_attr&&items.program_attr.description? +

+ + +

+ :"" + } + + +

: -

+

{ - items === undefined ||items === null? "" : items.choices.map((object, index) => { + items === undefined || items === null ? "" : items.choices.map((object, index) => { return ( -

- {tagArray[index]} -

+

+

{tagArray[index]}

+

+ {object ? + object.choice_text === undefined || object.choice_text=== null || object.choice_text === "" ? + + "" + : + object.choice_text.length>0? + + :"" + + + : + "" + } +

) }) @@ -163,91 +244,95 @@ class Listjihe extends Component {
-

难度:{items.difficulty===1?"简单":items.difficulty===2?"适中":items.difficulty===3?"困难":""}

-

题型:{items.item_type==="SINGLE"?"单选题":items.item_type==="MULTIPLE"?"多选题":items.item_type==="JUDGMENT"?"判断题":items.item_type==="PROGRAM"?"编程题":""}

+

难度:{items.difficulty === 1 ? "简单" : items.difficulty === 2 ? "适中" : items.difficulty === 3 ? "困难" : ""} +

+

题型:{items.item_type === "SINGLE" ? "单选题" : items.item_type === "MULTIPLE" ? "多选题" : items.item_type === "JUDGMENT" ? "判断题" : items.item_type === "PROGRAM" ? "编程题" : ""} +

{/*更新时间*/}

更新时间:{items.update_time}

{ - this.props.defaultActiveKey==="0"||this.props.defaultActiveKey===0? + this.props.defaultActiveKey === "0" || this.props.defaultActiveKey === 0 ? "" :

创建者:{items.author.name}

} { - items.item_type==="PROGRAM"? + items.item_type === "PROGRAM" ?

编程语言:{items.program_attr.language}

- :"" + : "" } { - items.item_type==="PROGRAM"? - items.program_attr.status===0? + items.item_type === "PROGRAM" ? + items.program_attr.status === 0 ?

未发布

- :"" - :"" + : "" + : "" }
{ - items.choosed===true? -

this.Selectingpracticaltrainings(items.id)}> + items.choosed === true ? +

this.Selectingpracticaltrainings(items.id)}> 撤销

: - items.item_type==="PROGRAM"? - items.program_attr.status===0? -

+ items.item_type === "PROGRAM" ? + items.program_attr.status === 0 ? +

选用

: -

this.Selectingpracticaltraining(items.id)}> +

this.Selectingpracticaltraining(items.id)}> 选用

: -

this.Selectingpracticaltraining(items.id)}> +

this.Selectingpracticaltraining(items.id)}> 选用

} { - defaultActiveKey===0||defaultActiveKey==="0"? + defaultActiveKey === 0 || defaultActiveKey === "0" ?
-

this.props.showmodelysl(items.id)}> +

this.props.showmodelysl(items.id)}> 删除

{ - items.item_type==="PROGRAM"? + items.item_type === "PROGRAM" ? -

+

编辑

: -

+

编辑

} { - items.public===false? - items.item_type==="PROGRAM"? - items.program_attr.status===0? + items.public === false ? + items.item_type === "PROGRAM" ? + items.program_attr.status === 0 ? "" : -

this.props.showmodels(items.id)}> +

this.props.showmodels(items.id)}> 公开

: -

this.props.showmodels(items.id)}> +

this.props.showmodels(items.id)}> 公开

@@ -256,54 +341,65 @@ class Listjihe extends Component { }
- :"" + : "" } { - items.item_type==="PROGRAM"? + items.item_type === "PROGRAM" ? "" : -

this.props.chakanjiexibool(keindex)}> +

this.props.chakanjiexibool(keindex)}> 查看解析

} -
{ - chakanjiexiboolindex===keindex?
+ chakanjiexiboolindex === keindex ?
-
+
{ - items.item_type==="SINGLE" || items.item_type==="MULTIPLE"? + items.item_type === "SINGLE" || items.item_type === "MULTIPLE" ?

:

}
- { - items&&items.analysis? - "" - :"" - } -
-

+

+ {items ? + items.analysis=== undefined || items.analysis=== null || items.analysis === "" ? + + "" + : + items.analysis.length>0? + + : + "" + : + "" + }

-
:"" +
: "" } @@ -313,4 +409,5 @@ class Listjihe extends Component { } } + export default Listjihe; diff --git a/public/react/src/modules/question/component/SingleEditor.js b/public/react/src/modules/question/component/SingleEditor.js index c111aa41b..c0135ac1f 100644 --- a/public/react/src/modules/question/component/SingleEditor.js +++ b/public/react/src/modules/question/component/SingleEditor.js @@ -75,10 +75,12 @@ class SingleEditor extends Component{ this.state = { question_choices: _question_choices || ['', '', '', ''], standard_answers: _standard_answers || [false, false, false, false], - question_title: this.props.question_title || '', + question_title: this.props.question_title!==undefined?JSON.parse(this.props.question_title):"", question_type: this.props.question_type || 0, question_score: this.props.question_score || this.props.init_question_score, - question_titles:this.props.question_titles||'', + question_titles: this.props.question_titles!==undefined?JSON.parse(this.props.question_titles):"", + question_titlesysl:this.props.question_titlesysl||'', + question_titleysl:this.props.question_title || '', item_banksedit:[], } } @@ -121,12 +123,21 @@ class SingleEditor extends Component{ } onSave = () => { var editordata=[]; - const {question_title, question_score, question_type,question_titles, question_choices, standard_answers } = this.state; + const {question_title, question_titleysl,question_score, question_type,question_titles,question_titlesysl, question_choices, standard_answers } = this.state; const { question_id_to_insert_after, question_id } = this.props // TODO check const answerArray = standard_answers.map((item, index) => { return item == true ? index+1 : -1 }).filter(item => item != -1); - if(!question_title) { - this.refs['titleEditor'].showError() + + // const _text = quill.getText(); + // const reg = /^[\s\S]*.*[^\s][\s\S]*$/; + // if (!reg.test(_text)) { + // // 处理编辑器内容为空 + // } else { + // // 提交到后台的内容需要处理一下; + // value = JSON.stringify(value) + // } + if(!question_titleysl) { + // this.refs['titleEditor'].showError() this.props.showNotification('请您输入题干'); return editordata; } @@ -139,14 +150,13 @@ class SingleEditor extends Component{ for(let i = 0; i < question_choices.length; i++) { if (!question_choices[i]) { - this.refs[`optionEditor${i}`].showError() + // this.refs[`optionEditor${i}`].showError() this.props.showNotification(`请先输入 ${tagArray[i]} 选项的内容`); return editordata; } } - if(!question_titles) { - this.refs['titleEditor2'].showError() + if(!question_titlesysl) { this.props.showNotification('请您输入题目解析'); return editordata; } @@ -158,7 +168,7 @@ class SingleEditor extends Component{ "question_choices":["a答案","b答案","c答案","d答案"], "standard_answers":[1] }*/ - editordata=[question_title,answerArray,question_choices,question_titles]; + editordata=[question_titleysl,answerArray,question_choices,question_titlesysl]; // question_title, // question_type: answerArray.length > 1 ? 1 : 0, // question_score, @@ -184,8 +194,10 @@ class SingleEditor extends Component{ try { this.setState({ item_banksedit:this.props.item_banksedit, - question_title:this.props.item_banksedit.name, - question_titles:this.props.item_banksedit.analysis, + question_title: this.props.item_banksedit.name!==undefined?JSON.parse(this.props.item_banksedit.name):"", + question_titleysl:this.props.item_banksedit.name|| '', + question_titles: this.props.item_banksedit.analysis!==undefined?JSON.parse(this.props.item_banksedit.analysis):"", + question_titlesysl:this.props.item_banksedit.analysis||'', mychoicess:this.props.item_banksedit.choices, }) @@ -204,8 +216,10 @@ class SingleEditor extends Component{ if(prevProps.item_banksedit !== this.props.item_banksedit) { this.setState({ item_banksedit: this.props.item_banksedit, - question_title: this.props.item_banksedit.name, - question_titles: this.props.item_banksedit.analysis, + question_title: this.props.item_banksedit.name!==undefined?JSON.parse(this.props.item_banksedit.name):"", + question_titleysl:this.props.item_banksedit.name|| '', + question_titles: this.props.item_banksedit.analysis!==undefined?JSON.parse(this.props.item_banksedit.analysis):"", + question_titlesysl:this.props.item_banksedit.analysis||'', mychoicess: this.props.item_banksedit.choices, }) @@ -229,14 +243,26 @@ class SingleEditor extends Component{ // standard_answers[index] = !standard_answers[index]; this.setState({ standard_answers }) } - onOptionContentChange = (value, index) => { + onOptionContentChange = (value,quill,index) => { if (index >= this.state.question_choices.length) { // TODO 新建,然后删除CD选项,再输入题干,会调用到这里,且index是3 return; } + var texts; + const _text = quill.getText(); + const reg = /^[\s\S]*.*[^\s][\s\S]*$/; + if (!reg.test(_text)) { + // 处理编辑器内容为空 + texts=""; + } else { + // 提交到后台的内容需要处理一下; + value = JSON.stringify(value) + texts=value; + } let question_choices = this.state.question_choices.slice(0); - question_choices[index] = value; - this.setState({ question_choices }) + question_choices[index] = texts; + console.log(question_choices); + this.setState({ question_choices }); } on_question_score_change = (e) => { this.setState({ question_score: e }) @@ -254,11 +280,46 @@ class SingleEditor extends Component{ } - onContentChange=(e)=>{ - console.log(e); + onContentChange=(value,quill)=>{ + const _text = quill.getText(); + const reg = /^[\s\S]*.*[^\s][\s\S]*$/; + if (!reg.test(_text)) { + // 处理编辑器内容为空 + this.setState({ + question_titleysl:"" + }) + } else { + // 提交到后台的内容需要处理一下; + value = JSON.stringify(value) + this.setState({ + question_titleysl:value + }) + } } + onContentChanges=(value,quill)=>{ + const _text = quill.getText(); + const reg = /^[\s\S]*.*[^\s][\s\S]*$/; + if (!reg.test(_text)) { + // 处理编辑器内容为空 + this.setState({ + question_titlesysl:"" + }) + } else { + // 提交到后台的内容需要处理一下; + value = JSON.stringify(value) + this.setState({ + question_titlesysl:value + }) + } + } + handleShowImage = (url) => { + console.log("点击了图片放大"); + console.log(url); + alert(url); + } + render() { - let { question_title, question_score, question_type, question_choices, standard_answers,question_titles} = this.state; + let { question_title, question_score, question_type, question_choices, standard_answers,question_titles,question_titlesysl} = this.state; let { question_id, index, exerciseIsPublish, // question_title, // question_type, @@ -279,7 +340,6 @@ class SingleEditor extends Component{ // ////console.log("xuanzheshijuan"); // ////console.log(answerTagArray); // ////console.log(!exerciseIsPublish); - return(
- this.setState({ question_titles: val})} - ref="titleEditor2" - - > +
+
diff --git a/public/react/src/modules/question/questioncss/questioncom.css b/public/react/src/modules/question/questioncss/questioncom.css index 5d37aeccd..1bdf3853c 100644 --- a/public/react/src/modules/question/questioncss/questioncom.css +++ b/public/react/src/modules/question/questioncss/questioncom.css @@ -332,6 +332,12 @@ line-height:19px; margin-top: 19px; } +.listjihetixingstitsp{ + color: #333333; + font-size: 14px; + line-height:19px; + margin-top: 10px; +} .listjihetixingstitssy{ color: #333333; font-size: 14px; @@ -939,3 +945,6 @@ .searchwidth{ width: 347px !important; } +.lh26{ + line-height: 26px !important; +}