model.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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: 138,
  9. minHeight: 138,
  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: 12,
  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题,每题4选项为标准展示效果
  40. const numberPerChildren = {
  41. A3: {
  42. 2: [0, 0, 6, 5, 4, 3, 3, 2, 2, 2, 2, 1, 1],
  43. 3: [0, 0, 4, 3, 2, 2, 2, 1],
  44. 4: [0, 0, 3, 2, 2, 1]
  45. },
  46. A4: {
  47. 1: [0, 0, 6, 5, 4, 3, 3, 2, 2, 2, 2, 1, 1],
  48. 2: [0, 0, 3, 2, 2, 1]
  49. }
  50. };
  51. // 以一行4题,每题5选项为标准展示效果
  52. // const numberPerChildren = {
  53. // 2: [0, 0, 7, 5, 4, 4, 3, 3, 2, 2, 2, 2, 1],
  54. // 3: [0, 0, 4, 3, 2, 2, 2, 2, 1],
  55. // 4: [0, 0, 3, 2, 2, 2, 1]
  56. // };
  57. const numList = numberPerChildren[pageSize][columnNumber];
  58. const groupPerLine =
  59. model.optionCount > numList.length
  60. ? numList.pop()
  61. : numList[model.optionCount];
  62. const numPerLine = groupPerLine * model.questionCountPerGroup;
  63. const total = Math.ceil(model.questionsCount / numPerLine);
  64. let elements = [];
  65. for (let i = 0; i < total; i++) {
  66. let child = Object.assign({}, parent, {
  67. id: getElementId(),
  68. key: randomCode(),
  69. groupPerLine,
  70. startNumber: model.startNumber + i * numPerLine,
  71. questionsCount:
  72. i === total - 1 ? model.questionsCount - numPerLine * i : numPerLine,
  73. parent,
  74. isLast: i === total - 1
  75. });
  76. const optionCount =
  77. model.questionDirection === "vertical"
  78. ? Math.min(child.questionsCount, model.questionCountPerGroup)
  79. : Math.ceil(child.questionsCount / groupPerLine);
  80. const optionsHeight =
  81. 14 * optionCount + (optionCount - 1) * model.questionGap + 36;
  82. child.h = i ? optionsHeight : optionsHeight + 34;
  83. child.minHeight = child.h;
  84. elements[i] = child;
  85. }
  86. return elements;
  87. };
  88. export { MODEL, getModel, getFullModel };