瀏覽代碼

新增作业票的左边隔离点交互

pm 1 年之前
父節點
當前提交
ad9dcf8724

+ 1 - 0
package.json

@@ -51,6 +51,7 @@
     "js-beautify": "1.13.0",
     "js-cookie": "3.0.1",
     "jsencrypt": "3.0.0-rc.1",
+    "konva": "^9.3.15",
     "nprogress": "0.2.0",
     "quill": "1.3.7",
     "screenfull": "5.0.2",

二進制
src/assets/images/localSetIcon.jpg


二進制
src/assets/images/localSetSelect.jpg


二進制
src/assets/images/table.png


+ 14 - 5
src/views/mes/job/jobm/NewOperations.vue

@@ -1,8 +1,11 @@
 <template>
   <div class="newOperations">
     <!--    newOperations盒子开始-->
-      <div class="left">
-        <h1>我是左边</h1>
+      <div class="left" >
+<!--        左边第一个是隔离点组件-->
+<!--        第二个是车间组件-->
+        <SeparationPoint v-if="activeName=='second'"></SeparationPoint>
+        <WorkShop v-if="activeName=='first'"></WorkShop>
       </div>
       <div class="right">
         <div class="right_top">
@@ -184,7 +187,6 @@
           <el-card class="box-card1">
             <div slot="header" class="clearfix">
               <span style="font-size: 18px">已选隔离点</span>
-
             </div>
             <div v-for="o in 4" :key="o" class="text item">
               {{'列表内容 ' + o }}
@@ -199,8 +201,14 @@
 
 
 <script>
