Browse Source

修复删除的bug

liwei 1 year ago
parent
commit
642314c983

+ 9 - 8
src/modules/editor/components/Viewport/Slider/SliderRight/CompTree.tsx

@@ -20,10 +20,12 @@ export const CompTree = defineComponent({
   setup() {
     const { store, actions, helper, controls } = useEditor();
     const { compUICtrl } = controls;
+
     const state = useReactive(() => ({
       expandedKeys: [] as string[],
       treeData() {
         const rootComp = helper.findRootComp();
+      
         function getCompChildren(ids: string[]): TreeItem[] {
           return ids.map((id) => {
             const comp = helper.findComp(id) as DesignComp;
@@ -42,16 +44,15 @@ export const CompTree = defineComponent({
       },
     }));
 
-    effect(() => {
-      state.expandedKeys = helper
-        .getCompTrees(store.currCompId)
-        .map((comp) => comp.id);
-    });
+   
+
+    return () => {
 
-    return () => (
+      state.expandedKeys = store.currCompId  ? helper.getCompTrees(store.currCompId).map((comp) => comp.id):[];
+      return (
       <Tree
         class={treeStyle}
-        treeData={state.treeData}
+        treeData={ state.treeData}
         v-model={[state.expandedKeys, "expandedKeys"]}
         selectedKeys={[store.currCompId]}
         blockNode={true}
@@ -71,7 +72,7 @@ export const CompTree = defineComponent({
         }}
       </Tree>
     );
-  },
+  }},
 });
 
 const CompNode = defineComponent({

+ 1 - 1
src/modules/editor/controllers/SelectCtrl/index.ts

@@ -361,7 +361,7 @@ export class SelectCtrl extends ModuleControl<EditorModule> {
       this._selCanvaseSize.w,
       this._selCanvaseSize.h
     );
-
+    this.mouseDownSelects = [];
     this.upgateGizmoStyle();
   }
 

+ 10 - 6
src/modules/editor/module/actions/edit.ts

@@ -27,7 +27,7 @@ export const editActions = EditorModule.action({
     //点击默认都创建一个容器
     //创建容器
     const isCreatCard =  compKey != "Text" && compKey != "Image" && compKey != "Video" && compKey != "Web3D";
-    
+
     let yOffset = 0;
     if (this.store.currCompId != this.store.currStreamCardId && !isCreatCard) {
         const bound = this.helper.getCardCompBound(this.store.currCompId);
@@ -126,10 +126,10 @@ export const editActions = EditorModule.action({
   removeComp(compId: string) {
 
     if (this.helper.isCompCanDelete(compId)) {
-      if (compId === this.store.currCompId) {
-        this.controls.selectCtrl.selecteObjs([]);
+      if (compId === this.store.currCompId) { 
         this.store.setCurrComp("root");
       }
+      this.controls.selectCtrl.selecteObjs([]);
       this.store.deleteComp(compId);
     }
   },
@@ -137,9 +137,10 @@ export const editActions = EditorModule.action({
   async removeStreamCard(compId: string) {
     await queenApi.showConfirm({ title: "删除", content: "确认删除当前内容?" });
 
-    if (this.store.streamCardIds.length < 2) {
-      return;
-    }
+    // if (this.store.streamCardIds.length < 2) {
+    //   queenApi.messageError("")
+    //   return;
+    // }
     let nextCard = this.store.currStreamCardId;
     if (compId == this.store.currStreamCardId) {
       const i = this.store.streamCardIds.indexOf(compId);
@@ -148,7 +149,10 @@ export const editActions = EditorModule.action({
         nextCard = this.store.streamCardIds[i - 1];
       }
     }
+    this.controls.selectCtrl.selecteObjs([])
+
     this.store.deleteComp(compId);
+    
     this.store.setCurrComp(nextCard);
   },
   // 移动组件顺序

+ 0 - 4
src/modules/editor/module/stores/index.ts

@@ -79,10 +79,6 @@ export const store = EditorModule.store({
       return compId;
     },
     setCurrComp(compId: string) {
-      if (compId != "root") {
-        this.store.currStreamCardId = "";
-      }
-     
       this.store.currCompId = compId;
 
       const comps = this.helper.getCompTrees(compId);