liwei 1 year ago
parent
commit
9ec32523fe
1 changed files with 37 additions and 28 deletions
  1. 37 28
      src/modules/editor/module/actions/edit.tsx

+ 37 - 28
src/modules/editor/module/actions/edit.tsx

@@ -122,14 +122,13 @@ export const editActions = EditorModule.action({
   const { result } = await this.https.getCompDetail(id, isSys);
 
   //先创建卡片
-  const currCardIndex =  this.store.streamCardIds.indexOf(this.store.currStreamCardId) + 1;
-  const cardId = await this.store.insertDesignContent(
-    "Container",
-    currCardIndex
-  );
-   const currCard = this.helper.findComp(cardId) as DesignComp;
-  
-   debugger
+  // const currCardIndex =  this.store.streamCardIds.indexOf(this.store.currStreamCardId) + 1;
+  // const cardId = await this.store.insertDesignContent(
+  //   "Container",
+  //   currCardIndex
+  // );
+  //  const currCard = this.helper.findComp(cardId) as DesignComp;
+    const currCard = this.store.currStreamCard;  
     const comp =  this.store.addUserCard(result);
 
     const compId = comp.id;
@@ -137,20 +136,26 @@ export const editActions = EditorModule.action({
     childIds.push(compId);
     currCard.children.default = childIds;
 
+    this.store.setCompPid(compId,  currCard.id);
+
     const addedComp = this.store.compMap[compId];
     addedComp.layout.position = "absolute";
 
-    this.actions.initAddedCompPos(this.store.currCompId, compId, cardId);
+    this.actions.initAddedCompPos(this.store.currCompId, compId, currCard.id);
+
+    this.actions.pickComp(compId);
   },
 
 
   initAddedCompPos(currId: string, addedId:string, cardId:string) {
+    
     let yOffset = 0;
     if (
       currId != this.store.currStreamCardId &&
       currId != "root"
     ) {
-      const bound = this.helper.getCardCompBound(currId);
+      const paths = this.helper.getCompTrees(currId)
+      const bound = this.helper.getCardCompBound(paths[2].id);
       yOffset = bound.y + bound.h;
     }
 
@@ -173,7 +178,6 @@ export const editActions = EditorModule.action({
     }
     obj.worldTransform.translate(xOffset, yOffset);
     currComp.layout.transformMatrix = obj.worldTransform.getMatrixStr();
-    this.actions.pickComp(addedId);
     this.helper.extendStreamCard(currCard.id);
     this.controls.cropCtrl.close();
   },
@@ -196,6 +200,7 @@ export const editActions = EditorModule.action({
     
         const addedComp = this.store.compMap[compId];
         addedComp.layout.position = "absolute";
+        this.store.setCompPid(compId,  currCard.id);
 
         this.actions.pickComp(compId);
 
@@ -203,24 +208,28 @@ export const editActions = EditorModule.action({
         await this.actions.addCompToDesign(compKey as any);
     }
 
-    const cardPoints = this.helper.getPointOffsetWith(
-      event,
-      currCardDom
-    );
-    const { currComp } = this.store;
-    let selCtrl = this.controls.selectCtrl;
-    selCtrl.translate(
-      this.helper.designSizeToPx(375 - (currComp.layout.size?.[0] || 750) / 2),
-      cardPoints.y
-    );
-
-    this.helper.extendStreamCard(this.store.currStreamCardId);
 
-    if (compKey == "Text") {
-      this.actions.selectObjs([]);
-      this.actions.textFocus(currComp.id, true);
-    }
-    this.controls.cropCtrl.close();
+    setTimeout(() => {
+      const cardPoints = this.helper.getPointOffsetWith(
+        event,
+        currCardDom
+      );
+      const { currComp } = this.store;
+      let selCtrl = this.controls.selectCtrl;
+      selCtrl.translate(
+        this.helper.designSizeToPx(375 - (currComp.layout.size?.[0] || 750) / 2),
+        cardPoints.y
+      );
+  
+      this.helper.extendStreamCard(this.store.currStreamCardId);
+  
+      if (compKey == "Text") {
+        this.actions.selectObjs([]);
+        this.actions.textFocus(currComp.id, true);
+      }
+      this.controls.cropCtrl.close();
+      
+    }, 100);
   },
 
   async selectObjs(ids: string[]) {