Browse Source

init click comp

bianjiang 1 year ago
parent
commit
99407e2cd5
1 changed files with 25 additions and 14 deletions
  1. 25 14
      src/modules/editor/module/actions/edit.ts

+ 25 - 14
src/modules/editor/module/actions/edit.ts

@@ -16,26 +16,37 @@ export const editActions = EditorModule.action({
       this.store.currStreamCard.$el
     );
     const { currComp } = this.store;
-    let selCtrl = this.controls.selectCtrl
-    selCtrl.translate(this.helper.designSizeToPx(375 - (currComp.layout.size?.[0] || 750) / 2), cardPoints.y);
+    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);
-
   },
   // 通过点击添加组件到画布
   async clickCompToDesign(compKey: ICompKeys, cb?: (comp: DesignComp) => void) {
-
     //点击默认都创建一个容器
     //创建容器
-    const isCreatCard =  compKey != "Text" && compKey != "Image" && compKey != "Video" && compKey != "Web3D";
+    const isCreatCard =
+      compKey != "Text" &&
+      compKey != "Image" &&
+      compKey != "Video" &&
+      compKey != "Web3D";
 
     let yOffset = 0;
-    if (this.store.currCompId != this.store.currStreamCardId && !isCreatCard) {
+    if (
+      this.store.currCompId != this.store.currStreamCardId &&
+      !isCreatCard &&
+      this.store.currCompId != "root"
+    ) {
       const bound = this.helper.getCardCompBound(this.store.currCompId);
-        yOffset = bound.y + bound.h
+      yOffset = bound.y + bound.h;
     }
 
-    if (isCreatCard) { //先创建卡片
-      const index = this.store.streamCardIds.indexOf(this.store.currStreamCardId) + 1;
+    if (isCreatCard) {
+      //先创建卡片
+      const index =
+        this.store.streamCardIds.indexOf(this.store.currStreamCardId) + 1;
       const compId = await this.store.insertDesignContent("Container", index);
       this.actions.pickComp(compId);
     }
@@ -45,7 +56,9 @@ export const editActions = EditorModule.action({
 
     //添加组件到当前选中的组件下面
     const selectCtrl = this.controls.selectCtrl;
-    let xOffset = this.helper.designSizeToPx(375 - (currComp.layout.size?.[0] || 750) / 2);
+    let xOffset = this.helper.designSizeToPx(
+      375 - (currComp.layout.size?.[0] || 750) / 2
+    );
     selectCtrl.translate(xOffset, yOffset);
     selectCtrl.selecteObjs([]);
 
@@ -53,8 +66,6 @@ export const editActions = EditorModule.action({
     this.helper.extendStreamCard(this.store.currStreamCardId);
   },
 
-  
-
   // 添加组件到画布
   async addCompToDesign(compKey: ICompKeys, index?: number) {
     if (!this.store.currStreamCardId) {
@@ -73,10 +84,10 @@ export const editActions = EditorModule.action({
       compKey,
       this.store.currStreamCard
     );
-    const addedComp = this.store.compMap[compId]
+    const addedComp = this.store.compMap[compId];
     this.actions.setCompPositionFloat(addedComp);
 
-    this.controls.selectCtrl.selecteObjs([new CompObject(addedComp)])
+    this.controls.selectCtrl.selecteObjs([new CompObject(addedComp)]);
   },
 
   // 切换当前组件