From 124fcd3d7827fc42e01e21682eeb9c3767311d41 Mon Sep 17 00:00:00 2001
From: gaosp <gaosp>
Date: 星期日, 10 三月 2024 19:49:59 +0800
Subject: [PATCH] 添加删除

---
 src/container/Map/Map.vue |   65 +++++++++++++++++++++++++++++---
 1 files changed, 58 insertions(+), 7 deletions(-)

diff --git a/src/container/Map/Map.vue b/src/container/Map/Map.vue
index d9e7057..da70c27 100644
--- a/src/container/Map/Map.vue
+++ b/src/container/Map/Map.vue
@@ -1,7 +1,7 @@
 <!--
  * @Date: 2024-01-05 23:47:53
  * @LastEditors: Sneed
- * @LastEditTime: 2024-03-08 09:11:52
+ * @LastEditTime: 2024-03-10 19:48:38
  * @FilePath: /belleson-frontend/Users/mache/Documents/demo/mdc/src/container/Map/Map.vue
 -->
 <template>
@@ -24,11 +24,13 @@
                 <!-- <el-button class="input" size="mini" type="primary" v-show="status !== 2" @click="createMap">鐢熸垚鍦板浘</el-button> -->
             </div>
             <div class="table" :class="$route.name === 'preview' ? 'active' : ''">
-                <div class="table-actions" :style="position" v-show="showAction && status !== 2">
+                <div class="table-actions" :style="position" v-show="showAction">
                     <div @click="merge">鍚堝苟</div>
                     <div @click="split">鎷嗗垎</div>
                     <div @click="addRow">澧炲姞琛�</div>
                     <div @click="addCol">澧炲姞鍒�</div>
+                    <div @click="delRow">鍒犻櫎琛�</div>
+                    <div @click="delCol">鍒犻櫎鍒�</div>
                     <div @click="sign(1)">杩囬亾</div>
                     <div @click="sign(2)">璁惧</div>
                     <div @click="sign(0)">绉婚櫎</div>
@@ -44,7 +46,7 @@
                                 <div class="td-div"
                                     :style="{ width: v.colspan * height - 2 + 'px', height: v.rowspan * height - 2 + 'px', overflow: 'hidden' }">
                                     <img @click="addDevice($event, v)" @mousedown="e => e.stopPropagation()"
-                                        v-if="v.type === 2 && status !== 2 && !v.id" src="./img/+.png" alt="娣诲姞鏈哄簥"
+                                        v-if="v.type === 2 && !v.id" src="./img/+.png" alt="娣诲姞鏈哄簥"
                                         title="娣诲姞鏈哄簥">
                                     <Device v-if="v.id" :id="v.id" style="width: 100%;height: 100%;"
                                         :deviceList="deviceList" :plantDeviceList="plantDeviceList" ::info="info"></Device>
@@ -246,7 +248,7 @@
     mounted() {
         this.$el.querySelector('table').addEventListener('contextmenu', this.contextmenu)
         this.$el.addEventListener('mouseup', e => {
-            if (this.status === 2) return
+            // if (this.status === 2) return
             this.tdMounseDown = false
         })
         try {
@@ -271,6 +273,53 @@
         }
     },
     methods: {
+        delRow ()  {
+            console.log(this.selection,this.select,this.map)
+            if (this.selection.length  == 1 && this.selection[0].rowspan ==1 && this.selection[0].colspan == 1) {
+                let rowIndex = this.selection[0].rowIndex
+                let flag = this.map[rowIndex].some(v => v.rowspan != 1 || v.colspan != 1)
+                if (flag) {
+                    this.$message({
+                        type: 'error',
+                        message: '鏈夊悎骞惰涓嶅彲鍒犻櫎'
+                    });
+                } else {
+                    this.map.splice(rowIndex,1)
+                    this.map.forEach((v,i) =>  {
+                        if (i>=rowIndex) {
+                            v.forEach((c,j) => {
+                                c.rowIndex -= 1
+                            })
+                        }
+                    })
+                    this.showAction = false
+                }
+            }
+        },
+        delCol ()  {
+            if (this.selection.length  == 1 && this.selection[0].rowspan ==1 && this.selection[0].colspan == 1) {
+                let colIndex = this.selection[0].colIndex
+                let flag = this.map.some(v => v[colIndex].rowspan != 1 || v[colIndex].colspan != 1)
+                if (flag) {
+                    this.$message({
+                        type: 'error',
+                        message: '鏈夊悎骞惰涓嶅彲鍒犻櫎'
+                    });
+                } else {
+                    this.map.forEach(v=>{
+                        v.splice(colIndex,1)
+                    })
+                    this.map.forEach((v,i) =>  {
+                        v.forEach((c,j) => {
+                            if (j >= colIndex) {
+                                c.colIndex -= 1
+                            }
+                        })
+                    })
+                    this.showAction = false
+                }
+            }
+        },
         back() {
             this.$router.push({
                 name: 'mapList'
@@ -346,7 +395,7 @@
         },
         contextmenu(e) {
             console.log(e)
-            if (this.status === 2) return
+            // if (this.status === 2) return
             if (this.range.x === undefined) return
             // if (this.range.x !=='') return 
             e.preventDefault()
@@ -365,7 +414,9 @@
                     top: top + 10 + 'px'
                 }
             }
-
+            if (window.innerHeight - top < 300) {
+                this.position.top = window.innerHeight -  300 + 'px'
+            }
         },
         onMousedown(e, v) {
             console.log('-----', v)
@@ -375,7 +426,7 @@
             this.selection = [v]
         },
         onMouseMove(e, v) {
-            if (this.status === 2) return
+            // if (this.status === 2) return
             if (!this.tdMounseDown) return
             this.$set(this.selection, 1, v)
         },

--
Gitblit v1.9.3