Переглянути джерело

editer:feat>左侧设备与画板产生联动

YaolongHan 4 роки тому
батько
коміт
806c8042e9

+ 27 - 15
src/components/editClass/big-edit/SBaseEditScene.ts

@@ -162,7 +162,7 @@ export class SBaseEditScene extends SGraphEditScene {
         this.addItem(item);
         this.grabItem = item;
         console.log(this.grabItem);
-        
+
         item.connect("finishCreated", this, this.finishCreated);
         item.connect("onContextMenu", this, this.getItem);
         if (this.view) {
@@ -193,7 +193,7 @@ export class SBaseEditScene extends SGraphEditScene {
             /** 由应用自己定义 */
             properties: {
                 type: "BaseEquipment",
-                infoMsgList:[{
+                infoMsgList: [{
 
                 }]
             },
@@ -331,19 +331,31 @@ export class SBaseEditScene extends SGraphEditScene {
      *
      * @return 删除的图例
      */
-    deleteItem(): any {
-        if (this.selectContainer.count == 0) {
-            return []
-        }
-        let itemList = this.selectContainer.itemList;
-        // 推入 undo/redo 栈
-        this.undoStack.push(new SGraphDeleteListCommand(this, [...itemList]))
-        itemList.forEach((element: any) => {
-            this.removeItem(element)
-        });
-        if (this.view) {
-            this.view.update()
+    deleteItem(itemArr: SGraphItem[] = []): any {
+        let itemList = null;
+        if (itemArr && itemArr.length) {
+            itemList = itemArr
+            itemArr.forEach((element: any) => {
+                this.removeItem(element)
+            });
+            if (this.view) {
+                this.view.update()
+            }
+        } else {
+            if (this.selectContainer.count == 0) {
+                return []
+            }
+            itemList = this.selectContainer.itemList;
+            // 推入 undo/redo 栈
+            this.undoStack.push(new SGraphDeleteListCommand(this, [...itemList]))
+            itemList.forEach((element: any) => {
+                this.removeItem(element)
+            });
+            if (this.view) {
+                this.view.update()
+            }
         }
+
         return itemList
     } // Function deleteItem()
 
@@ -496,7 +508,7 @@ export class SBaseEditScene extends SGraphEditScene {
 
     /**
      *  添加多个item命令
-     * 
+     *
      *  @param  itemList       鼠标事件对象
      */
     addListCommand(itemList: SGraphEdit[]): void {

+ 2 - 1
src/components/editview/baseTopoEditer.vue

@@ -143,7 +143,8 @@ export default {
       // 删除
       bus.$off("deleteItem");
       bus.$on("deleteItem", (val) => {
-        this.scene.deleteItem();
+        this.scene.deleteItem([val]);
+        this.EDITEQUIPITEM()
       });
       // 复制
       bus.$off("copy");

+ 15 - 3
src/components/editview/leftToolBar/equipmentList.vue

@@ -108,10 +108,18 @@
                       </div>
                     </div>
                     <div class="icons">
-                      <Icon
+                      <Popover
                         v-show="hoverIndex == '' + index + i + b"
-                        name="more"
-                      />
+                        type="base"
+                        placement="top-center"
+                      >
+                        <template slot="content">
+                          <Button @click="deleteItem(a)" type="text" icon="edit"
+                            >删除</Button
+                          >
+                        </template>
+                        <Icon name="more" />
+                      </Popover>
                     </div>
                   </li>
                 </ul>
@@ -159,6 +167,10 @@ export default {
     ShowItem(a) {
       a.visible = !a.visible;
     },
+    // 删除Item
+    deleteItem(a) {
+      bus.$emit("deleteItem", a);
+    },
     // 获取设备图例
     getEquipItem(id) {
       const obj = {

+ 2 - 2
src/store/index.ts

@@ -52,7 +52,7 @@ export default new Vuex.Store({
     ADDEQUIPITEM(state, item): void {
       state.equipmentItemList.push(item);
       state.equipmentItemNum = state.equipmentItemList.length
-      console.log( state.equipmentItemList)
+      console.log(state.equipmentItemList)
     },
     // 删除设备实例 item
     EDITEQUIPITEM(state): void {
@@ -61,7 +61,7 @@ export default new Vuex.Store({
       if (!arr1.length) return;
 
       for (var i = 0; i < arr1.length; i++) {
-        if (arr1[i].parent) {
+        if (!arr1[i].parent) {
           arr1.splice(i, 1);
           i--;//i需要自减,否则每次删除都会讲原数组索引发生变化
         }