model.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { deepCopy, getElementId, randomCode } from "../../../../plugins/utils";
  2. const MODEL = {
  3. type: "FILL_LINE",
  4. x: 0,
  5. y: 0,
  6. w: 500,
  7. h: 100,
  8. minHeight: 40,
  9. sign: "subjective",
  10. topicName: "",
  11. topicNo: null,
  12. startNumber: 1,
  13. questionsCount: 4,
  14. questionNumberPerLine: 2,
  15. lineNumberPerQuestion: 1,
  16. lineSpacing: 40,
  17. questionDirection: "vertical",
  18. questionLineType: "norm",
  19. questionLineNums: [],
  20. numberPre: "",
  21. isCovered: false
  22. };
  23. const getModel = (options = {}) => {
  24. let model = Object.assign({}, deepCopy(MODEL), options);
  25. model.key = randomCode();
  26. if (!model.id) model.id = getElementId();
  27. if (model.questionLineType === "norm") {
  28. let questionLineNums = [];
  29. for (
  30. let j = model.startNumber;
  31. j < model.startNumber + model.questionsCount;
  32. j++
  33. ) {
  34. questionLineNums.push({
  35. no: j,
  36. count: model.lineNumberPerQuestion
  37. });
  38. }
  39. model.questionLineNums = questionLineNums;
  40. } else {
  41. const orgQuestionLineCounts = model.questionLineNums.map(
  42. item => item.count
  43. );
  44. let questionLineNums = [];
  45. for (let j = 0; j < model.questionsCount; j++) {
  46. questionLineNums.push({
  47. no: j + model.startNumber,
  48. count: orgQuestionLineCounts[j] || model.lineNumberPerQuestion
  49. });
  50. }
  51. model.questionLineNums = questionLineNums;
  52. }
  53. return model;
  54. };
  55. export { MODEL, getModel };