|
@@ -7,23 +7,23 @@ import { DesignComp } from "../../objects/DesignTemp/DesignComp";
|
|
|
import { ICompKeys, Layout } from "../../typings";
|
|
|
|
|
|
export const editActions = EditorModule.action({
|
|
|
-
|
|
|
pickComp(compId: string, selected = true) {
|
|
|
- if (compId == "") {//空的时候,就选择根页面
|
|
|
+ if (compId == "") {
|
|
|
+ //空的时候,就选择根页面
|
|
|
compId = "root";
|
|
|
}
|
|
|
- const selectCardChild = (id:string)=>{
|
|
|
- const paths = this.helper.getCompTrees(id)
|
|
|
- const cardChilds = paths[2];
|
|
|
- if (cardChilds) {
|
|
|
- this.actions.selectObjs([cardChilds.id])
|
|
|
- } else {
|
|
|
- this.actions.selectObjs([])
|
|
|
- if (id != "root") {
|
|
|
- this.store.setCurrComp(this.store.currStreamCardId);
|
|
|
- }
|
|
|
+ const selectCardChild = (id: string) => {
|
|
|
+ const paths = this.helper.getCompTrees(id);
|
|
|
+ const cardChilds = paths[2];
|
|
|
+ if (cardChilds) {
|
|
|
+ this.actions.selectObjs([cardChilds.id]);
|
|
|
+ } else {
|
|
|
+ this.actions.selectObjs([]);
|
|
|
+ if (id != "root") {
|
|
|
+ this.store.setCurrComp(this.store.currStreamCardId);
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
if (this.store.currCompId == compId) {
|
|
|
return;
|
|
@@ -34,14 +34,13 @@ export const editActions = EditorModule.action({
|
|
|
}
|
|
|
},
|
|
|
|
|
|
-
|
|
|
// 通过点击添加组件到画布
|
|
|
async clickCompToDesign(compKey: ICompKeys, cb?: (comp: DesignComp) => void) {
|
|
|
if (!this.store.currStreamCardId) {
|
|
|
- queenApi.messageError("请先选中一个卡片")
|
|
|
+ queenApi.messageError("请先选中一个卡片");
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//点击默认都创建一个容器
|
|
|
//创建容器
|
|
|
const isCreatCard =
|
|
@@ -61,30 +60,41 @@ export const editActions = EditorModule.action({
|
|
|
}
|
|
|
|
|
|
let currCard = this.store.currStreamCard;
|
|
|
-
|
|
|
+
|
|
|
if (isCreatCard) {
|
|
|
//先创建卡片
|
|
|
- const currCardIndex = this.store.streamCardIds.indexOf(this.store.currStreamCardId) + 1;
|
|
|
- const compId = await this.store.insertDesignContent("Container", currCardIndex);
|
|
|
+ const currCardIndex =
|
|
|
+ this.store.streamCardIds.indexOf(this.store.currStreamCardId) + 1;
|
|
|
+ const compId = await this.store.insertDesignContent(
|
|
|
+ "Container",
|
|
|
+ currCardIndex
|
|
|
+ );
|
|
|
currCard = this.helper.findComp(compId) as DesignComp;
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
const compId = await this.store.insertCompContainer(compKey, currCard);
|
|
|
const addedComp = this.store.compMap[compId];
|
|
|
addedComp.layout.position = "absolute";
|
|
|
|
|
|
- const currComp = this.helper.findComp(compId) as DesignComp;
|
|
|
+ const currComp = this.helper.findComp(compId) as DesignComp;
|
|
|
cb?.(currComp);
|
|
|
|
|
|
//添加组件到当前选中的组件下面
|
|
|
let xOffset = this.helper.designSizeToPx(
|
|
|
375 - (currComp.layout.size?.[0] || 750) / 2
|
|
|
);
|
|
|
- const obj = new CompObject(currComp)
|
|
|
+ const obj = new CompObject(currComp);
|
|
|
+ //没有选中组件添加到当前卡片最后
|
|
|
+ const children = currCard.children.default || [];
|
|
|
+ if (yOffset == 0 && children.length >= 2) {
|
|
|
+ const prevCompIndex = children.indexOf(compId) - 1;
|
|
|
+ const bound = this.helper.getCardCompBound(children[prevCompIndex]);
|
|
|
+ yOffset = bound.y + bound.h;
|
|
|
+ }
|
|
|
obj.worldTransform.translate(xOffset, yOffset);
|
|
|
currComp.layout.transformMatrix = obj.worldTransform.getMatrixStr();
|
|
|
-
|
|
|
- this.actions.pickComp(compId)
|
|
|
+
|
|
|
+ this.actions.pickComp(compId);
|
|
|
this.helper.extendStreamCard(currCard.id);
|
|
|
|
|
|
if (compKey == "Text") {
|
|
@@ -114,11 +124,11 @@ export const editActions = EditorModule.action({
|
|
|
this.actions.textFocus(currComp.id, true);
|
|
|
}
|
|
|
},
|
|
|
-
|
|
|
- async selectObjs(ids: string[]) {
|
|
|
- this.store.selected = ids;
|
|
|
- this.store.selectId = ids.length > 1 ? (Date.now() + "") : ""
|
|
|
- },
|
|
|
+
|
|
|
+ async selectObjs(ids: string[]) {
|
|
|
+ this.store.selected = ids;
|
|
|
+ this.store.selectId = ids.length > 1 ? Date.now() + "" : "";
|
|
|
+ },
|
|
|
|
|
|
// 添加组件到画布
|
|
|
async addCompToDesign(compKey: ICompKeys, index?: number) {
|
|
@@ -193,7 +203,7 @@ export const editActions = EditorModule.action({
|
|
|
const selected = this.store.selected.slice(0);
|
|
|
this.actions.selectObjs([]);
|
|
|
let n = selected.length;
|
|
|
- while( n--) {
|
|
|
+ while (n--) {
|
|
|
this.actions.removeComp(selected[n]);
|
|
|
}
|
|
|
},
|
|
@@ -410,14 +420,15 @@ export const editActions = EditorModule.action({
|
|
|
this.store.setCurrComp(groupComp.children.default?.[0] as string);
|
|
|
},
|
|
|
|
|
|
- handleSelectMoving(key:string) {
|
|
|
+ handleSelectMoving(key: string) {
|
|
|
if (this.store.selected.length < 1) return;
|
|
|
- let x = 0, y = 0;
|
|
|
- switch(key) {
|
|
|
+ let x = 0,
|
|
|
+ y = 0;
|
|
|
+ switch (key) {
|
|
|
case "left":
|
|
|
x = -1;
|
|
|
break;
|
|
|
- case "right":
|
|
|
+ case "right":
|
|
|
x = 1;
|
|
|
break;
|
|
|
case "up":
|
|
@@ -427,7 +438,7 @@ export const editActions = EditorModule.action({
|
|
|
y = 1;
|
|
|
break;
|
|
|
}
|
|
|
- this.controls.selectCtrl.translate(x*0.5, y*0.5);
|
|
|
+ this.controls.selectCtrl.translate(x * 0.5, y * 0.5);
|
|
|
this.controls.selectCtrl.assistCtrl?.flashDrawCardDists();
|
|
|
- }
|
|
|
+ },
|
|
|
});
|