model.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import {
  2. getElementId,
  3. randomCode,
  4. deepCopy,
  5. getNumList,
  6. objAssign
  7. } from "../../plugins/utils";
  8. const MODEL = {
  9. type: "PAGE",
  10. columnGap: 20,
  11. locators: [],
  12. globals: [],
  13. columns: [],
  14. pageSize: "A3",
  15. columnNumber: 2,
  16. showForbidArea: false
  17. };
  18. // 可编辑栏
  19. const COLUMN = {
  20. type: "COLUMN",
  21. x: "",
  22. y: "",
  23. w: "",
  24. h: "",
  25. elements: []
  26. };
  27. // 定位点
  28. const LOCATOR = {
  29. type: "LOCATOR",
  30. x: "",
  31. y: "",
  32. w: "",
  33. h: ""
  34. };
  35. const getLocators = () => {
  36. const id = getElementId();
  37. return {
  38. top: [
  39. {
  40. id: `locator-${id}-00`,
  41. ...LOCATOR
  42. },
  43. {
  44. id: `locator-${id}-01`,
  45. ...LOCATOR
  46. }
  47. ],
  48. bottom: [
  49. {
  50. id: `locator-${id}-10`,
  51. ...LOCATOR
  52. }
  53. ]
  54. };
  55. };
  56. const getModel = (datas = {}) => {
  57. let npage = deepCopy(MODEL);
  58. npage = objAssign(npage, datas);
  59. npage.id = getElementId();
  60. const { pageSize, columnNumber } = npage;
  61. if (
  62. (pageSize === "A3" && columnNumber === 4) ||
  63. (pageSize === "A4" && columnNumber === 2)
  64. ) {
  65. npage.columnGap = 10;
  66. }
  67. npage.locators = getLocators();
  68. npage.columns = getNumList(columnNumber).map(() => {
  69. return { id: `column-${randomCode()}`, ...deepCopy(COLUMN) };
  70. });
  71. return npage;
  72. };
  73. export { MODEL, getModel };