model.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { getElementId } 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. ...MODEL
  33. };
  34. };
  35. const getFullModel = (model, columnNumber) => {
  36. const parent = { ...model };
  37. // 不同栏数,不同选项个数,每一行对应的组数
  38. // 以一行4题,每题4选项为标准展示效果
  39. const numberPerChildren = {
  40. 2: [0, 0, 6, 5, 4, 3, 3, 2, 2, 2, 2, 1, 1],
  41. 3: [0, 0, 4, 3, 2, 2, 2, 1],
  42. 4: [0, 0, 3, 2, 2, 1]
  43. };
  44. // 以一行4题,每题5选项为标准展示效果
  45. // const numberPerChildren = {
  46. // 2: [0, 0, 7, 5, 4, 4, 3, 3, 2, 2, 2, 2, 1],
  47. // 3: [0, 0, 4, 3, 2, 2, 2, 2, 1],
  48. // 4: [0, 0, 3, 2, 2, 2, 1]
  49. // };
  50. const numList = numberPerChildren[columnNumber];
  51. const groupPerLine =
  52. model.optionCount > numList.length
  53. ? numList.pop()
  54. : numList[model.optionCount];
  55. const numPerLine = groupPerLine * model.questionCountPerGroup;
  56. const total = Math.ceil(model.questionsCount / numPerLine);
  57. let elements = [];
  58. for (let i = 0; i < total; i++) {
  59. let child = Object.assign({}, parent, {
  60. id: getElementId(),
  61. groupPerLine,
  62. startNumber: model.startNumber + i * numPerLine,
  63. questionsCount:
  64. i === total - 1 ? model.questionsCount - numPerLine * i : numPerLine,
  65. parent,
  66. isLast: i === total - 1
  67. });
  68. const optionCount =
  69. model.questionDirection === "vertical"
  70. ? Math.min(child.questionsCount, model.questionCountPerGroup)
  71. : Math.ceil(child.questionsCount / groupPerLine);
  72. const optionsHeight =
  73. 14 * optionCount + (optionCount - 1) * model.questionGap + 36;
  74. child.h = i ? optionsHeight : optionsHeight + 34;
  75. child.minHeight = child.h;
  76. elements[i] = child;
  77. }
  78. return elements;
  79. };
  80. export { MODEL, getModel, getFullModel };