model.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { getElementId, 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. ...COMPOSITION_PROP
  37. };
  38. };
  39. const getFullModel = compositionProp => {
  40. const parent = { ...compositionProp };
  41. let model = {
  42. id: getElementId(),
  43. ...deepCopy(MODEL)
  44. };
  45. model.w = parent.w;
  46. model.parent = parent;
  47. model.topicNo = parent.topicNo;
  48. let linesModel = createLines();
  49. linesModel.lineCount = 5;
  50. linesModel.h = linesModel.lineCount * (linesModel.lineSpacing + 3);
  51. linesModel.w = parent.w;
  52. linesModel.container = {
  53. id: model.id,
  54. type: model.type
  55. };
  56. model.h = linesModel.h + 50;
  57. model.elements.push(linesModel);
  58. return model;
  59. };
  60. export { MODEL, getModel, getFullModel };