|
@@ -14,21 +14,26 @@ function parseSimpleQuestion(simpleQuestion) {
|
|
|
return {
|
|
|
detailNo: detailNo * 1,
|
|
|
questionNo: questionNo * 1,
|
|
|
- subQno: subQno && subQno * 1,
|
|
|
+ subQno: subQno ? subQno * 1 : null,
|
|
|
questionType,
|
|
|
qinfo: qinfo * 1,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+function checkDetailIsOnlyOneNested(detail) {
|
|
|
+ const firstQuestionNo = detail.questions[0].questionNo;
|
|
|
+ return !detail.questions.some((q) => q.questionNo !== firstQuestionNo);
|
|
|
+}
|
|
|
+
|
|
|
function parsePaperStruct(paperSimpleStruct) {
|
|
|
// console.log(paperSimpleStruct);
|
|
|
const dataList = paperSimpleStruct.split("#");
|
|
|
const details = dataList.filter((item) => item.startsWith("detail"));
|
|
|
let detailNames = {};
|
|
|
details.forEach((detail) => {
|
|
|
- const [detailNos, detailName] = detail.split("-");
|
|
|
- const detailNo = detailNos.replace("detail:", "") * 1;
|
|
|
- detailNames[detailNo] = detailName;
|
|
|
+ const pos = detail.indexOf("-");
|
|
|
+ const detailNo = detail.substring(0, pos).replace("detail:", "") * 1;
|
|
|
+ detailNames[detailNo] = detail.substring(pos + 1);
|
|
|
});
|
|
|
const questions = dataList
|
|
|
.filter((item) => !item.startsWith("detail"))
|
|
@@ -50,8 +55,9 @@ function parsePaperStruct(paperSimpleStruct) {
|
|
|
|
|
|
let structList = [];
|
|
|
detailList.forEach((detail) => {
|
|
|
- const commonQuestions = detail.questions.filter((q) =>
|
|
|
- COMMON_QUESTION_TYPES.includes(q.questionType)
|
|
|
+ detail.isOnlyOneNested = checkDetailIsOnlyOneNested(detail);
|
|
|
+ const commonQuestions = detail.questions.filter(
|
|
|
+ (q) => COMMON_QUESTION_TYPES.includes(q.questionType) && q.subQno === null
|
|
|
);
|
|
|
if (commonQuestions.length) {
|
|
|
const commonStructList = getCommonQuestionStructList(
|
|
@@ -63,9 +69,7 @@ function parsePaperStruct(paperSimpleStruct) {
|
|
|
structList.push(...commonStructList);
|
|
|
}
|
|
|
|
|
|
- const nestedQuestions = detail.questions.filter(
|
|
|
- (q) => !COMMON_QUESTION_TYPES.includes(q.questionType)
|
|
|
- );
|
|
|
+ const nestedQuestions = detail.questions.filter((q) => q.subQno !== null);
|
|
|
if (nestedQuestions.length) {
|
|
|
const nestedStructList = getNestedQuestionStructList(
|
|
|
detail,
|
|
@@ -100,6 +104,7 @@ function getCommonQuestionStructList(
|
|
|
structList.push({
|
|
|
detailName: detail.detailName,
|
|
|
detailNo: detail.detailNo,
|
|
|
+ isOnlyOneNested: detail.isOnlyOneNested,
|
|
|
structType,
|
|
|
isCommon,
|
|
|
nestedQNo,
|
|
@@ -135,6 +140,7 @@ function getNestedQuestionStructList(detail, questions) {
|
|
|
false,
|
|
|
question.questionNo
|
|
|
);
|
|
|
+ // console.log(qStructList);
|
|
|
structList.push(...qStructList);
|
|
|
});
|
|
|
return structList;
|