Forráskód Böngészése

修复锁定站点位拖拽操作 修复点击地图数据

pm 2 hónapja
szülő
commit
198fc040dd

+ 80 - 206
src/views/mes/dv/lotoStation/MapData.vue

@@ -460,7 +460,6 @@ export default {
       this.layer.draw()
     },
 
-    // 绘制柜内所有点
     // 绘制柜内所有点
     renderGrid() {
       this.selectedStates = []
@@ -563,7 +562,8 @@ export default {
 
           group.on('dragend', () => {
             const groupPos = group.getAbsolutePosition()
-            console.log(groupPos,'我在那里')
+
+            // 计算在哪个区域
             const isInRightBox =
               groupPos.x >= rightBoxBounds.x &&
               groupPos.x <= rightBoxBounds.x + rightBoxBounds.width &&
@@ -575,24 +575,12 @@ export default {
               groupPos.x <= cabinetBounds.x + cabinetBounds.width &&
               groupPos.y >= cabinetBounds.y &&
               groupPos.y <= cabinetBounds.y + cabinetBounds.height
-            let pointData = positions.find(p => p.entityName === labelText)
-            let fromRight = false
-
-            // 如果拖动的点是从右侧来的
-            if (!pointData) {
-              const rightIndex = this.rightPoints.findIndex(p => p.entityName === labelText)
-              if (rightIndex !== -1) {
-                pointData = this.rightPoints.splice(rightIndex, 1)[0]
-                fromRight = true
-              }
-            }
-            if (!pointData) return
 
             const newRow = Math.max(0, Math.min(Math.round(groupPos.x / 50), Math.floor(1200 / 50) - 1))
             const newCol = Math.max(0, Math.min(Math.round(groupPos.y / 50), Math.floor(860 / 50) - 1))
 
             const updatedPointData = {
-              ...pointData,
+              ...pos,
               row: newRow,
               col: newCol,
               x: newRow,
@@ -602,69 +590,31 @@ export default {
             }
 
             // ================== 拖拽逻辑 ==================
-            if (pos.from === 'cabinet') {
-              if (isInCabinet) {
-                this.movePoints.push(updatedPointData)
-              } else if (isInRightBox) {
-                this.unbindingPoints.push(updatedPointData)
-                if (!this.unbindPointIds.includes(updatedPointData.entityId)) {
-                  this.unbindPointIds.push(updatedPointData.entityId) // 记录解绑ID
-                }
-                this.bindingPointIds = this.bindingPointIds.filter(id => id !== updatedPointData.entityId)
-                pos.from = 'right'
-              } else {
-                this.movePoints.push(updatedPointData)
-                pos.from = 'outside'
-              }
-            } else if (pos.from === 'left') {
-              if (isInCabinet) {
-                this.bindingPoints.push(updatedPointData)
-                if (!this.bindingPointIds.includes(updatedPointData.entityId)) {
-                  this.bindingPointIds.push(updatedPointData.entityId) // 记录绑定ID
-                }
-                this.movePoints.push(updatedPointData)
-                pos.from = 'cabinet'
-              } else if (isInRightBox) {
-                this.unbindingPoints.push(updatedPointData)
-                if (!this.unbindPointIds.includes(updatedPointData.entityId)) {
-                  this.unbindPointIds.push(updatedPointData.entityId)
-                }
-                pos.from = 'right'
-              } else {
-                this.bindingPoints.push(updatedPointData)
-                if (!this.bindingPointIds.includes(updatedPointData.entityId)) {
-                  this.bindingPointIds.push(updatedPointData.entityId)
-                }
-                pos.from = 'outside'
+            if (pos.from === 'cabinet' && isInRightBox) {
+              // 左 → 右 = 解绑
+              this.unbindingPoints.push(updatedPointData)
+              if (!this.unbindPointIds.includes(updatedPointData.entityId)) {
+                this.unbindPointIds.push(updatedPointData.entityId)
               }
-            } else if (pos.from === 'right') {
-              if (isInCabinet) {
-                this.bindingPoints.push(updatedPointData)
-                if (!this.bindingPointIds.includes(updatedPointData.entityId)) {
-                  this.bindingPointIds.push(updatedPointData.entityId)
-                }
-                this.movePoints.push(updatedPointData)
-                pos.from = 'cabinet'
-              } else {
-                this.movePoints.push(updatedPointData)
-                pos.from = 'outside'
-              }
-            } else if (pos.from === 'outside') {
-              if (isInCabinet) {
-                this.bindingPoints.push(updatedPointData)
-                if (!this.bindingPointIds.includes(updatedPointData.entityId)) {
-                  this.bindingPointIds.push(updatedPointData.entityId)
-                }
-                this.movePoints.push(updatedPointData)
-                pos.from = 'cabinet'
-              } else {
-                this.movePoints.push(updatedPointData)
+              this.bindingPointIds = this.bindingPointIds.filter(id => id !== updatedPointData.entityId)
+              pos.from = 'right'
+            } else if (pos.from === 'right' && isInCabinet) {
+              // 右 → 左 = 绑定
+              this.bindingPoints.push(updatedPointData)
+              if (!this.bindingPointIds.includes(updatedPointData.entityId)) {
+                this.bindingPointIds.push(updatedPointData.entityId)
               }
+              this.movePoints.push(updatedPointData)
+              pos.from = 'cabinet'
+            } else {
+              // 其他情况 = 更新位置
+              this.movePoints.push(updatedPointData)
             }
 
             this.layer.draw()
           })
 
+
         }
       })
     },
@@ -795,79 +745,48 @@ export default {
             entityName: point.pointName
           }
 
-          // ================== 拖拽逻辑 ==================
-          if (point.from === 'left') {
-            if (isInCabinet) {
-              this.bindingPoints.push(updatedPoint)
-              this.movePoints.push(updatedPoint)
-              if (!this.bindingPointIds.includes(updatedPoint.entityId)) {
-                this.bindingPointIds.push(updatedPoint.entityId) // 记录绑定ID
-              }
-              valueArray.push(updatedPoint)
-              point.from = 'cabinet'
-            } else if (isInRightBox) {
-              this.unbindingPoints.push(updatedPoint)
-              if (!this.unbindPointIds.includes(updatedPoint.entityId)) {
-                this.unbindPointIds.push(updatedPoint.entityId) // 记录解绑ID
-              }
-              point.from = 'right'
-            } else {
-              this.bindingPoints.push(updatedPoint)
-              if (!this.bindingPointIds.includes(updatedPoint.entityId)) {
-                this.bindingPointIds.push(updatedPoint.entityId)
-              }
-              point.from = 'outside'
+          // ============== 拖拽逻辑精简版 ==============
+          if (point.from === 'cabinet' && isInRightBox) {
+            // 从柜子 → 右侧 = 解绑
+            this.unbindingPoints.push(updatedPoint)
+            if (!this.unbindPointIds.includes(updatedPoint.entityId)) {
+              this.unbindPointIds.push(updatedPoint.entityId)
             }
-          } else if (point.from === 'cabinet') {
-            if (isInCabinet) {
-              this.movePoints.push(updatedPoint)
-            } else if (isInRightBox) {
-              this.unbindingPoints.push(updatedPoint)
-              if (!this.unbindPointIds.includes(updatedPoint.entityId)) {
-                this.unbindPointIds.push(updatedPoint.entityId)
-              }
-              this.bindingPointIds = this.bindingPointIds.filter(id => id !== updatedPoint.entityId)
-              valueArray = valueArray.filter(item => item.pointId !== point.pointId)
-              point.from = 'right'
-            } else {
-              this.movePoints.push(updatedPoint)
-            }
-          } else if (point.from === 'right') {
-            if (isInCabinet) {
-              this.bindingPoints.push(updatedPoint)
-              this.movePoints.push(updatedPoint)
-              if (!this.bindingPointIds.includes(updatedPoint.entityId)) {
-                this.bindingPointIds.push(updatedPoint.entityId)
-              }
-              valueArray.push(updatedPoint)
-              point.from = 'cabinet'
-            } else {
-              this.movePoints.push(updatedPoint)
-              point.from = 'outside'
-            }
-          } else if (point.from === 'outside') {
-            if (isInCabinet) {
-              this.bindingPoints.push(updatedPoint)
-              this.movePoints.push(updatedPoint)
-              if (!this.bindingPointIds.includes(updatedPoint.entityId)) {
-                this.bindingPointIds.push(updatedPoint.entityId)
-              }
-              valueArray.push(updatedPoint)
-              point.from = 'cabinet'
-            } else {
-              this.movePoints.push(updatedPoint)
+            this.bindingPointIds = this.bindingPointIds.filter(id => id !== updatedPoint.entityId)
+            valueArray = valueArray.filter(item => item.pointId !== point.pointId)
+            point.from = 'right'
+          } else if (point.from === 'right' && isInCabinet) {
+            // 从右侧 → 柜子 = 绑定
+            this.bindingPoints.push(updatedPoint)
+            if (!this.bindingPointIds.includes(updatedPoint.entityId)) {
+              this.bindingPointIds.push(updatedPoint.entityId)
             }
+            this.movePoints = this.updateOrPush(this.movePoints, updatedPoint)
+            valueArray.push(updatedPoint)
+            point.from = 'cabinet'
+          } else {
+            // 其他情况 = 只是更新位置
+            this.movePoints = this.updateOrPush(this.movePoints, updatedPoint)
           }
 
           this.value = JSON.stringify(valueArray, null, 4)
           this.layer.draw()
         })
 
+
         this.layer.draw()
       }
     },
-
-
+    // 更新点位
+    updateOrPush(arr, point) {
+      const idx = arr.findIndex(p => p.entityId === point.entityId)
+      if (idx !== -1) {
+        arr.splice(idx, 1, point) // 更新已有
+      } else {
+        arr.push(point) // 新增
+      }
+      return arr
+    },
 
     // 从 json 删除对应的点
     removePointFromJson(point) {
@@ -952,7 +871,7 @@ export default {
         const cabinetBounds = { x: 330, y: 10, width: 500, height: 790 }
 
         this.rightPoints.forEach((point) => {
-          point.from = 'right' // 标记来源
+          point.from = 'right' // 初始来源是右侧
 
           const group = new Konva.Group({
             x: currentX,
@@ -1006,34 +925,20 @@ export default {
 
               const row = Math.floor(snappedY / gridY)
               const col = Math.floor(snappedX / gridX)
-              const y = Math.floor(snappedY / gridY)
-              const x = Math.floor(snappedX / gridX)
+
               const updatedPointData = {
+                ...point,
                 row,
                 col,
-                x,
-                y,
-                pointId: point.pointId,
-                entityId: point.entityId,
-                entityName: point.entityName,
-                pointName: point.pointName,
-                remark: point.remark,
-                prePointId: point.prePointId,
-                pointType: point.pointType,
-                pointTypeName: point.pointTypeName,
-                powerType: point.powerType,
-                powerTypeName: point.powerTypeName,
-                state: point.status,
-                pointIcon: point.pointIcon,
-                pointPicture: point.pointPicture,
-                mapImg: null,
+                x: col,
+                y: row,
                 mapId: this.mapId,
                 mapType: this.mapType
               }
 
               let valueArray = []
               try {
-                valueArray = JSON.parse(this.value)
+                valueArray = JSON.parse(this.value) || []
               } catch (e) {
                 console.error('Failed to parse value:', e)
               }
@@ -1043,67 +948,36 @@ export default {
                 snappedX <= rightBoxBounds.x + rightBoxBounds.width &&
                 snappedY >= rightBoxBounds.y &&
                 snappedY <= rightBoxBounds.y + rightBoxBounds.height
+
               const inCabinet =
                 snappedX >= cabinetBounds.x &&
                 snappedX <= cabinetBounds.x + cabinetBounds.width &&
                 snappedY >= cabinetBounds.y &&
                 snappedY <= cabinetBounds.y + cabinetBounds.height
 
-              this.bindingPoints = this.bindingPoints || []
-              this.unbindingPoints = this.unbindingPoints || []
-              this.movePoints = this.movePoints || []
-              this.bindingPointIds = this.bindingPointIds || []
-              this.unbindPointIds = this.unbindPointIds || []
-
-              if (point.from === 'cabinet') {
-                if (inCabinet) {
-                  this.movePoints.push(updatedPointData)
-                } else if (inRightBox) {
-                  this.unbindingPoints.push(updatedPointData)
-                  if (!this.unbindPointIds.includes(updatedPointData.entityId)) {
-                    this.unbindPointIds.push(updatedPointData.entityId)
-                  }
-                  this.bindingPointIds = this.bindingPointIds.filter(id => id !== updatedPointData.entityId)
-                  valueArray = valueArray.filter((item) => item.pointId !== point.pointId)
-                  point.from = 'right'
-                } else {
-                  this.movePoints.push(updatedPointData)
-                }
-              } else if (point.from === 'left') {
-                if (inCabinet) {
-                  this.bindingPoints.push(updatedPointData)
-                  this.movePoints.push(updatedPointData)
-                  if (!this.bindingPointIds.includes(updatedPointData.entityId)) {
-                    this.bindingPointIds.push(updatedPointData.entityId)
-                  }
-                  valueArray.push(updatedPointData)
-                  point.from = 'cabinet'
-                } else if (inRightBox) {
-                  this.unbindingPoints.push(updatedPointData)
-                  if (!this.unbindPointIds.includes(updatedPointData.entityId)) {
-                    this.unbindPointIds.push(updatedPointData.entityId)
-                  }
-                  point.from = 'right'
-                } else {
-                  this.bindingPoints.push(updatedPointData)
-                  if (!this.bindingPointIds.includes(updatedPointData.entityId)) {
-                    this.bindingPointIds.push(updatedPointData.entityId)
-                  }
-                  point.from = 'outside'
+              // ================== 拖拽逻辑 ==================
+              if (inCabinet) {
+                // 右侧 → 左侧(绑定)
+                this.bindingPoints.push(updatedPointData)
+                this.movePoints.push(updatedPointData)
+                if (!this.bindingPointIds.includes(updatedPointData.entityId)) {
+                  this.bindingPointIds.push(updatedPointData.entityId)
                 }
-              } else if (point.from === 'right') {
-                if (inCabinet) {
-                  this.bindingPoints.push(updatedPointData)
-                  this.movePoints.push(updatedPointData)
-                  if (!this.bindingPointIds.includes(updatedPointData.entityId)) {
-                    this.bindingPointIds.push(updatedPointData.entityId)
-                  }
-                  valueArray.push(updatedPointData)
-                  point.from = 'cabinet'
-                } else {
-                  this.movePoints.push(updatedPointData)
-                  point.from = 'outside'
+                valueArray.push(updatedPointData)
+                point.from = 'cabinet'
+              } else if (inRightBox) {
+                // 左侧 → 右侧(解绑)
+                this.unbindingPoints.push(updatedPointData)
+                if (!this.unbindPointIds.includes(updatedPointData.entityId)) {
+                  this.unbindPointIds.push(updatedPointData.entityId)
                 }
+                this.bindingPointIds = this.bindingPointIds.filter(id => id !== updatedPointData.entityId)
+                valueArray = valueArray.filter((item) => item.pointId !== point.pointId)
+                point.from = 'right'
+              } else {
+                // 其他情况(纯位置更新)
+                this.movePoints.push(updatedPointData)
+                point.from = 'outside'
               }
 
               this.value = JSON.stringify(valueArray, null, 4)

+ 13 - 22
src/views/mes/dv/switchMotor/MapData.vue

@@ -142,7 +142,7 @@ export default {
       // 创建图层
       this.layer = new Konva.Layer()
       // 绘制隔离点等其他内容
-      this.drawGrid(50, 50, '#e0e0e0') // 每个单元格50x50,浅灰色网格
+      this.drawGrid(10, 10, '#e0e0e0') // 每个单元格10x10,浅灰色网格
       // 创建物资柜底图
       const bgImage = new Image()
       const imageConfig = {
@@ -199,19 +199,6 @@ export default {
         this.layer.add(horizontalLine)
       }
 
-      // 添加网格坐标文本
-      // for (let row = 0; row < height / cellHeight; row++) {
-      //   for (let col = 0; col < width / cellWidth; col++) {
-      //     const text = new Konva.Text({
-      //       x: col * cellWidth + 5, // 调整位置以适应网格
-      //       y: row * cellHeight + 5, // 调整位置以适应网格
-      //       text: `(${col},${row})`,
-      //       fontSize: 10,
-      //       fill: 'gray',
-      //     });
-      //     this.layer.add(text);
-      //   }
-      // }
 
       this.layer.draw()
     },
@@ -235,8 +222,8 @@ export default {
       console.log(positions, 'positions')
 
       positions.forEach(pos => {
-        const x = pos.x * 50
-        const y = pos.y * 50
+        const x = pos.x * 10
+        const y = pos.y * 10
         const labelText = pos.entityName
 
         const group = new Konva.Group({
@@ -250,8 +237,8 @@ export default {
           x: 15,
           y: 15,
           radius: 15,
-          fill: 'green',
-          stroke: 'white',
+          fill: '#16af5d',
+          stroke: '#16af5d',
           strokeWidth: 2
         })
 
@@ -276,8 +263,8 @@ export default {
         group.on('dragend', () => {
           const groupPos = group.getAbsolutePosition()
 
-          const newRow = Math.max(0, Math.round(groupPos.x / 50))
-          const newCol = Math.max(0, Math.round(groupPos.y / 50))
+          const newRow = Math.max(0, Math.round(groupPos.x / 10))
+          const newCol = Math.max(0, Math.round(groupPos.y / 10))
 
           const updatedPoint = {
             ...pos,
@@ -287,16 +274,20 @@ export default {
             mapType: this.mapType
           }
 
-          // 更新 movePoints,如果存在就替换
-          const existIdx = this.movePoints.findIndex(p => p.pointId === updatedPoint.pointId)
+          // 更新 movePoints,用 entityId 作为唯一标识
+          const existIdx = this.movePoints.findIndex(p => p.entityId === updatedPoint.entityId)
           if (existIdx !== -1) {
+            // 已存在 -> 替换
             this.movePoints.splice(existIdx, 1, updatedPoint)
           } else {
+            // 不存在 -> 添加
             this.movePoints.push(updatedPoint)
           }
 
           console.log(this.movePoints, '更新后的 movePoints')
         })
+
+
       })
 
       this.layer.draw()

+ 27 - 13
src/views/mes/dv/switchMotor/index.vue

@@ -70,14 +70,14 @@
       @selection-change="handleSelectionChange"
     >
       <el-table-column type="selection" width="55" align="center" />
-
-      <el-table-column
-        label="电机名称"
-        align="center"
-        prop="motorName"
-      />
+      <el-table-column label="电机编码" align="center" prop="motorCode"/>
+      <el-table-column label="电机名称" align="center" prop="motorName"/>
       <el-table-column label="隔离点绑定" align="center" prop="pointName" />
-
+      <el-table-column label="电机类型" align="center" prop="motorType">
+        <template slot-scope="scope">
+          <dict-tag :options="dict.type.motor_type" :value="scope.row.motorType"/>
+        </template>
+      </el-table-column>
 
       <el-table-column
         label="操作"
@@ -117,15 +117,28 @@
     <!-- 添加或修改设备维修单对话框 -->
     <el-dialog :title="title" :visible.sync="open" width="450px" append-to-body>
       <el-form ref="form" :model="form" :rules="rules" label-width="120px">
+        <el-form-item label="电机编号" prop="motorCode">
+          <el-input v-model="form.motorCode" placeholder="请输入电机编号" />
+        </el-form-item>
         <el-form-item label="电机名称" prop="motorName">
           <el-input v-model="form.motorName" placeholder="请输入电机名称" />
         </el-form-item>
         <el-form-item label="隔离点绑定" prop="pointId">
-          <el-select style="width:290px" v-model="form.pointId" placeholder="隔离点绑定">
+          <el-select style="width:290px" v-model="form.pointId" placeholder="隔离点绑定" clearable>
             <el-option v-for="item in this.isolationPointOptions" :key="item.pointId" :label="item.pointName" :value="item.pointId">
             </el-option>
           </el-select>
         </el-form-item>
+        <el-form-item label="电机类型" align="center" prop="motorType" >
+          <el-select style="width:290px" v-model="form.motorType" placeholder="选择电机类型" clearable>
+            <el-option
+              v-for="dict in dict.type.motor_type"
+              :key="dict.value"
+              :label="dict.label"
+              :value="dict.value"
+            />
+          </el-select>
+        </el-form-item>
       </el-form>
       <div slot="footer" class="dialog-footer">
         <el-button v-no-more-click type="primary" @click="submitForm">确 定</el-button>
@@ -146,13 +159,11 @@ import {
 
 import Treeselect from "@riophae/vue-treeselect";
 import "@riophae/vue-treeselect/dist/vue-treeselect.css";
-import { listMarsDept } from '@/api/system/marsdept'
-import { listTechnology } from '@/api/system/machinery'
-import { listHardware } from '@/api/mes/hw/hardwareinfo'
+
 import { getIsIsolationPointPage } from '@/api/mes/spm/segregationPoint'
 export default {
   name: "lock",
-  dicts: ["hardware_status"],
+  dicts: ["hardware_status",'motor_type'],
   components: { Treeselect },
   data() {
     return {
@@ -196,7 +207,10 @@ export default {
       // 表单校验
       rules: {
         motorName: [
-          { required: true, message: "布局编码不能为空", trigger: "blur" },
+          { required: true, message: "电机名称不能为空", trigger: "blur" },
+        ],
+        motorCode:[
+          { required: true, message: "电机编码不能为空", trigger: "blur" },
         ],
         // pointId: [
         //   { required: true, message: "隔离点不能为空", trigger: "blur" },

+ 18 - 0
src/views/system/mappoint/index.vue

@@ -51,6 +51,11 @@
 
     <el-table v-loading="loading" :data="List" @selection-change="handleSelectionChange">
       <el-table-column type="selection" width="55" align="center"/>
+      <el-table-column label="地图点位编号" align="center" width="210px" prop="id">
+        <template slot-scope="scope">
+          <span>{{ scope.row.id }}</span>
+        </template>
+      </el-table-column>
       <el-table-column label="地图名称" align="center" width="210px" prop="mapName">
         <template slot-scope="scope">
           <span>{{ scope.row.mapName }}</span>
@@ -64,6 +69,7 @@
           />
         </template>
       </el-table-column>
+
       <el-table-column label="实体名称" align="center" width="210px" prop="entityName">
         <template slot-scope="scope">
           <span>{{ scope.row.entityName }}</span>
@@ -149,6 +155,12 @@
             </el-option>
           </el-select>
         </el-form-item>
+        <el-form-item v-if="form.mapType=='4'" label="实体" prop="entityId">
+          <el-select style="width: 280px" v-model="form.entityId" placeholder="实体">
+            <el-option v-for="item in this.motorOptions" :key="item.motorId" :label="item.motorName" :value="item.motorId">
+            </el-option>
+          </el-select>
+        </el-form-item>
         <el-form-item label="横坐标" prop="x">
           <el-input v-model="form.x" placeholder="请输入横坐标"/>
         </el-form-item>
@@ -214,6 +226,7 @@ import '@riophae/vue-treeselect/dist/vue-treeselect.css'
 import { listMarsDept } from '@/api/system/marsdept'
 import { getIsIsolationPointPage } from '@/api/mes/spm/segregationPoint'
 import { getToken } from '@/utils/auth'
+import { getIsMotorPage } from '@/api/mes/motor'
 
 export default {
   name: 'autoCodeRule',
@@ -253,6 +266,7 @@ export default {
       deptOptions: null,
       // 隔离点下拉
       spmOptions: null,
+      motorOptions: null,
       // 用户导入参数
       upload: {
         // 是否显示弹出层(用户导入)
@@ -338,6 +352,10 @@ export default {
         console.log(response,'隔离点数据')
         this.spmOptions = response.data.records
       })
+      getIsMotorPage(data).then(response => {
+        console.log(response,'电机点位')
+        this.motorOptions=response.data.records
+      })
     },
     /** 转换mars岗位数据结构 */
     Marsnormalizer(node) {