Browse Source

修复人员批量上传chekbox

pm 9 tháng trước cách đây
mục cha
commit
5e235a5d30

+ 155 - 45
src/views/mes/hw/lotoStation/MapData.vue

@@ -389,7 +389,19 @@ export default {
 
 
         let currentX = boxX + padding
         let currentX = boxX + padding
         let currentY = boxY + padding
         let currentY = boxY + padding
-
+        // 定义区域的范围
+        const leftBoxBounds = {
+          x: 50,
+          y: 15,
+          width: 200,
+          height: 800,
+        };
+        const cabinetBounds = {
+          x: 330,
+          y: 10,
+          width: 500,
+          height: 790,
+        };
         this.leftPoints.forEach((point, index) => {
         this.leftPoints.forEach((point, index) => {
           // 创建一个组来组合红色边框、图片和文字
           // 创建一个组来组合红色边框、图片和文字
           const group = new Konva.Group({
           const group = new Konva.Group({
@@ -473,23 +485,55 @@ export default {
                 mapImg: null
                 mapImg: null
               }
               }
 
 
-              // 将字符串转换为数组
-              let valueArray = []
-              try {
-                valueArray = JSON.parse(this.value)
-              } catch (e) {
-                console.error('Failed to parse value:', e)
+              // 判断拖拽目标区域
+              if (
+                snappedX >= leftBoxBounds.x &&
+                snappedX <= leftBoxBounds.x + leftBoxBounds.width &&
+                snappedY >= leftBoxBounds.y &&
+                snappedY <= leftBoxBounds.y + leftBoxBounds.height
+              ) {
+                console.log('进入右侧盒子区域');
+                // 从 JSON 中移除点
+                let valueArray = [];
+                try {
+                  valueArray = JSON.parse(this.value);
+                } catch (e) {
+                  console.error('Failed to parse value:', e);
+                }
+                this.value = JSON.stringify(
+                  valueArray.filter((item) => item.pointId !== point.pointId),
+                  null,
+                  4
+                );
+
+                // 添加到右侧盒子数据
+                this.leftPoints.push(pointData);
+              } else if (
+                snappedX >= cabinetBounds.x &&
+                snappedX <= cabinetBounds.x + cabinetBounds.width &&
+                snappedY >= cabinetBounds.y &&
+                snappedY <= cabinetBounds.y + cabinetBounds.height
+              ) {
+                console.log('进入物资柜区域');
+                // 添加到 JSON 数据
+                let valueArray = [];
+                try {
+                  valueArray = JSON.parse(this.value);
+                } catch (e) {
+                  console.error('Failed to parse value:', e);
+                }
+                valueArray.push(pointData);
+                this.value = JSON.stringify(valueArray, null, 4);
+
+                // 从右侧盒子移除点
+                this.leftPoints = this.leftPoints.filter(
+                  (item) => item.pointId !== point.pointId
+                );
+              } else {
+                console.log('未进入目标区域,保持原状态');
               }
               }
-              // 添加新数据到数组
-              valueArray.push(pointData)
-              console.log(valueArray)
-              // 将数组转换回字符串
-              this.value = JSON.stringify(valueArray, null, 4)
-
-              // 重新绘制图层
-              this.layer.draw()
-            })
-
+              this.layer.draw();
+            });
             // 重新绘制图层
             // 重新绘制图层
             this.layer.draw()
             this.layer.draw()
           }
           }
@@ -516,7 +560,18 @@ export default {
 
 
         let currentX = boxX + padding
         let currentX = boxX + padding
         let currentY = boxY + padding
         let currentY = boxY + padding
-
+        const rightBoxBounds = {
+          x: 990,
+          y: 15,
+          width: 200,
+          height: 800,
+        };
+        const cabinetBounds = {
+          x: 330,
+          y: 10,
+          width: 500,
+          height: 790,
+        };
         this.rightPoints.forEach((point, index) => {
         this.rightPoints.forEach((point, index) => {
           // 创建一个组来组合红色边框、图片和文字
           // 创建一个组来组合红色边框、图片和文字
           const group = new Konva.Group({
           const group = new Konva.Group({
@@ -600,19 +655,54 @@ export default {
                 mapImg: null
                 mapImg: null
               }
               }
 
 
-              // 将字符串转换为数组
-              let valueArray = []
-              try {
-                valueArray = JSON.parse(this.value)
-              } catch (e) {
-                console.error('Failed to parse value:', e)
+              // 判断拖拽目标区域
+              if (
+                snappedX >= rightBoxBounds.x &&
+                snappedX <= rightBoxBounds.x + rightBoxBounds.width &&
+                snappedY >= rightBoxBounds.y &&
+                snappedY <= rightBoxBounds.y + rightBoxBounds.height
+              ) {
+                console.log('进入右侧盒子区域');
+                // 从 JSON 中移除点
+                let valueArray = [];
+                try {
+                  valueArray = JSON.parse(this.value);
+                } catch (e) {
+                  console.error('Failed to parse value:', e);
+                }
+                this.value = JSON.stringify(
+                  valueArray.filter((item) => item.pointId !== point.pointId),
+                  null,
+                  4
+                );
+
+                // 添加到右侧盒子数据
+                this.rightPoints.push(pointData);
+
+              } else if (
+                snappedX >= cabinetBounds.x &&
+                snappedX <= cabinetBounds.x + cabinetBounds.width &&
+                snappedY >= cabinetBounds.y &&
+                snappedY <= cabinetBounds.y + cabinetBounds.height
+              ) {
+                console.log('进入物资柜区域');
+                // 添加到 JSON 数据
+                let valueArray = [];
+                try {
+                  valueArray = JSON.parse(this.value);
+                } catch (e) {
+                  console.error('Failed to parse value:', e);
+                }
+                valueArray.push(pointData);
+                this.value = JSON.stringify(valueArray, null, 4);
+
+                // 从右侧盒子移除点
+                this.rightPoints = this.rightPoints.filter(
+                  (item) => item.pointId !== point.pointId
+                );
+              } else {
+                console.log('未进入目标区域,保持原状态');
               }
               }
-              // 添加新数据到数组
-              valueArray.push(pointData)
-              console.log(valueArray)
-              // 将数组转换回字符串
-              this.value = JSON.stringify(valueArray, null, 4)
-
               // 重新绘制图层
               // 重新绘制图层
               this.layer.draw()
               this.layer.draw()
             })
             })
@@ -722,12 +812,14 @@ export default {
             width: 500, // 物资柜的宽度
             width: 500, // 物资柜的宽度
             height: 790 // 物资柜的高度
             height: 790 // 物资柜的高度
           }
           }
-          const allPoints = {
+          const leftBoxBounds = {
             x: 50, // 左侧列表的 x 坐标
             x: 50, // 左侧列表的 x 坐标
             y: 15,  // 左侧列表的 y 坐标
             y: 15,  // 左侧列表的 y 坐标
             width: 200,
             width: 200,
             height: 800,
             height: 800,
           }
           }
+          // 定义是否已经在物资柜中的状态
+    
           group.on('dragend', () => {
           group.on('dragend', () => {
             // 获取拖拽的内容对应的点名称
             // 获取拖拽的内容对应的点名称
             const labelText = group.findOne('Text').text()
             const labelText = group.findOne('Text').text()
@@ -742,12 +834,6 @@ export default {
               groupPos.y >= cabinetBounds.y &&
               groupPos.y >= cabinetBounds.y &&
               groupPos.y <= cabinetBounds.y + cabinetBounds.height
               groupPos.y <= cabinetBounds.y + cabinetBounds.height
 
 
-            // 如果仍在物资柜中,则不做任何操作
-            if (isInCabinet) {
-              console.log(`${labelText} 点仍在物资柜中`)
-              return
-            }
-
             // 检查是否在右侧盒子范围内
             // 检查是否在右侧盒子范围内
             const isInRightBox =
             const isInRightBox =
               groupPos.x >= rightBoxBounds.x &&
               groupPos.x >= rightBoxBounds.x &&
@@ -757,10 +843,10 @@ export default {
 
 
             // 检查是否在左侧所有点的区域内
             // 检查是否在左侧所有点的区域内
             const isInLeftBox =
             const isInLeftBox =
-              groupPos.x >= allPoints.x &&
-              groupPos.x <= allPoints.x + allPoints.width &&
-              groupPos.y >= allPoints.y &&
-              groupPos.y <= allPoints.y + allPoints.height
+              groupPos.x >= leftBoxBounds.x &&
+              groupPos.x <= leftBoxBounds.x + leftBoxBounds.width &&
+              groupPos.y >= leftBoxBounds.y &&
+              groupPos.y <= leftBoxBounds.y + leftBoxBounds.height
 
 
             // 查找并删除对应的点数据
             // 查找并删除对应的点数据
             const indexToRemove = positions.findIndex(item => item.pointName === labelText)
             const indexToRemove = positions.findIndex(item => item.pointName === labelText)
@@ -779,14 +865,38 @@ export default {
                   if (!this.leftPoints.find(point => point.pointName === movedPoint.pointName)) {
                   if (!this.leftPoints.find(point => point.pointName === movedPoint.pointName)) {
                     this.leftPoints.push(movedPoint)
                     this.leftPoints.push(movedPoint)
                   }
                   }
+                } else if (isInCabinet) {
+                  // 如果仍然在物资柜中,什么都不做,避免更新 this.value
+                  console.log('点仍在物资柜内,保持原状态')
+                  return
+                } else {
+                  // 如果不在任何区域内,可以选择将其移除或保留
+                  console.warn('Point moved to an undefined area:', movedPoint)
                 }
                 }
               }
               }
             } else {
             } else {
-              console.warn('Drag operation failed: Point not found in positions array.')
+              // 如果点不在 positions 中,可能是从右侧或左侧列表移动回来
+              const rightIndex = this.rightPoints.findIndex(item => item.pointName === labelText)
+              const leftIndex = this.leftPoints.findIndex(item => item.pointName === labelText)
+
+              if (rightIndex !== -1) {
+                // 从右侧列表移回物资柜
+                const movedPoint = this.rightPoints.splice(rightIndex, 1)[0]
+                positions.push(movedPoint)
+              } else if (leftIndex !== -1) {
+                // 从左侧列表移回物资柜
+                const movedPoint = this.leftPoints.splice(leftIndex, 1)[0]
+                positions.push(movedPoint)
+              } else {
+                // console.warn('Drag operation failed: Point not found in any array.')
+              }
             }
             }
 
 
-            // 更新 this.value
-            this.value = JSON.stringify(positions, null, 4)
+            // 更新 this.value,只有当数据发生变化时才更新
+            console.log(isInCabinet,'isInCabinet位置')
+            if (!isInCabinet) {
+              this.value = JSON.stringify(positions, null, 4)
+            }
 
 
             // 清理 undefined 数据
             // 清理 undefined 数据
             this.rightPoints = this.rightPoints.filter(Boolean)
             this.rightPoints = this.rightPoints.filter(Boolean)
@@ -801,7 +911,7 @@ export default {
           this.layer.draw()
           this.layer.draw()
         }
         }
       })
       })
-    }
+    },
 
 
   }
   }
 }
 }

+ 3 - 3
src/views/system/user/index.vue

@@ -377,9 +377,9 @@
         <i class="el-icon-upload"></i>
         <i class="el-icon-upload"></i>
         <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
         <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
         <div class="el-upload__tip text-center" slot="tip">
         <div class="el-upload__tip text-center" slot="tip">
-          <div class="el-upload__tip" slot="tip">
-            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据
-          </div>
+<!--          <div class="el-upload__tip" slot="tip">-->
+<!--            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据-->
+<!--          </div>-->
           <span>仅允许导入xls、xlsx格式文件。</span>
           <span>仅允许导入xls、xlsx格式文件。</span>
           <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
           <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
         </div>
         </div>