model.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 === "8K" && columnNumber === 4) ||
  63. (pageSize === "A3" && columnNumber === 4) ||
  64. (pageSize === "A4" && columnNumber === 2)
  65. ) {
  66. npage.columnGap = 10;
  67. }
  68. npage.locators = getLocators();
  69. npage.columns = getNumList(columnNumber).map(() => {
  70. return { id: `column-${randomCode()}`, ...deepCopy(COLUMN) };
  71. });
  72. return npage;
  73. };
  74. export { MODEL, getModel };