Explorar o código

fix: 修复多选组件后无法取消的情况

wu.jian2 hai 1 ano
pai
achega
e9819c895b

+ 14 - 1
data-room-ui/packages/BigScreenDesign/MouseSelect/index.vue

@@ -120,7 +120,7 @@ export default {
         // this.changeActiveCodes([])
         // this.changeActiveCode('')
       }
-
+      // 鼠标按下,并开始选择
       if (event.button === 0 && this.isSelecting) {
         this.isSelecting = false
         if (newTime - time < 300) {
@@ -142,6 +142,19 @@ export default {
         this.startY = 0
         this.endX = 0
         this.endY = 0
+      } else if (!this.shiftKeyDown && !this.isSelecting) {
+        // 重置起始点和结束点的坐标
+        this.startX = 0
+        this.startY = 0
+        this.endX = 0
+        this.endY = 0
+        this.$emit('selectArea', {
+          startX: Math.min(this.startX, this.endX),
+          startY: Math.min(this.startY, this.endY),
+          endX: Math.max(this.startX, this.endX),
+          endY: Math.max(this.startY, this.endY)
+        })
+        this.changeActiveCodes([])
       }
     },
     handleMouseLeave () {

+ 18 - 7
data-room-ui/packages/js/store/mutations.js

@@ -37,13 +37,24 @@ export default {
     state.activeItemConfig = _.cloneDeep(activeItem)
   },
   changeActiveCodes (state, codes) {
-    state.activeCodes = codes
-    state.pageInfo.chartList = state.pageInfo.chartList?.map(chart => {
-      return {
-        ...chart,
-        group: (codes.includes(chart.code) && !chart.group) ? 'tempGroup' : chart.group
-      }
-    })
+    // 传入codes,将codes中的组件的group改为tempGroup,不传入或者传入空数组,将所有组件的group改为'',即取消组合
+    if (codes.length !== 0) {
+      state.activeCodes = codes
+      state.pageInfo.chartList = state.pageInfo.chartList?.map(chart => {
+        return {
+          ...chart,
+          group: (codes.includes(chart.code) && !chart.group) ? 'tempGroup' : chart.group
+        }
+      })
+    } else {
+      state.activeCodes = codes
+      state.pageInfo.chartList = state.pageInfo.chartList?.map(chart => {
+        return {
+          ...chart,
+          group: ''
+        }
+      })
+    }
   },
   // 改变当前hover组件id
   changeHoverCode (state, code) {