liwei 1 year ago
parent
commit
0e97031609

+ 13 - 10
src/modules/editor/components/CompUI/basicUI/View.tsx

@@ -5,6 +5,7 @@ import { defineComponent } from "vue";
 import { string } from "vue-types";
 import { useEditor } from "../../..";
 import { useCompRef } from "./hooks";
+import { CompObject } from "@/modules/editor/controllers/SelectCtrl/compObj";
 
 export const View = defineComponent({
   props: {
@@ -20,6 +21,9 @@ export const View = defineComponent({
       if (!comp) return store.isEditMode ? <div>无效组件</div> : null;
       const isStreamCard = helper.isStreamCard(props.compId);
       const isGroupComp = helper.isGroupComp(props.compId);
+      const obj =new CompObject(store.compMap[props.compId])
+      const m = obj.worldTransform.clone();
+      m.invert();
 
       return (
         <div
@@ -39,17 +43,15 @@ export const View = defineComponent({
           onDblclick={() => emit("dblclick")}
         >
           <div
-            // onMousedown={(e) => {
-            //   if (helper.isGroupCompChild(props.compId)) return;
+            onMousedown={(e) => {
+              if (helper.isGroupCompChild(props.compId)) return;
+              e.stopPropagation();
+              
+              if (store.isEditMode) {
+                actions.pickComp(props.compId);
+              }
+            }}
 
-            //   // e.stopPropagation();
-            //   if (store.isEditMode) {
-            //     actions.pickComp(props.compId);
-            //     if (!helper.isStreamCard(props.compId)) {
-            //       controls.transferCtrl.mousedown(e, "move", store.currComp);
-            //     }
-            //   }
-            // }}
             onMousemove={(e) => {
               if (
                 !store.isEditMode ||
@@ -60,6 +62,7 @@ export const View = defineComponent({
               actions.pickComp(props.compId);
             }}
           >
+            
             {slots.default?.()}
           </div>
 

+ 16 - 3
src/modules/editor/controllers/SelectCtrl/ObjsContainer.ts

@@ -223,13 +223,26 @@ export class ObjsContainer {
 
     scaleY(y:number) {
         this.parent.scale.y = y;
-
         this.parent.updateTransform();
-
-       
         this.updateCompState();
     }
 
+    // scaleSize(w:number, h:number) {
+
+    // }
+
+    scaleWidth(w:number) {
+         
+        //怎么改对应的偏移值
+        this.parent.scale.x = w / this.rect.width
+
+
+        this.rect.width = w;
+        this.selected[0].width = w;
+    }
+    // scaleHeight(w:number) {
+
+    // }
     //清除当前元素的缩放 改为类容的宽度
     applyScaleToChildSize() {
         if (this.selected.length  != 1 ) return;

+ 5 - 2
src/modules/editor/controllers/SelectCtrl/index.ts

@@ -74,7 +74,7 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
     this._selCanvaseSize.w = selCanvas.width * 2;
     this._selCanvaseSize.h = selCanvas.height * 2;
 
-    document.addEventListener("mousedown", this.onDocMouseDown.bind(this));
+    document.addEventListener("mousedown", this.onDocMouseDown.bind(this), {capture: true});
     document.addEventListener("mousemove", this.onDocMouseMove.bind(this));
     document.addEventListener("mouseup", this.onDocMouseUp.bind(this));
 
@@ -85,6 +85,9 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
   onDocMouseDown(e: MouseEvent) {
     if (!this.pageEl || !this.selCanvas) return;
 
+    if (this.store.textEditingState) {
+        return
+    }
     let box = this.pageEl.getBoundingClientRect();
     const pageX = e.clientX - box?.left;
     const pageY = e.clientY - box?.top;
@@ -301,7 +304,7 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
     let isClick = false;
     const dx = Math.abs(e.clientX - this._downClientX);
     const dy = Math.abs(e.clientY - this._downClientY);
-    if (dx < 2 && dy < 2) {
+    if (dx < 2 && dy < 2 && !this.store.textEditingState ) {
       isClick = true;
     }
     if (isClick) {

+ 3 - 1
src/modules/editor/module/actions/edit.ts

@@ -108,8 +108,10 @@ export const editActions = EditorModule.action({
   },
   // 删除组件
   removeComp(compId: string) {
+
     if (this.helper.isCompCanDelete(compId)) {
       if (compId === this.store.currCompId) {
+        this.controls.selectCtrl.selecteObjs([]);
         this.store.setCurrComp("root");
       }
       this.store.deleteComp(compId);
@@ -236,7 +238,7 @@ export const editActions = EditorModule.action({
   // 设置组件变换
   setCompTransformMatrix(comp: DesignComp, transformMatrix: string) {
     if (!comp) return;
-    
+
     comp.layout.transformMatrix = transformMatrix;
   },
 

+ 3 - 33
src/modules/editor/module/stores/index.ts

@@ -31,7 +31,7 @@ export const store = EditorModule.store({
     compMap(state) {
       return state.designData.compMap;
     },
-    
+
     currComp(state) {
       return state.designData.compMap[state.currCompId];
     },
@@ -85,39 +85,9 @@ export const store = EditorModule.store({
      
       this.store.currCompId = compId;
 
-      const find = (objs: string[], id: string): boolean => {
-        if (!objs || objs.length < 1) return false;
-
-        if (objs.includes(id)) return true;
+      const comps = this.helper.getCompTrees(compId);
 
-        let n = objs.length;
-        let f = false;
-        while (n--) {
-          f = find(
-            this.store.designData.compMap[objs[n]].children.default as any,
-            id
-          );
-          if (f) {
-            break;
-          }
-        }
-        return f;
-      };
-      const ids = this.store.streamCardIds;
-      if (ids.indexOf(compId) > -1) {
-        this.store.currStreamCardId = compId;
-      }
-      let i = ids.length;
-      while (i--) {
-        const isFind = find(
-          this.store.designData.compMap[ids[i]].children.default as any,
-          compId
-        );
-        if (isFind) {
-          this.store.currStreamCardId = ids[i];
-          break;
-        }
-      }
+      this.store.currStreamCardId = comps[1]?.id || ''
     },
 
     deleteComp(compId: string) {