model.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { getElementId, randomCode, deepCopy } from "../../plugins/utils";
  2. import { getModel as createLines } from "../lines/model";
  3. const COMPOSITION_PROP = {
  4. type: "COMPOSITION",
  5. sign: "subjective",
  6. topicNo: null,
  7. topicName: ""
  8. };
  9. const MODEL = {
  10. type: "COMPOSITION",
  11. x: 0,
  12. y: 0,
  13. w: 0,
  14. h: 350,
  15. minHeight: 60,
  16. sign: "subjective",
  17. topicNo: null,
  18. isCovered: false,
  19. // 是否是最后一个答题区,初始只有一个答题区,默认为true
  20. isLast: true,
  21. // 是否是扩展的答题区
  22. isExtend: false,
  23. // 是否展示作文题题目内容,作文题第1个答题区需要显示作文题题目内容
  24. showTitle: true,
  25. // 答题区序号,默认为0
  26. serialNumber: 0,
  27. // 每一个作文题都可以包含其他基础元件
  28. // 新建作文题,默认插入5线的多横线
  29. elements: [],
  30. // 作文题整体信息,COMPOSITION_PROP
  31. parent: {}
  32. };
  33. const getModel = () => {
  34. return {
  35. id: getElementId(),
  36. key: randomCode(),
  37. ...COMPOSITION_PROP
  38. };
  39. };
  40. const getFullModel = compositionProp => {
  41. const parent = { ...compositionProp };
  42. let model = {
  43. id: getElementId(),
  44. key: randomCode(),
  45. ...deepCopy(MODEL)
  46. };
  47. model.w = parent.w;
  48. model.parent = parent;
  49. model.topicNo = parent.topicNo;
  50. let linesModel = createLines();
  51. linesModel.lineCount = 5;
  52. linesModel.h = linesModel.lineCount * (linesModel.lineSpacing + 3);
  53. linesModel.w = parent.w;
  54. linesModel.container = {
  55. id: model.id,
  56. type: model.type
  57. };
  58. model.h = linesModel.h + 50;
  59. model.elements.push(linesModel);
  60. return model;
  61. };
  62. export { MODEL, getModel, getFullModel };