|
@@ -5,7 +5,10 @@ import { CompObject } from "../../controllers/SelectCtrl/compObj";
|
|
import { Matrix } from "../../controllers/SelectCtrl/matrix";
|
|
import { Matrix } from "../../controllers/SelectCtrl/matrix";
|
|
import { Design_Page_Size, Design_Pixel_Ratio } from "../../dicts/CompOptions";
|
|
import { Design_Page_Size, Design_Pixel_Ratio } from "../../dicts/CompOptions";
|
|
import { DesignComp } from "../../objects/DesignTemp/DesignComp";
|
|
import { DesignComp } from "../../objects/DesignTemp/DesignComp";
|
|
-import { createCompStyle, createViewStyles } from "../../objects/DesignTemp/creates/createCompStyle";
|
|
|
|
|
|
+import {
|
|
|
|
+ createCompStyle,
|
|
|
|
+ createViewStyles,
|
|
|
|
+} from "../../objects/DesignTemp/creates/createCompStyle";
|
|
import { Layout } from "../../typings";
|
|
import { Layout } from "../../typings";
|
|
import { designSizeToPx, pxToDesignSize } from "../utils";
|
|
import { designSizeToPx, pxToDesignSize } from "../utils";
|
|
|
|
|
|
@@ -39,7 +42,7 @@ export const helpers = EditorModule.helper({
|
|
isStreamCard(compId: string) {
|
|
isStreamCard(compId: string) {
|
|
return this.controls.pageCtrl.streamCardIds.indexOf(compId) > -1;
|
|
return this.controls.pageCtrl.streamCardIds.indexOf(compId) > -1;
|
|
},
|
|
},
|
|
-
|
|
|
|
|
|
+
|
|
isGroupCompChild(compId: string) {
|
|
isGroupCompChild(compId: string) {
|
|
const comps = this.helper.getCompTrees(compId);
|
|
const comps = this.helper.getCompTrees(compId);
|
|
comps.pop();
|
|
comps.pop();
|
|
@@ -57,7 +60,7 @@ export const helpers = EditorModule.helper({
|
|
}
|
|
}
|
|
const cards = this.controls.pageCtrl.streamCardIds;
|
|
const cards = this.controls.pageCtrl.streamCardIds;
|
|
let n = cards.length;
|
|
let n = cards.length;
|
|
- const ctrl = this.controls.pageCtrl
|
|
|
|
|
|
+ const ctrl = this.controls.pageCtrl;
|
|
const compMap = ctrl.designData.compMap;
|
|
const compMap = ctrl.designData.compMap;
|
|
while (n--) {
|
|
while (n--) {
|
|
const childs = compMap[cards[n]].children.default || [];
|
|
const childs = compMap[cards[n]].children.default || [];
|
|
@@ -69,18 +72,18 @@ export const helpers = EditorModule.helper({
|
|
findParentComp(compId: string): DesignComp | undefined {
|
|
findParentComp(compId: string): DesignComp | undefined {
|
|
const comp = this.helper.findComp(compId);
|
|
const comp = this.helper.findComp(compId);
|
|
|
|
|
|
- if (comp) return this.helper.findComp(this.controls.pageCtrl.compPids[compId]);
|
|
|
|
|
|
+ if (comp)
|
|
|
|
+ return this.helper.findComp(this.controls.pageCtrl.compPids[compId]);
|
|
},
|
|
},
|
|
|
|
|
|
findRootComp(): DesignComp | undefined {
|
|
findRootComp(): DesignComp | undefined {
|
|
return this.controls.pageCtrl.rootPage;
|
|
return this.controls.pageCtrl.rootPage;
|
|
},
|
|
},
|
|
|
|
|
|
- findCardAllChildren(index:number) {
|
|
|
|
-
|
|
|
|
- const ctrl = this.controls.pageCtrl
|
|
|
|
|
|
+ findCardAllChildren(index: number) {
|
|
|
|
+ const ctrl = this.controls.pageCtrl;
|
|
const cardId = ctrl.streamCardIds[index];
|
|
const cardId = ctrl.streamCardIds[index];
|
|
- return ctrl.designData.compMap[cardId].children.default || [] as string[];
|
|
|
|
|
|
+ return ctrl.designData.compMap[cardId].children.default || ([] as string[]);
|
|
},
|
|
},
|
|
|
|
|
|
getCompCard(compId: string) {
|
|
getCompCard(compId: string) {
|
|
@@ -94,8 +97,8 @@ export const helpers = EditorModule.helper({
|
|
let n = paths.length;
|
|
let n = paths.length;
|
|
let box = paths[1].$el.getBoundingClientRect();
|
|
let box = paths[1].$el.getBoundingClientRect();
|
|
const s = this.controls.editorCtrl.state.scale;
|
|
const s = this.controls.editorCtrl.state.scale;
|
|
- m.translate((box.left - vx) / s, (box.top - vy)/s);
|
|
|
|
-
|
|
|
|
|
|
+ m.translate((box.left - vx) / s, (box.top - vy) / s);
|
|
|
|
+
|
|
for (let i = 2; i < n - 1; i++) {
|
|
for (let i = 2; i < n - 1; i++) {
|
|
//card开始遍历
|
|
//card开始遍历
|
|
const m1 = new Matrix();
|
|
const m1 = new Matrix();
|
|
@@ -106,7 +109,7 @@ export const helpers = EditorModule.helper({
|
|
},
|
|
},
|
|
|
|
|
|
getCompTrees(compId: string) {
|
|
getCompTrees(compId: string) {
|
|
- const ctrl = this.controls.pageCtrl;
|
|
|
|
|
|
+ const ctrl = this.controls.pageCtrl;
|
|
|
|
|
|
const comps: DesignComp[] = [];
|
|
const comps: DesignComp[] = [];
|
|
const getParentComp = (compId: string) => {
|
|
const getParentComp = (compId: string) => {
|
|
@@ -120,16 +123,22 @@ export const helpers = EditorModule.helper({
|
|
return comps;
|
|
return comps;
|
|
},
|
|
},
|
|
createStyle(layout: Partial<Layout> & { size: any[] }, comp: DesignComp) {
|
|
createStyle(layout: Partial<Layout> & { size: any[] }, comp: DesignComp) {
|
|
- return createCompStyle(this, layout, comp);
|
|
|
|
|
|
+ const parentId = this.controls.pageCtrl.compPids[comp.id];
|
|
|
|
+ return createCompStyle(this, layout, comp, parentId);
|
|
},
|
|
},
|
|
- createViewStyles(layout: Partial<Layout> & { size: any[] }, comp: DesignComp) {
|
|
|
|
|
|
+ createViewStyles(
|
|
|
|
+ layout: Partial<Layout> & { size: any[] },
|
|
|
|
+ comp: DesignComp
|
|
|
|
+ ) {
|
|
return createViewStyles(this, layout);
|
|
return createViewStyles(this, layout);
|
|
},
|
|
},
|
|
isCurrComp(compId: string) {
|
|
isCurrComp(compId: string) {
|
|
const gizmo = this.controls.selectCtrl.gizmo;
|
|
const gizmo = this.controls.selectCtrl.gizmo;
|
|
- return gizmo.selectedIds.length == 1 && gizmo.selected[0].comp.id === compId;
|
|
|
|
|
|
+ return (
|
|
|
|
+ gizmo.selectedIds.length == 1 && gizmo.selected[0].comp.id === compId
|
|
|
|
+ );
|
|
},
|
|
},
|
|
-
|
|
|
|
|
|
+
|
|
isCustomChildComp(comp: DesignComp): boolean {
|
|
isCustomChildComp(comp: DesignComp): boolean {
|
|
const parentComp = this.helper.findParentComp(comp.id);
|
|
const parentComp = this.helper.findParentComp(comp.id);
|
|
if (!parentComp) return false;
|
|
if (!parentComp) return false;
|
|
@@ -183,20 +192,20 @@ export const helpers = EditorModule.helper({
|
|
};
|
|
};
|
|
getUsedIds(["root"]);
|
|
getUsedIds(["root"]);
|
|
const ctrl = this.controls.pageCtrl;
|
|
const ctrl = this.controls.pageCtrl;
|
|
- const compScreenMap = ctrl.designData.compScreenMap
|
|
|
|
- const keys = Object.keys(compScreenMap)
|
|
|
|
- keys.forEach(k=>{
|
|
|
|
- const card = compScreenMap[k];
|
|
|
|
- card.forEach(c=>{
|
|
|
|
- c.children.forEach(item=>{
|
|
|
|
- const comp = compMap[item.id];
|
|
|
|
- if (!comp) return;
|
|
|
|
- used.add(item.id);
|
|
|
|
- getUsedIds([item.id])
|
|
|
|
- })
|
|
|
|
- })
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
|
|
+ const compScreenMap = ctrl.designData.compScreenMap;
|
|
|
|
+ const keys = Object.keys(compScreenMap);
|
|
|
|
+ keys.forEach((k) => {
|
|
|
|
+ const card = compScreenMap[k];
|
|
|
|
+ card.forEach((c) => {
|
|
|
|
+ c.children.forEach((item) => {
|
|
|
|
+ const comp = compMap[item.id];
|
|
|
|
+ if (!comp) return;
|
|
|
|
+ used.add(item.id);
|
|
|
|
+ getUsedIds([item.id]);
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+
|
|
Object.keys(compMap).forEach((compId) => {
|
|
Object.keys(compMap).forEach((compId) => {
|
|
if (!used.has(compId)) {
|
|
if (!used.has(compId)) {
|
|
delete compMap[compId];
|
|
delete compMap[compId];
|
|
@@ -204,7 +213,6 @@ export const helpers = EditorModule.helper({
|
|
});
|
|
});
|
|
},
|
|
},
|
|
|
|
|
|
-
|
|
|
|
getPointOffsetWith(e: MouseEvent, dom: HTMLElement) {
|
|
getPointOffsetWith(e: MouseEvent, dom: HTMLElement) {
|
|
const domRect = dom.getBoundingClientRect();
|
|
const domRect = dom.getBoundingClientRect();
|
|
return {
|
|
return {
|
|
@@ -214,7 +222,6 @@ export const helpers = EditorModule.helper({
|
|
},
|
|
},
|
|
|
|
|
|
getCardCompBound(compId: string) {
|
|
getCardCompBound(compId: string) {
|
|
-
|
|
|
|
const ctrl = this.controls.pageCtrl;
|
|
const ctrl = this.controls.pageCtrl;
|
|
const compMap = ctrl.designData.compMap;
|
|
const compMap = ctrl.designData.compMap;
|
|
const c = compMap[compId];
|
|
const c = compMap[compId];
|
|
@@ -229,14 +236,14 @@ export const helpers = EditorModule.helper({
|
|
const ctrl = this.controls.pageCtrl;
|
|
const ctrl = this.controls.pageCtrl;
|
|
const compMap = ctrl.designData.compMap;
|
|
const compMap = ctrl.designData.compMap;
|
|
const card = compMap[streamCardId];
|
|
const card = compMap[streamCardId];
|
|
- const size:any = card.layout.size.slice(0)
|
|
|
|
|
|
+ const size: any = card.layout.size.slice(0);
|
|
if (this.controls.screenCtrl.isShortPage) {
|
|
if (this.controls.screenCtrl.isShortPage) {
|
|
- const h = this.controls.screenCtrl.getCurrScreenHeight();
|
|
|
|
|
|
+ const h = this.controls.screenCtrl.getCurrScreenHeight();
|
|
size[1] = h;
|
|
size[1] = h;
|
|
card.layout.setSize(size);
|
|
card.layout.setSize(size);
|
|
- return h;
|
|
|
|
|
|
+ return h;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
const childs = card.children.default || [];
|
|
const childs = card.children.default || [];
|
|
let maxH = 0,
|
|
let maxH = 0,
|
|
n = childs.length;
|
|
n = childs.length;
|
|
@@ -250,35 +257,35 @@ export const helpers = EditorModule.helper({
|
|
maxH = 200;
|
|
maxH = 200;
|
|
}
|
|
}
|
|
size[1] = maxH;
|
|
size[1] = maxH;
|
|
- card.layout.setSize(size);
|
|
|
|
|
|
+ card.layout.setSize(size);
|
|
return maxH;
|
|
return maxH;
|
|
},
|
|
},
|
|
|
|
|
|
- getCardNextPosY(cardId:string, itemWidth:number) {
|
|
|
|
- let yOffset = 0;
|
|
|
|
- if (cardId != this.controls.pageCtrl.state.currStreamCardId) {
|
|
|
|
- //const paths = this.helper.getCompTrees(cardId);
|
|
|
|
- const bound = this.helper.getCardCompBound(cardId);
|
|
|
|
|
|
+ getCardNextPosY(cardId: string, itemWidth: number) {
|
|
|
|
+ let yOffset = 0;
|
|
|
|
+ if (cardId != this.controls.pageCtrl.state.currStreamCardId) {
|
|
|
|
+ //const paths = this.helper.getCompTrees(cardId);
|
|
|
|
+ const bound = this.helper.getCardCompBound(cardId);
|
|
|
|
+ yOffset = bound.y + bound.h;
|
|
|
|
+ } else {
|
|
|
|
+ const currCard = this.helper.findComp(cardId) as DesignComp;
|
|
|
|
+ //没有选中组件添加到当前卡片最后
|
|
|
|
+ const children = currCard.children.default || [];
|
|
|
|
+ let prevCompIndex = -1;
|
|
|
|
+ if (this.store.currCompId != "" && this.store.currCompId != "root") {
|
|
|
|
+ prevCompIndex = children.indexOf(this.store.currCompId);
|
|
|
|
+ }
|
|
|
|
+ if (prevCompIndex != -1) {
|
|
|
|
+ const bound = this.helper.getCardCompBound(children[prevCompIndex]);
|
|
yOffset = bound.y + bound.h;
|
|
yOffset = bound.y + bound.h;
|
|
- } else {
|
|
|
|
- const currCard = this.helper.findComp(cardId) as DesignComp;
|
|
|
|
- //没有选中组件添加到当前卡片最后
|
|
|
|
- const children = currCard.children.default || [];
|
|
|
|
- let prevCompIndex = -1;
|
|
|
|
- if (this.store.currCompId != "" && this.store.currCompId != "root") {
|
|
|
|
- prevCompIndex = children.indexOf(this.store.currCompId);
|
|
|
|
- }
|
|
|
|
- if (prevCompIndex != -1) {
|
|
|
|
- const bound = this.helper.getCardCompBound(children[prevCompIndex]);
|
|
|
|
- yOffset = bound.y + bound.h;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
- const w = this.controls.screenCtrl.getCurrScreenWidth();
|
|
|
|
- //添加组件到当前选中的组件下面
|
|
|
|
- const xOffset:number = this.helper.designSizeToPx(
|
|
|
|
- w / 2.0 - (itemWidth || w) / 2
|
|
|
|
- );
|
|
|
|
- return {x: xOffset, y: yOffset};
|
|
|
|
|
|
+ }
|
|
|
|
+ const w = this.controls.screenCtrl.getCurrScreenWidth();
|
|
|
|
+ //添加组件到当前选中的组件下面
|
|
|
|
+ const xOffset: number = this.helper.designSizeToPx(
|
|
|
|
+ w / 2.0 - (itemWidth || w) / 2
|
|
|
|
+ );
|
|
|
|
+ return { x: xOffset, y: yOffset };
|
|
},
|
|
},
|
|
|
|
|
|
getClientId() {
|
|
getClientId() {
|
|
@@ -296,21 +303,21 @@ export const helpers = EditorModule.helper({
|
|
return clientId;
|
|
return clientId;
|
|
},
|
|
},
|
|
|
|
|
|
- loadImage(url ) {
|
|
|
|
- return new Promise((res, rej)=>{
|
|
|
|
- let t = setTimeout(() => {
|
|
|
|
|
|
+ loadImage(url) {
|
|
|
|
+ return new Promise((res, rej) => {
|
|
|
|
+ let t = setTimeout(() => {
|
|
t = null as any;
|
|
t = null as any;
|
|
- rej("下载超时")
|
|
|
|
- }, 1000 * 10);
|
|
|
|
- const img = new Image();
|
|
|
|
- img.onload = ()=>{
|
|
|
|
- res(img);
|
|
|
|
- if (t) clearTimeout(t);
|
|
|
|
- }
|
|
|
|
- img.onerror = (e)=>{
|
|
|
|
- rej("下载失败!")
|
|
|
|
- }
|
|
|
|
- img.src = url;
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
|
|
+ rej("下载超时");
|
|
|
|
+ }, 1000 * 10);
|
|
|
|
+ const img = new Image();
|
|
|
|
+ img.onload = () => {
|
|
|
|
+ res(img);
|
|
|
|
+ if (t) clearTimeout(t);
|
|
|
|
+ };
|
|
|
|
+ img.onerror = (e) => {
|
|
|
|
+ rej("下载失败!");
|
|
|
|
+ };
|
|
|
|
+ img.src = url;
|
|
|
|
+ });
|
|
|
|
+ },
|
|
});
|
|
});
|