model.js 1.6 KB

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