From fbb29ad1a91503b864b6fc0663c0c57df018e823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=9E=97?= <904079904@qq.com> Date: Tue, 18 Feb 2020 14:15:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E9=80=89=E9=A2=98=E9=A2=98=E5=BA=93?= =?UTF-8?q?=E5=AD=97=E6=95=B0=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../question/component/ChoquesEditor.js | 43 ++++++++++++--- .../question/component/JudquestionEditor.js | 24 +++++++-- .../question/component/SingleEditor.js | 54 +++++++++++++++---- 3 files changed, 100 insertions(+), 21 deletions(-) diff --git a/public/react/src/modules/question/component/ChoquesEditor.js b/public/react/src/modules/question/component/ChoquesEditor.js index e442eeda8..c96b8a6b7 100644 --- a/public/react/src/modules/question/component/ChoquesEditor.js +++ b/public/react/src/modules/question/component/ChoquesEditor.js @@ -232,8 +232,16 @@ class ChoquesEditor extends Component { texts=JSON.stringify(texts); }else { // 提交到后台的内容需要处理一下; - value = JSON.stringify(value); - texts = value; + value = JSON.stringify(value); + if(value.length>=500){ + let a=value.length-500; + let b=_text.length-a; + var result = _text.substring(0,b); + texts={"ops":[{"insert":result}]}; + texts=JSON.stringify(texts); + }else{ + texts=value; + } } } let question_choices = this.state.question_choices.slice(0); @@ -258,7 +266,8 @@ class ChoquesEditor extends Component { } - onContentChange = (value, quill) => { + onContentChange=(value,quill)=>{ + debugger const _text = quill.getText(); const reg = /^[\s\S]*.*[^\s][\s\S]*$/; if (!reg.test(_text)) { @@ -279,9 +288,19 @@ class ChoquesEditor extends Component { var result = _text.substring(0,975); texts={"ops":[{"insert":result}]}; texts=JSON.stringify(texts); + console.log("111111111"); + console.log(texts.length); }else { - value = JSON.stringify(value) - texts=value; + value = JSON.stringify(value); + if(value.length>=1000){ + let a=value.length-1000; + let b=_text.length-a; + var result = _text.substring(0,b); + texts={"ops":[{"insert":result}]}; + texts=JSON.stringify(texts); + }else{ + texts=value; + } } this.setState({ question_titleysl: texts @@ -309,9 +328,19 @@ class ChoquesEditor extends Component { var result = _text.substring(0,975); texts={"ops":[{"insert":result}]}; texts=JSON.stringify(texts); + console.log("2222222"); + console.log(texts.length); }else { - value = JSON.stringify(value) - texts=value; + value = JSON.stringify(value); + if(value.length>=1000){ + let a=value.length-1000; + let b=_text.length-a; + var result = _text.substring(0,b); + texts={"ops":[{"insert":result}]}; + texts=JSON.stringify(texts); + }else{ + texts=value; + } } this.setState({ question_titlesysl: texts diff --git a/public/react/src/modules/question/component/JudquestionEditor.js b/public/react/src/modules/question/component/JudquestionEditor.js index 9f6b5c96a..c82088105 100644 --- a/public/react/src/modules/question/component/JudquestionEditor.js +++ b/public/react/src/modules/question/component/JudquestionEditor.js @@ -307,8 +307,16 @@ class JudquestionEditor extends Component { texts={"ops":[{"insert":result}]}; texts=JSON.stringify(texts); }else { - value = JSON.stringify(value) - texts=value; + value = JSON.stringify(value); + if(value.length>=1000){ + let a=value.length-1000; + let b=_text.length-a; + var result = _text.substring(0,b); + texts={"ops":[{"insert":result}]}; + texts=JSON.stringify(texts); + }else{ + texts=value; + } } this.setState({ question_titleysl: texts @@ -338,8 +346,16 @@ class JudquestionEditor extends Component { texts={"ops":[{"insert":result}]}; texts=JSON.stringify(texts); }else { - value =JSON.stringify(value); - texts=value; + value = JSON.stringify(value); + if(value.length>=1000){ + let a=value.length-1000; + let b=_text.length-a; + var result = _text.substring(0,b); + texts={"ops":[{"insert":result}]}; + texts=JSON.stringify(texts); + }else{ + texts=value; + } } this.setState({ question_titlesysl: texts diff --git a/public/react/src/modules/question/component/SingleEditor.js b/public/react/src/modules/question/component/SingleEditor.js index a2500544c..88580a023 100644 --- a/public/react/src/modules/question/component/SingleEditor.js +++ b/public/react/src/modules/question/component/SingleEditor.js @@ -253,8 +253,16 @@ class SingleEditor extends Component { texts=JSON.stringify(texts); }else { // 提交到后台的内容需要处理一下; - value = JSON.stringify(value) - texts = value; + value = JSON.stringify(value); + if(value.length>=500){ + let a=value.length-500; + let b=_text.length-a; + var result = _text.substring(0,b); + texts={"ops":[{"insert":result}]}; + texts=JSON.stringify(texts); + }else{ + texts=value; + } } } let question_choices = this.state.question_choices.slice(0); @@ -317,16 +325,29 @@ class SingleEditor extends Component { var texts=""; if(_text.length>=979){ var result = _text.substring(0,975); - console.log("11111111"); - console.log(result.length); + // console.log("11111111"); + // console.log(result.length); texts={"ops":[{"insert":result}]}; texts=JSON.stringify(texts); - console.log("2222"); - console.log(texts.length); + // console.log("2222"); + // console.log(texts.length); }else { +<<<<<<< HEAD value = JSON.stringify(value) texts=value; >>>>>>> 91722ce... 题库字数优化 +======= + value = JSON.stringify(value); + if(value.length>=1000){ + let a=value.length-1000; + let b=_text.length-a; + var result = _text.substring(0,b); + texts={"ops":[{"insert":result}]}; + texts=JSON.stringify(texts); + }else{ + texts=value; + } +>>>>>>> 3610b7e... 多选题题库字数优化 } this.setState({ question_titleysl: texts @@ -376,16 +397,29 @@ class SingleEditor extends Component { var texts=""; if(_text.length>=979){ var result = _text.substring(0,975); - console.log("33333333"); - console.log(result.length); + // console.log("33333333"); + // console.log(result.length); texts={"ops":[{"insert":result}]}; texts=JSON.stringify(texts); - console.log("44444444"); - console.log(texts.length); + // ; console.log("44444444"); + // console.log(texts.length) }else { +<<<<<<< HEAD value = JSON.stringify(value) texts=value; >>>>>>> 91722ce... 题库字数优化 +======= + value = JSON.stringify(value); + if(value.length>=1000){ + let a=value.length-1000; + let b=_text.length-a; + var result = _text.substring(0,b); + texts={"ops":[{"insert":result}]}; + texts=JSON.stringify(texts); + }else{ + texts=value; + } +>>>>>>> 3610b7e... 多选题题库字数优化 } this.setState({ question_titlesysl: texts