123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- import { getElementId, randomCode } from "../../plugins/utils";
- import { BOOLEAN_TYPE } from "../../enumerate";
- const MODEL = {
- type: "FILL_QUESTION",
- x: 0,
- y: 0,
- w: 0,
- h: 114,
- minHeight: 114,
- sign: "objective",
- topicName: "",
- topicNo: null,
- nameFontSize: "14px",
- nameFontWeight: 400,
- startNumber: 1,
- questionsCount: 10,
- optionCount: 4,
- questionCountPerGroup: 5,
- groupPerLine: 4, // 小题纵向排列时,表示每行组数。小题横向排列时,表示每行小题数。
- optionDirection: "horizontal",
- questionDirection: "vertical",
- questionGap: 8,
- groupGap: 30,
- optionGap: 6,
- isBoolean: false, // 是否是判断题
- booleanType: BOOLEAN_TYPE[0],
- isMultiply: false, // 是否是多选题
- isCovered: false,
- fontSize: "14px",
- };
- const getModel = (preSetData = {}) => {
- const model = Object.assign({}, MODEL, preSetData);
- return {
- id: getElementId(),
- key: randomCode(),
- ...model,
- };
- };
- const getOptionStructInfo = (pageSize, columnNumber, model) => {
- // 选项纵向排列
- if (model.optionDirection === "vertical") {
- return { groupGap: 23, groupPerLine: 5 };
- }
- // 选项横向排列
- // 不同栏数,不同选项个数,每一行对应的组数
- // 以一行4题,每题5选项为标准展示效果
- const numberPerChildren = {
- "8K": {
- 1: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
- 2: [0, 0, 6, 5, 4, 3, 3, 2, 2, 2, 2, 2, 1],
- 3: [0, 0, 4, 3, 3, 2, 2, 1],
- 4: [0, 0, 3, 3, 2, 1],
- },
- A3: {
- 2: [0, 0, 7, 6, 5, 4, 3, 3, 3, 2, 2, 2, 2, 1],
- 3: [0, 0, 5, 4, 3, 2, 2, 2, 1],
- 4: [0, 0, 3, 3, 2, 2, 1],
- },
- A4: {
- 1: [0, 0, 7, 6, 5, 4, 3, 3, 3, 2, 2, 2, 2, 1],
- 2: [0, 0, 3, 3, 2, 2, 1],
- },
- };
- const groupGapSet = {
- "8K": {
- 2: [0, 0, 35, 30, 38, 70, 45, 90, 70, 60, 50, 20],
- 3: [0, 0, 32, 35, 16, 60, 40, 30],
- 4: [0, 0, 33, 27, 40, 30],
- },
- A3: {
- 2: [0, 0, 33, 28, 27, 40, 40, 40, 27, 40, 40],
- 3: [0, 0, 27, 27, 40, 40, 40, 40, 30],
- 4: [0, 0, 33, 27, 40, 30],
- },
- A4: {
- 1: [0, 0, 33, 28, 27, 40, 40, 40, 27, 40, 40],
- 2: [0, 0, 33, 27, 40, 30],
- },
- };
- const groupGapList = groupGapSet[pageSize][columnNumber];
- const groupGap =
- model.optionCount >= groupGapList.length
- ? groupGapList.pop()
- : groupGapList[model.optionCount];
- const numList = numberPerChildren[pageSize][columnNumber];
- const groupPerLine =
- model.optionCount >= numList.length
- ? numList.pop()
- : numList[model.optionCount];
- return { groupGap, groupPerLine };
- };
- const getFullModel = (model, { pageSize, columnNumber }) => {
- const parent = { ...model };
- const { groupGap, groupPerLine } = getOptionStructInfo(
- pageSize,
- columnNumber,
- model
- );
- 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,
- groupGap,
- startNumber: model.startNumber + i * numPerLine,
- questionsCount:
- i === total - 1 ? model.questionsCount - numPerLine * i : numPerLine,
- parent,
- isLast: i === total - 1,
- });
- if (model.optionDirection === "vertical") {
- const optionCount = model.optionCount + 1;
- const optionsHeight =
- 10 * optionCount + (optionCount - 1) * model.optionGap + 20;
- child.h = i ? optionsHeight : optionsHeight + 34;
- } else {
- const optionCount =
- model.questionDirection === "vertical"
- ? Math.min(child.questionsCount, model.questionCountPerGroup)
- : Math.ceil(child.questionsCount / groupPerLine);
- const optionsHeight =
- 10 * optionCount + (optionCount - 1) * model.questionGap + 20;
- child.h = i ? optionsHeight : optionsHeight + 34;
- }
- child.minHeight = child.h;
- elements[i] = child;
- }
- return elements;
- };
- export { MODEL, getModel, getFullModel };
|