|
@@ -1,5 +1,5 @@
|
|
|
-import { getElementId, randomCode } from "../../plugins/utils";
|
|
|
-import { BOOLEAN_TYPE } from "../../enumerate";
|
|
|
+import { getElementId, randomCode, objAssign } from "../../plugins/utils";
|
|
|
+import { BOOLEAN_TYPE, ALPHABET } from "../../enumerate";
|
|
|
|
|
|
const MODEL = {
|
|
|
type: "FILL_QUESTION",
|
|
@@ -11,82 +11,115 @@ const MODEL = {
|
|
|
sign: "objective",
|
|
|
topicName: "",
|
|
|
topicNo: null,
|
|
|
- startNumber: 1,
|
|
|
- questionsCount: 10,
|
|
|
- optionCount: 4,
|
|
|
questionCountPerGroup: 5,
|
|
|
- groupPerLine: 4, // 小题纵向排列时,表示每行组数。小题横向排列时,表示每行小题数。
|
|
|
- optionDirection: "horizontal",
|
|
|
- questionDirection: "vertical",
|
|
|
questionGap: 8,
|
|
|
groupGap: 30,
|
|
|
optionGap: 12,
|
|
|
+ questions: [], // question: questionNo,optionCount
|
|
|
+ questionGroup: [],
|
|
|
isBoolean: false, // 是否是判断题
|
|
|
booleanType: BOOLEAN_TYPE[0],
|
|
|
isMultiply: false, // 是否是多选题
|
|
|
isCovered: false,
|
|
|
- fontSize: "14px",
|
|
|
};
|
|
|
|
|
|
-const getModel = () => {
|
|
|
- return {
|
|
|
- id: getElementId(),
|
|
|
- key: randomCode(),
|
|
|
- ...MODEL,
|
|
|
- };
|
|
|
+function getChoiceList(data) {
|
|
|
+ if (data.isBoolean) {
|
|
|
+ return data.booleanType.split(",");
|
|
|
+ } else {
|
|
|
+ return ALPHABET.slice(0, data.optionCount).split("");
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const getModel = (presetData) => {
|
|
|
+ const model = objAssign(MODEL, presetData);
|
|
|
+ model.id = getElementId();
|
|
|
+ model.key = randomCode();
|
|
|
+ return model;
|
|
|
};
|
|
|
|
|
|
const getFullModel = (model, { pageSize, columnNumber }) => {
|
|
|
const parent = { ...model };
|
|
|
// 不同栏数,不同选项个数,每一行对应的组数
|
|
|
- // 以一行4题,每题4选项为标准展示效果
|
|
|
- const numberPerChildren = {
|
|
|
+ // 以一行4题,每题4选项为标准展示效果:选项序号占一个选项位置,即一行最多展示20个选项位置。
|
|
|
+ // 可扩展其他分栏的最佳展示效果
|
|
|
+ const lineMaxOptionCountConfig = {
|
|
|
A3: {
|
|
|
- 2: [0, 0, 6, 5, 4, 3, 3, 2, 2, 2, 2, 1, 1],
|
|
|
- 3: [0, 0, 4, 3, 2, 2, 2, 1],
|
|
|
- 4: [0, 0, 3, 2, 2, 1],
|
|
|
+ 2: 20,
|
|
|
},
|
|
|
A4: {
|
|
|
- 1: [0, 0, 6, 5, 4, 3, 3, 2, 2, 2, 2, 1, 1],
|
|
|
- 2: [0, 0, 3, 2, 2, 1],
|
|
|
+ 1: 20,
|
|
|
},
|
|
|
};
|
|
|
- // 以一行4题,每题5选项为标准展示效果
|
|
|
- // const numberPerChildren = {
|
|
|
- // 2: [0, 0, 7, 5, 4, 4, 3, 3, 2, 2, 2, 2, 1],
|
|
|
- // 3: [0, 0, 4, 3, 2, 2, 2, 2, 1],
|
|
|
- // 4: [0, 0, 3, 2, 2, 2, 1]
|
|
|
- // };
|
|
|
- const numList = numberPerChildren[pageSize][columnNumber];
|
|
|
- const groupPerLine =
|
|
|
- model.optionCount > numList.length
|
|
|
- ? numList.pop()
|
|
|
- : numList[model.optionCount];
|
|
|
- const numPerLine = groupPerLine * model.questionCountPerGroup;
|
|
|
- const total = Math.ceil(model.questionsCount / numPerLine);
|
|
|
+ const lineMaxOptionCount = lineMaxOptionCountConfig[pageSize][columnNumber];
|
|
|
+ let questionList = model.questions.map((item) => {
|
|
|
+ const choiceList = getChoiceList({
|
|
|
+ ...item,
|
|
|
+ isBoolean: model.isBoolean,
|
|
|
+ booleanType: model.booleanType,
|
|
|
+ });
|
|
|
+ return {
|
|
|
+ ...item,
|
|
|
+ choiceList,
|
|
|
+ };
|
|
|
+ });
|
|
|
+
|
|
|
+ const getNextGroupQuestions = () => {
|
|
|
+ let isEnough = false;
|
|
|
+ let groupOptionCount = 0;
|
|
|
+ let groups = [];
|
|
|
+ do {
|
|
|
+ const curGroup = questionList.splice(0, model.questionCountPerGroup);
|
|
|
+ if (curGroup.length) {
|
|
|
+ const curGroupMaxOptionCount = Math.max.apply(
|
|
|
+ null,
|
|
|
+ curGroup.map((item) => item.optionCount)
|
|
|
+ );
|
|
|
+ if (
|
|
|
+ curGroupMaxOptionCount + 1 + groupOptionCount <=
|
|
|
+ lineMaxOptionCount
|
|
|
+ ) {
|
|
|
+ groupOptionCount += curGroupMaxOptionCount + 1;
|
|
|
+ groups.push(curGroup);
|
|
|
+ } else {
|
|
|
+ isEnough = true;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ isEnough = true;
|
|
|
+ }
|
|
|
+ } while (!isEnough);
|
|
|
+
|
|
|
+ return groups;
|
|
|
+ };
|
|
|
+
|
|
|
let elements = [];
|
|
|
- for (let i = 0; i < total; i++) {
|
|
|
+
|
|
|
+ while (questionList.length) {
|
|
|
+ const questionGroup = getNextGroupQuestions();
|
|
|
let child = Object.assign({}, parent, {
|
|
|
id: getElementId(),
|
|
|
key: randomCode(),
|
|
|
- groupPerLine,
|
|
|
- startNumber: model.startNumber + i * numPerLine,
|
|
|
- questionsCount:
|
|
|
- i === total - 1 ? model.questionsCount - numPerLine * i : numPerLine,
|
|
|
parent,
|
|
|
- isLast: i === total - 1,
|
|
|
+ isFirst: !elements.length,
|
|
|
+ isLast: false,
|
|
|
+ questionGroup,
|
|
|
});
|
|
|
- const optionCount =
|
|
|
- model.questionDirection === "vertical"
|
|
|
- ? Math.min(child.questionsCount, model.questionCountPerGroup)
|
|
|
- : Math.ceil(child.questionsCount / groupPerLine);
|
|
|
+ const maxOptionCountPerGroup =
|
|
|
+ questionGroup.length > 1
|
|
|
+ ? model.questionCountPerGroup
|
|
|
+ : questionGroup[0].length;
|
|
|
const optionsHeight =
|
|
|
- 14 * optionCount + (optionCount - 1) * model.questionGap + 36;
|
|
|
- child.h = i ? optionsHeight : optionsHeight + 34;
|
|
|
- child.minHeight = child.h;
|
|
|
+ 14 * maxOptionCountPerGroup +
|
|
|
+ (maxOptionCountPerGroup - 1) * model.questionGap +
|
|
|
+ 36;
|
|
|
|
|
|
- elements[i] = child;
|
|
|
+ child.h = elements.length ? optionsHeight : optionsHeight + 34;
|
|
|
+ child.minHeight = child.h;
|
|
|
+ elements.push(child);
|
|
|
}
|
|
|
+
|
|
|
+ elements[elements.length - 1].isLast = true;
|
|
|
+
|
|
|
return elements;
|
|
|
};
|
|
|
|