+import SeparationPoint from '@/views/mes/job/jobm/SeparationPoint.vue'
+import WorkShop from '@/views/mes/job/jobm/WorkShop.vue'
 export default {
   name: 'addView',
+  components:{
+    SeparationPoint,
+    WorkShop
+  },
   data(){
     return {
       activeName: 'first',
@@ -218,6 +226,7 @@ export default {
         startTime:'',//开始时间
         endTime:'',//结束时间
       },
+      hardwareTypeOption:null,
       pickerOptions: {
         shortcuts: [{
           text: '今天',
@@ -265,7 +274,7 @@ export default {
   display: flex;
   .left{
     width: 75%;
-    height: 770px;
+    height: 800px;
     background: #eee;
     margin-right: 10px;
   }
@@ -304,7 +313,7 @@ export default {
 }
 .box-card1 {
   width: 390px;
-  height: 280px;
+  height: 310px;
 }
 //右侧卡片样式结束
 </style>

+ 170 - 0
src/views/mes/job/jobm/SeparationPoint.vue

@@ -0,0 +1,170 @@
+<template>
+  <div id="container" ref="container"></div>
+</template>
+
+<script>
+import Konva from 'konva'
+
+export default {
+  name: 'KonvaExample',
+  data() {
+    return {
+      stage: null,
+      layer: null,
+      isSelected:true,//判断是否选中隔离点
+      selectedStates: {} // 存储每个图片的选中状态
+    }
+  },
+  mounted() {
+    this.initKonva()
+  },
+  methods: {
+    initKonva() {
+      // 创建舞台
+      this.stage = new Konva.Stage({
+        container: this.$refs.container, // 容器元素
+        width: 1250,
+        height: 770,
+        fill: 'black'
+      })
+
+      // 创建图层
+      this.layer = new Konva.Layer()
+
+      // 创建底图
+      const bgImage = new Image()
+      bgImage.src = require('@/assets/images/table.png')
+      bgImage.onload = () => {
+        const KnovaImage = new Konva.Image({
+          x: 350,
+          y: 10,
+          image: bgImage,
+          width: 500,
+          height: 770,
+          draggable: false
+        })
+        this.layer.add(KnovaImage)
+
+        this.layer.draw()
+      }
+    // 调用函数
+      const imageSrc = require('@/assets/images/localSetIcon.jpg'); // 图片路径
+
+      this.renderGrid( imageSrc, 6, 3, 450, 100, 120, 100, 50, 50, 60, 25);
+      // 将图层添加到舞台
+      this.stage.add(this.layer)
+      this.layer.draw()
+
+      // 添加鼠标滚轮缩放功能
+      this.stage.on('wheel', (e) => {
+        e.evt.preventDefault()
+
+        const scaleBy = 1.05 // 缩放因子
+        const oldScale = this.stage.scaleX() // 获取当前缩放比例
+        const pointer = this.stage.getPointerPosition() // 获取鼠标位置
+
+        const mousePointTo = {
+          x: (pointer.x - this.stage.x()) / oldScale,
+          y: (pointer.y - this.stage.y()) / oldScale
+        }
+
+        // 根据滚轮滚动的方向决定缩放
+        const newScale = e.evt.deltaY > 0 ? oldScale / scaleBy : oldScale * scaleBy
+
+        this.stage.scale({ x: newScale, y: newScale })
+
+        const newPos = {
+          x: pointer.x - mousePointTo.x * newScale,
+          y: pointer.y - mousePointTo.y * newScale
+        }
+        this.stage.position(newPos)
+        this.stage.batchDraw()
+      })
+
+      this.stage.on('mousedown', function() {
+        this.stage.container().style.cursor = 'move'
+      }.bind(this))
+
+      this.stage.on('mouseup', function() {
+        this.stage.container().style.cursor = 'default'
+      }.bind(this))
+      this.stage.draggable(true)
+    },
+    renderGrid( imageSrc, rows, cols, startX, startY, xOffset, yOffset, imageWidth, imageHeight, rectWidth, rectHeight) {
+      for (let row = 0; row < rows; row++) {
+        for (let col = 0; col < cols; col++) {
+          const x = startX + col * xOffset // 每个图片的 x 轴位置
+          const y = startY + row * yOffset // 每个图片的 y 轴位置
+          const index = row * cols + col + 1 // 唯一标识的编号
+
+          const point = new Image()
+          point.src = imageSrc
+          point.onload = () => {
+            // 创建图片
+            const knovaImage = new Konva.Image({
+              x: x,
+              y: y,
+              image: point,
+              width: imageWidth,
+              height: imageHeight,
+              draggable: false
+            })
+            // 状态变量用于追踪当前图片
+            // 点击事件
+            knovaImage.on('click', () => {
+
+              console.log(this.isSelected,'isSelected')
+              if (this.isSelected) {
+                point.src = require('@/assets/images/localSetSelect.jpg'); // 替换成选中的图片
+              } else {
+                point.src = imageSrc; // 恢复成原来的图片
+              }
+              this.isSelected = !this.isSelected; // 切换状态
+              knovaImage.image(point); // 更新图片
+              this.layer.draw(); // 重绘图层
+            });
+            this.layer.add(knovaImage)
+
+            // 创建矩形框
+            const rect = new Konva.Rect({
+              x: x - 3,
+              y: y + imageHeight + 10, // 矩形在图片下方
+              width: rectWidth,
+              height: rectHeight,
+              cornerRadius: 10,
+              stroke: 'red',
+              strokeWidth: 2,
+              fill: 'white'
+            })
+            this.layer.add(rect)
+
+            // 创建文本
+            const text = new Konva.Text({
+              x: x + 12, // 调整文本在矩形内的位置
+              y: y + imageHeight + 15, // 在矩形内部居中显示
+              fontSize: 20,
+              text: `E-${index}`,
+              fontFamily: 'Calibri',
+              fill: 'red'
+            })
+            this.layer.add(text)
+
+            // 渲染图层
+            this.layer.draw()
+          }
+        }
+      }
+    }
+
+    //     methods结束
+  }
+
+}
+</script>
+
+<style scoped lang="scss">
+#container {
+  width: 100%;
+  height: 100%;
+}
+</style>

+ 15 - 0
src/views/mes/job/jobm/WorkShop.vue

@@ -0,0 +1,15 @@
+<template>
+
+</template>
+
+<script>
+import Konva from 'konva';
+export default {
+  name: 'workshop'
+}
+</script>
+
+
+<style scoped lang="scss">
+
+</style>