model.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { getElementId, randomCode } from "../../plugins/utils";
  2. import { BOOLEAN_TYPE } from "../../enumerate";
  3. const MODEL = {
  4. type: "FILL_QUESTION",
  5. x: 0,
  6. y: 0,
  7. w: 0,
  8. h: 114,
  9. minHeight: 114,
  10. sign: "objective",
  11. topicName: "",
  12. topicNo: null,
  13. startNumber: 1,
  14. questionsCount: 10,
  15. optionCount: 4,
  16. questionCountPerGroup: 5,
  17. groupPerLine: 4, // 小题纵向排列时,表示每行组数。小题横向排列时,表示每行小题数。
  18. optionDirection: "horizontal",
  19. questionDirection: "vertical",
  20. questionGap: 8,
  21. groupGap: 30,
  22. optionGap: 6,
  23. isBoolean: false, // 是否是判断题
  24. booleanType: BOOLEAN_TYPE[0],
  25. isMultiply: false, // 是否是多选题
  26. isCovered: false,
  27. fontSize: "14px",
  28. };
  29. const getModel = () => {
  30. return {
  31. id: getElementId(),
  32. key: randomCode(),
  33. ...MODEL,
  34. };
  35. };
  36. const getFullModel = (model, { pageSize, columnNumber }) => {
  37. const parent = { ...model };
  38. // 不同栏数,不同选项个数,每一行对应的组数
  39. // 以一行4题,每题5选项为标准展示效果
  40. const numberPerChildren = {
  41. A3: {
  42. 2: [0, 0, 7, 6, 5, 4, 3, 3, 3, 2, 2, 2, 2, 1],
  43. 3: [0, 0, 5, 4, 3, 2, 2, 2, 1],
  44. 4: [0, 0, 3, 3, 2, 2, 1],
  45. },
  46. A4: {
  47. 1: [0, 0, 7, 6, 5, 4, 3, 3, 3, 2, 2, 2, 2, 1],
  48. 2: [0, 0, 3, 3, 2, 2, 1],
  49. },
  50. };
  51. const groupGapSet = {
  52. A3: {
  53. 2: [0, 0, 33, 28, 27, 40, 40, 40, 27, 40, 40],
  54. 3: [0, 0, 27, 27, 40, 40, 40, 40, 30],
  55. 4: [0, 0, 33, 27, 40, 30],
  56. },
  57. A4: {
  58. 1: [0, 0, 33, 28, 27, 40, 40, 40, 27, 40, 40],
  59. 2: [0, 0, 33, 27, 40, 30],
  60. },
  61. };
  62. const groupGapList = groupGapSet[pageSize][columnNumber];
  63. const groupGap =
  64. model.optionCount >= groupGapList.length
  65. ? groupGapList.pop()
  66. : groupGapList[model.optionCount];
  67. const numList = numberPerChildren[pageSize][columnNumber];
  68. const groupPerLine =
  69. model.optionCount >= numList.length
  70. ? numList.pop()
  71. : numList[model.optionCount];
  72. const numPerLine = groupPerLine * model.questionCountPerGroup;
  73. const total = Math.ceil(model.questionsCount / numPerLine);
  74. let elements = [];
  75. for (let i = 0; i < total; i++) {
  76. let child = Object.assign({}, parent, {
  77. id: getElementId(),
  78. key: randomCode(),
  79. groupPerLine,
  80. groupGap,
  81. startNumber: model.startNumber + i * numPerLine,
  82. questionsCount:
  83. i === total - 1 ? model.questionsCount - numPerLine * i : numPerLine,
  84. parent,
  85. isLast: i === total - 1,
  86. });
  87. const optionCount =
  88. model.questionDirection === "vertical"
  89. ? Math.min(child.questionsCount, model.questionCountPerGroup)
  90. : Math.ceil(child.questionsCount / groupPerLine);
  91. const optionsHeight =
  92. 14 * optionCount + (optionCount - 1) * model.questionGap + 20;
  93. child.h = i ? optionsHeight : optionsHeight + 24;
  94. child.minHeight = child.h;
  95. elements[i] = child;
  96. }
  97. return elements;
  98. };
  99. export { MODEL, getModel, getFullModel };