import { getElementId, randomCode } from "../../plugins/utils"; import { BOOLEAN_TYPE } from "../../enumerate"; const MODEL = { type: "FILL_QUESTION", x: 0, y: 0, w: 0, h: 138, minHeight: 138, 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, isBoolean: false, // 是否是判断题 booleanType: BOOLEAN_TYPE[0], isMultiply: false, // 是否是多选题 isCovered: false, fontSize: "14px", }; const getModel = () => { return { id: getElementId(), key: randomCode(), ...MODEL, }; }; const getFullModel = (model, { pageSize, columnNumber }) => { const parent = { ...model }; // 不同栏数,不同选项个数,每一行对应的组数 // 以一行4题,每题4选项为标准展示效果 const numberPerChildren = { 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], }, A4: { 1: [0, 0, 6, 5, 4, 3, 3, 2, 2, 2, 2, 1, 1], 2: [0, 0, 3, 2, 2, 1], }, }; // 以一行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); let elements = []; for (let i = 0; i < total; i++) { 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, }); const optionCount = model.questionDirection === "vertical" ? Math.min(child.questionsCount, model.questionCountPerGroup) : Math.ceil(child.questionsCount / groupPerLine); const optionsHeight = 14 * optionCount + (optionCount - 1) * model.questionGap + 36; child.h = i ? optionsHeight : optionsHeight + 34; child.minHeight = child.h; elements[i] = child; } return elements; }; export { MODEL, getModel, getFullModel };