123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- import {
- getElementId,
- randomCode,
- deepCopy,
- getNumList,
- objAssign
- } from "../../plugins/utils";
- const MODEL = {
- type: "PAGE",
- columnGap: 20,
- locators: [],
- globals: [],
- columns: [],
- pageSize: "A3",
- columnNumber: 2,
- showForbidArea: false
- };
- // 可编辑栏
- const COLUMN = {
- type: "COLUMN",
- x: "",
- y: "",
- w: "",
- h: "",
- elements: []
- };
- // 定位点
- const LOCATOR = {
- type: "LOCATOR",
- x: "",
- y: "",
- w: "",
- h: ""
- };
- const getLocators = () => {
- const id = getElementId();
- return {
- top: [
- {
- id: `locator-${id}-00`,
- ...LOCATOR
- },
- {
- id: `locator-${id}-01`,
- ...LOCATOR
- }
- ],
- bottom: [
- {
- id: `locator-${id}-10`,
- ...LOCATOR
- }
- ]
- };
- };
- const getModel = (datas = {}) => {
- let npage = deepCopy(MODEL);
- npage = objAssign(npage, datas);
- npage.id = getElementId();
- const { pageSize, columnNumber } = npage;
- if (
- (pageSize === "A3" && columnNumber === 4) ||
- (pageSize === "A4" && columnNumber === 2)
- ) {
- npage.columnGap = 10;
- }
- npage.locators = getLocators();
- npage.columns = getNumList(columnNumber).map(() => {
- return { id: `column-${randomCode()}`, ...deepCopy(COLUMN) };
- });
- return npage;
- };
- export { MODEL, getModel };
|