Commit 8ef73141 by yuananting

fix:灰度填空修改合并

parent 9fcfeafa
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: yuananting * @Author: yuananting
* @Date: 2021-02-25 14:34:29 * @Date: 2021-02-25 14:34:29
* @LastEditors: yuananting * @LastEditors: yuananting
* @LastEditTime: 2021-03-25 19:38:03 * @LastEditTime: 2021-03-25 19:52:09
* @Description: 助学工具-题库-题目管理-新建题目Tab * @Description: 助学工具-题库-题目管理-新建题目Tab
* @Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有 * @Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
*/ */
...@@ -103,18 +103,13 @@ class NewQuestionTab extends Component { ...@@ -103,18 +103,13 @@ class NewQuestionTab extends Component {
} }
shouldComponentUpdate(nextProps, nextState) { shouldComponentUpdate(nextProps, nextState) {
console.log("nextProps", nextProps);
const { questionInfo } = nextProps; const { questionInfo } = nextProps;
if (this.props.questionInfo !== questionInfo) { if (this.props.questionInfo !== questionInfo) {
console.log("4. 组件更新:", questionInfo.gapFillingAnswerList); this.setState({
this.setState( gapFillingAnswer: JSON.parse(
{ JSON.stringify(questionInfo.gapFillingAnswerList)
gapFillingAnswer: JSON.parse( ),
JSON.stringify(questionInfo.gapFillingAnswerList) });
),
},
() => console.log("___________________", this.state.gapFillingAnswer)
);
this.setState( this.setState(
{ {
stemContent: JSON.parse( stemContent: JSON.parse(
...@@ -586,23 +581,17 @@ class NewQuestionTab extends Component { ...@@ -586,23 +581,17 @@ class NewQuestionTab extends Component {
} }
changeBlankCount = (data, idx) => { changeBlankCount = (data, idx) => {
console.log(123, data, idx);
const { gapFillingAnswer } = this.state;
let _gap = this.state.gapFillingAnswer; let _gap = this.state.gapFillingAnswer;
console.log(data.length, idx)
if (data.length <= idx) { if (data.length <= idx) {
_gap.splice(idx, 1); _gap.splice(idx, 1);
} else { } else {
data.forEach((item, index) => { data.forEach((item, index) => {
if (index === idx) { if (index === idx) {
if (_gap.length < data.length) { if (_gap.length < data.length) {
console.log(1)
_gap.splice(idx, 0, { correctAnswerList: [] }); _gap.splice(idx, 0, { correctAnswerList: [] });
} else if (_gap.length > data.length) { } else if (_gap.length > data.length) {
console.log(2)
_gap.splice(idx, 1); _gap.splice(idx, 1);
} else { } else {
console.log(3)
_gap.splice(idx, 1, { correctAnswerList: [] }); _gap.splice(idx, 1, { correctAnswerList: [] });
} }
} }
......
...@@ -160,62 +160,59 @@ class QuestionEditor extends Component { ...@@ -160,62 +160,59 @@ class QuestionEditor extends Component {
} }
editorRoot.config.onchange = (html) => { editorRoot.config.onchange = (html) => {
setTimeout(() => { const conLen = html.replace(/<(?!img|input).*?>/g, "").length;
const conLen = html.replace(/<(?!img|input).*?>/g, "").length; counter++;
counter++; const { focusFlag } = this.state;
const { focusFlag } = this.state; const textLength = editorRoot.txt.text().replace(/\&nbsp\;/gi, " ")
const textLength = editorRoot.txt.text().replace(/\&nbsp\;/gi, " ") .length;
.length; const imgLength = html.match(/<img/g)
const imgLength = html.match(/<img/g) ? html.match(/<img/g).length * 2
? html.match(/<img/g).length * 2 : 0;
: 0; const contentLength = imgLength + textLength;
const contentLength = imgLength + textLength; const divHeight = document.getElementById(`editor${editorId}_content`)
const divHeight = document.getElementById(`editor${editorId}_content`) .firstChild.offsetHeight;
.firstChild.offsetHeight; if (divHeight > 30 || imgLength > 0) {
if (divHeight > 30 || imgLength > 0) { this.setState({ isShowSingleInput: false });
this.setState({ isShowSingleInput: false }); } else {
} else { this.setState({ isShowSingleInput: true });
this.setState({ isShowSingleInput: true }); }
} if (
if ( this.state.isGapFilling &&
this.state.isGapFilling && this.state.contentType === "QUESTION_STEM"
this.state.contentType === "QUESTION_STEM" ) {
) { const stemHtml = this.transferStemDocument(html);
const stemHtml = this.transferStemDocument(html); var _blanksList = stemHtml.getElementsByClassName("add-fill-line");
var _blanksList = stemHtml.getElementsByClassName("add-fill-line"); const ids = [..._blanksList].map((item) => item.id);
const ids = [..._blanksList].map((item) => item.id);
const isEdit = getParameterByName("id"); const isEdit = getParameterByName("id");
if (isEdit && counter === 1) { if (isEdit && counter === 1) {
const prev = localStorage.getItem("gap_ques_prevList"); const prev = localStorage.getItem("gap_ques_prevList");
prevList = prev && JSON.parse(prev); prevList = prev && JSON.parse(prev);
} }
let idx = 0; let idx = 0;
if (prevList && ids) { if (prevList && ids) {
console.log(prevList, ids); idx = this.getNewArr(prevList, ids);
idx = this.getNewArr(prevList, ids); const oldLen = prevList.length;
const oldLen = prevList.length; idx = idx >= oldLen ? idx - oldLen : idx;
idx = idx >= oldLen ? idx - oldLen : idx; }
}
prevList = [...ids]; prevList = [...ids];
this.setState({ blanksList: _blanksList }, () => this.setState({ blanksList: _blanksList }, () =>
this.props.changeBlankCount(_blanksList, ids.length > 0 ? idx : -1) this.props.changeBlankCount(_blanksList, ids.length > 0 ? idx : -1)
);
}
this.setState(
{
contentLength,
visiblePlacehold:
(conLen === 0 || (conLen === 1 && html === " ")) && !focusFlag,
},
() => {
onChange && onChange(html, this.state.contentLength);
}
); );
}, 0); }
this.setState(
{
contentLength,
visiblePlacehold:
(conLen === 0 || (conLen === 1 && html === " ")) && !focusFlag,
},
() => {
onChange && onChange(html, this.state.contentLength);
}
);
}; };
editorRoot.config.onblur = () => { editorRoot.config.onblur = () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment