Commit 9413e388 by sunbingqing

fix: 编辑问题

parent 670804b8
/*
* @Author: 陈剑宇
* @Date: 2020-05-07 14:43:01
* @LastEditTime: 2021-03-11 11:43:59
* @LastEditors: yuananting
* @LastEditTime: 2021-03-18 16:53:23
* @LastEditors: sunbingqing
* @Description:
* @FilePath: /wheat-web-demo/src/domains/basic-domain/constants.ts
*/
import { MapInterface } from '@/domains/basic-domain/interface'
// 默认是 dev 环境
const ENV: string = process.env.DEPLOY_ENV || 'dev1';
const ENV: string = process.env.DEPLOY_ENV || 'dev';
console.log("process.env.DEPLOY_ENV",process)
const BASIC_HOST_MAP: MapInterface = {
dev: 'https://dev-heimdall.xiaomai5.com/',
......
......@@ -2,7 +2,7 @@
* @Author: yuananting
* @Date: 2021-02-25 14:34:29
* @LastEditors: sunbingqing
* @LastEditTime: 2021-03-18 14:55:15
* @LastEditTime: 2021-03-18 18:44:09
* @Description: 助学工具-题库-题目管理-新建题目Tab
* @Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
*/
......@@ -530,9 +530,24 @@ class NewQuestionTab extends Component {
});
}
changeBlankCount = (data) => {
changeBlankCount = (data, idx) => {
console.log("data:", data);
data && data.length > 0 && data.forEach((item) => {
const { gapFillingAnswer } = this.state;
let _gap = [...gapFillingAnswer];
console.log(9, _gap)
data && data.length > 0 && data.forEach((item, index) => {
if (index === idx) {
if (_gap.length < data.length) {
_gap.splice(idx, 0, {correctAnswerList: []})
} else if (_gap.length > data.length){
_gap.splice(idx, 1)
} else {
_gap.splice(idx, 1, {correctAnswerList: []})
}
}
if (!item.correctAnswerList) {
item.correctAnswerList = [];
}
......@@ -541,8 +556,16 @@ class NewQuestionTab extends Component {
item.editInput = false;
return item;
});
this.setState({ blanksList: data });
};
console.log('idx', idx)
console.log('****', _gap)
this.setState({
blanksList: data,
gapFillingAnswer: _gap
});
};
addAnswerTag = (optionItem) => {
const _blanksList = this.state.blanksList;
......@@ -554,26 +577,27 @@ class NewQuestionTab extends Component {
this.setState({ blanksList: _blanksList });
};
// 填空选项
handleInputConfirm = (optionItem, val) => {
const _blanksList = this.state.blanksList;
// const { gapFillingAnswer } = this.state;
let _gapFillingAnswer = [];
const { gapFillingAnswer } = this.state;
console.log(0.2, val)
console.log(0.3, optionItem)
let _gapFillingAnswer = [...gapFillingAnswer];
console.log(0.4, _gapFillingAnswer)
_blanksList.forEach((item, index) => {
gapFillingAnswer.push({ correctAnswerList: item.answerTagList });
// if (gapFillingAnswer[index] && gapFillingAnswer[index].correctAnswerList) {
// _gapFillingAnswer[index] = gapFillingAnswer[index]
// } else {
// _gapFillingAnswer.push({ correctAnswerList: item.correctAnswerList });
// }
if (item.id === optionItem.id) {
if (val) {
optionItem.correctAnswerList.push(val);
_gapFillingAnswer[index].correctAnswerList.push(val);
optionItem.inputVisible = false;
} else {
optionItem.errorHold = true;
}
}
});
})
console.log(8888, _gapFillingAnswer)
this.setState({ gapFillingAnswer: _gapFillingAnswer }, () => this._onSetState());
this.setState({ blanksList: _blanksList });
......@@ -1147,10 +1171,6 @@ class NewQuestionTab extends Component {
} = this.state;
const { stemValidate, stemText, radioValidate, radioText } = this.state;
const isJudge = this.props.questionTypeKey === "JUDGE";
<<<<<<< HEAD
=======
>>>>>>> acb5ccd546aa59474df75f3b0397b7308f9d5b12
const isGapFilling = this.props.questionTypeKey === "GAP_FILLING";
const placehold = isGapFilling ? (
<span>
......
......@@ -40,7 +40,6 @@ class QuestionEditor extends Component {
isGapFilling: props.isGapFilling,
contentType: props.contentType,
detailInfo: props.detailInfo || {},
gapFillingAnswer: props.gapFillingAnswer || [],
blanksList: props.blanksList || [],
};
}
......@@ -138,7 +137,18 @@ class QuestionEditor extends Component {
return str;
};
let prevList = []
const isEdit = getParameterByName('id');
if (isEdit) {
const stemDom = document.getElementsByClassName("add-fill-line");
prevList = [...stemDom].map(item => item.id)
console.log('!!!!!!!!!', prevList)
localStorage.setItem('gap_ques_prevList', JSON.stringify(prevList));
}
let counter = 0
editorRoot.customConfig.onchange = (html) => {
counter ++;
const { focusFlag } = this.state;
const textLength = editorRoot.txt.text().replace(/\&nbsp\;/gi, " ")
.length;
......@@ -153,9 +163,33 @@ class QuestionEditor extends Component {
} else {
this.setState({ isShowSingleInput: true });
}
if (this.state.isGapFilling) {
console.log(9999, this.state.isGapFilling)
this.props.changeBlankCount(this.state.blanksList);
if (this.state.isGapFilling && this.state.contentType === "QUESTION_STEM") {
const stemHtml = this.transferStemDocument(html);
var _blanksList = stemHtml.getElementsByClassName("add-fill-line")
const ids = [..._blanksList].map(item => item.id);
const isEdit = getParameterByName('id');
if (isEdit && counter === 1) {
const prev = localStorage.getItem('gap_ques_prevList');
prevList = prev && JSON.parse(prev);
}
console.log(prevList, '++++++++++++++++', ids)
let idx = 0;
if (prevList && ids) {
idx = this.getNewArr(prevList, ids);
const oldLen = prevList.length;
console.log(555, idx, oldLen)
idx = idx >= oldLen ? idx - oldLen : idx
}
prevList = [...ids];
this.setState({ blanksList: _blanksList }, () => this.props.changeBlankCount(_blanksList, idx))
}
this.setState(
{ contentLength, visiblePlacehold: contentLength === 0 && !focusFlag },
......@@ -210,6 +244,21 @@ class QuestionEditor extends Component {
bindChangeContent && bindChangeContent(this.handleChangeContent);
}
getNewArr(a, b) {
const arr = [...a, ...b];
const idx = arr.findIndex(item => {
return !(a.includes(item) && b.includes(item));
});
return idx;
}
transferStemDocument = (txt) => {
const template = `<div class='option-content'>${txt}</div>`;
let doc = new DOMParser().parseFromString(template, "text/html");
let div = doc.querySelector(".option-content");
return div;
};
insertBlank = (blanks) => {
var blanks = `<input class="add-fill-line" disabled correctAnswerList="[]" id=${window.random_string(
16
......
/*
* @Author: chenjianyu
* @Date: 2020-09-12 17:00:44
* @LastEditTime: 2021-03-18 09:33:26
* @LastEditors: yuananting
* @LastEditTime: 2021-03-18 17:23:09
* @LastEditors: sunbingqing
* @Description: 答题模式模板
* @Copyright © 2020 杭州杰竞科技有限公司 版权所有
*/
......@@ -56,9 +56,9 @@ export function defineQuestionInfo(questionType) {
], // 题干
optionList: questionType === "JUDGE" ? [] : [], // 非填空题选项
gapFillingAnswerList: [
{
correctAnswerList: []
}
// {
// correctAnswerList: []
// }
], //填空题填空项
questionAnswerDescList: [
{
......
......@@ -124,7 +124,7 @@ class QuestionPreviewModal extends Component {
`<input
class="add-fill-line"
disabled
answerTagList=""
correctAnswerList=""
id=${window.random_string(16)}
value="填空"
/>`
......
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