严智鑫
2024-12-03 def1eb8623e1444164ae4bce9179d011a89b8c5e
UI-Project/src/views/MechanicalArm/mechanicalArm.vue
@@ -1,10 +1,10 @@
<!--  打标机  -->
<!--  上片机  -->
<script setup>
import request from "@/utils/request";
import { ElMessage, ElMessageBox } from "element-plus";
import { reactive, ref, onMounted, onBeforeUnmount,onUnmounted } from 'vue'
import { computed,reactive, ref, onMounted, onBeforeUnmount, onUnmounted } from 'vue'
import { useI18n } from 'vue-i18n'
import { WebSocketHost ,host} from '@/utils/constants'
import { WebSocketHost, host } from '@/utils/constants'
import { initializeWebSocket, closeWebSocket } from '@/utils/WebSocketService';
let language = ref(localStorage.getItem('lang') || 'zh')
const { t } = useI18n()
@@ -12,22 +12,41 @@
  account: '',
  password: '',
});
const blind = ref(false)
const errorInfo = ref(true)
const loadData = ref([]);
const findMachine = ref([]);
const machineId=1;//当前页面的设备ID
const sendRecords = ref([]);
const downLineTask = ref([]);
const findPrimitiveTask = ref([]);
const scanCodeOld = ref([]);
const searchs = ref();
const machineId = 2;//当前页面的设备ID
var errorScanId;
//使用WebSocket方式展示数据
let socket = null;
const socketUrl = `ws://${WebSocketHost}:${host}/api/deviceInteraction/api/talk/mechanicalArm`;
let socketDownLineTask = null;
const socketUrl = `ws://${WebSocketHost}:${host}/api/deviceInteraction/api/talk/loadTask`;
const socketDownLineTaskUrl = `ws://${WebSocketHost}:${host}/api/deviceInteraction/api/talk/downLineTask`;
// 定义消息处理函数,更新 receivedData 变量
const handleMessage = (data) => {
  // 更新 tableData 的数据
  loadData.value = data.taskingList[0];
  loadData.value = data.findPrimitiveTasking[0];
  findPrimitiveTask.value = data.findPrimitiveTask[0];
  findMachine.value = data.machine[0];
  sendRecords.value = data.sendRecords[0].reverse();
};
// 定义消息处理函数,更新 receivedData 变量
const handleMessage2 = (data) => {
  downLineTask.value = data.downLineTask[0];
  // console.log(data);
};
onUnmounted(() => {
  if (socket) {
    closeWebSocket(socket);
  }
  if (socketDownLineTask) {
    closeWebSocket(socketDownLineTask);
  }
});
onBeforeUnmount(() => {
@@ -38,257 +57,362 @@
onMounted(async () => {
  //使用WebSocket方式展示数据
  socket = initializeWebSocket(socketUrl, handleMessage);// 初始化 WebSocket,并传递消息处理函数
  //使用接口方式展示数据
  //load();
  //使用WebSocket方式展示数据
  socketDownLineTask = initializeWebSocket(socketDownLineTaskUrl, handleMessage2);// 初始化 WebSocket,并传递消息处理函数
});
// //获取数据
// const load = async() => {
//   //获取设备任务数据
//   try {
//     const response = await request.post('/deviceInteraction/tasking/findMachineTask',
//     {
//       "id": 11
//     }); // 替换为你的API端点
//     if (response.code === 200) {
//       loadData.value.findTaskingData= response.data;
//     } else {
//       ElMessage.warning(res.msg)
//     }
//   } catch (error) {
//     // console.error('Error fetching rects :', error);
//   }
//   //获取设备状态
//   try {
//     const response = await request.post('/deviceInteraction/machine/findMachine',
//     {
//       "id": 11
//     }); // 替换为你的API端点
//     if (response.code === 200) {
//       findMachine.value= response.data;
//     } else {
//       ElMessage.warning(res.msg)
//     }
//   } catch (error) {
//     // console.error('Error fetching rects :', error);
//   }
// }
//报警提示
const errorInfoFuntion = async (info) => {
  let infoScancode='扫码ID:'+info.scanId+'  '+info.scanCode;
  ElMessageBox.confirm(
    infoScancode,
    t('delivery.prompt'),
    {
      confirmButtonText: t('functionState.sureStart'),
      cancelButtonText: t('functionState.cancel'),
      type: 'warning',
    }
  )
    .then(() => {
      //重新补单
      request.post("/deviceInteraction/tasking/glassAgainTopLine",
        {
          "scanId": info.scanId,
        }).then((res) => { // 替换为你的API端点
          if (res.code === 200) {
            ElMessage.success(res.message);
          } else {
            ElMessage.warning(res.message)
          }
        })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: t('functionState.cancel'),
      })
    })
}
//修改工作状态 【失败/正在工作/完工】
const workStatus = async(row,state) => {
const workStatus = async (row, state) => {
  let url;
  if(state=="重发"){
    url="/deviceInteraction/tasking/loseMachineTask";
  }else if(state=="正在工作"){
    url="/deviceInteraction/tasking/startMachineTask";
  }else if(state=="完工"){
    url="/deviceInteraction/tasking/finishMachineTask";
  }else{
  if (state == "重发") {
    url = "/deviceInteraction/tasking/loseMachineTask";
  } else if (state == "正在工作") {
    url = "/deviceInteraction/tasking/startMachineTask";
  } else if (state == "完工") {
    url = "/deviceInteraction/tasking/finishMachineTask";
  } else {
    return;
  }
  ElMessageBox.confirm(
        t('functionState.tips'),
        t('delivery.prompt'),
    t('functionState.tips'),
    t('delivery.prompt'),
    {
      confirmButtonText: t('functionState.sure'),
      cancelButtonText: t('functionState.cancel'),
      type: 'warning',
    }
  )
    .then(() => {
      //开始修改
      request.post(url,
        {
          confirmButtonText: t('functionState.sure'),
          cancelButtonText: t('functionState.cancel'),
          type: 'warning',
        }
      )
        .then(() => {
          //开始修改
          request.post(url,
            {
              "id": machineId
            }).then((res) => { // 替换为你的API端点
              if (res.code === 200) {
                ElMessage.success(res.message);
              } else {
                ElMessage.warning(res.message)
              }
            })
          "id": machineId
        }).then((res) => { // 替换为你的API端点
          if (res.code === 200) {
            ElMessage.success(res.message);
          } else {
            ElMessage.warning(res.message)
          }
        })
        .catch(() => {
          ElMessage({
            type: 'info',
            message: t('functionState.cancel'),
          })
        })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: t('functionState.cancel'),
      })
    })
}
//开工/暂停
const machineStatus = async(state) => {
//定制/标准
const machineMode = async (mode) => {
  ElMessageBox.confirm(
        t('functionState.tips'),
        t('delivery.prompt'),
    t('functionState.tips'),
    t('delivery.prompt'),
    {
      confirmButtonText: t('functionState.sure'),
      cancelButtonText: t('functionState.cancel'),
      type: 'warning',
    }
  )
    .then(() => {
      //下线接口
      request.post("/deviceInteraction/machine/toggleModeMachine",
        {
          confirmButtonText: t('functionState.sure'),
          cancelButtonText: t('functionState.cancel'),
          type: 'warning',
        }
      )
        .then(() => {
          //下线接口
          request.post("/deviceInteraction/machine/updateMachineState",
            {
              "id": machineId,
              "state": state
            }).then((res) => { // 替换为你的API端点
              if (res.code === 200) {
                ElMessage.success(res.message);
              } else {
                ElMessage.warning(res.message)
              }
            })
          "id": machineId,
          "mode": mode
        }).then((res) => { // 替换为你的API端点
          if (res.code === 200) {
            ElMessage.success(res.message);
          } else {
            ElMessage.warning(res.message)
          }
        })
        .catch(() => {
          ElMessage({
            type: 'info',
            message: t('functionState.cancel'),
          })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: t('functionState.cancel'),
      })
    })
}
//开工/暂停
const machineStatus = async (state) => {
  ElMessageBox.confirm(
    t('functionState.tips'),
    t('delivery.prompt'),
    {
      confirmButtonText: t('functionState.sure'),
      cancelButtonText: t('functionState.cancel'),
      type: 'warning',
    }
  )
    .then(() => {
      //下线接口
      request.post("/deviceInteraction/machine/updateMachineState",
        {
          "id": machineId,
          "state": state
        }).then((res) => { // 替换为你的API端点
          if (res.code === 200) {
            ElMessage.success(res.message);
          } else {
            ElMessage.warning(res.message)
          }
        })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: t('functionState.cancel'),
      })
    })
}
//破损
const damagedTask = async(row) => {
const damagedTask = async (row) => {
  ElMessageBox.confirm(
        t('functionState.tips'),
        t('delivery.prompt'),
    t('functionState.tips'),
    t('delivery.prompt'),
    {
      confirmButtonText: t('functionState.sure'),
      cancelButtonText: t('functionState.cancel'),
      type: 'warning',
    }
  )
    .then(() => {
      //下线接口
      request.post("/deviceInteraction/tasking/damagedTask",
        {
          confirmButtonText: t('functionState.sure'),
          cancelButtonText: t('functionState.cancel'),
          type: 'warning',
        }
      )
        .then(() => {
          //下线接口
          request.post("/deviceInteraction/tasking/damagedTask",
            {
              "glassId": row.glassId
            }).then((res) => { // 替换为你的API端点
              if (res.code === 200) {
                ElMessage.success(res.message);
              } else {
                ElMessage.warning(res.message)
              }
            })
          "glassId": row.glassId
        }).then((res) => { // 替换为你的API端点
          if (res.code === 200) {
            ElMessage.success(res.message);
          } else {
            ElMessage.warning(res.message)
          }
        })
        .catch(() => {
          ElMessage({
            type: 'info',
            message: t('functionState.cancel'),
          })
        })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: t('functionState.cancel'),
      })
    })
}
//下线(拿走)
const glassDownLine = async(row) => {
const glassDownLine = async (row) => {
  ElMessageBox.confirm(
        t('functionState.tips'),
        t('delivery.prompt'),
    t('functionState.tips'),
    t('delivery.prompt'),
    {
      confirmButtonText: t('functionState.sure'),
      cancelButtonText: t('functionState.cancel'),
      type: 'warning',
    }
  )
    .then(() => {
      //下线接口
      request.post("/deviceInteraction/tasking/glassDownLine",
        {
          confirmButtonText: t('functionState.sure'),
          cancelButtonText: t('functionState.cancel'),
          type: 'warning',
        }
      )
        .then(() => {
          //下线接口
          request.post("/deviceInteraction/tasking/glassDownLine",
            {
              "glassId": row.glassId,
            }).then((res) => { // 替换为你的API端点
              if (res.code === 200) {
                ElMessage.success(res.message);
              } else {
                ElMessage.warning(res.message)
              }
            })
          "glassId": row.glassId,
        }).then((res) => { // 替换为你的API端点
          if (res.code === 200) {
            ElMessage.success(res.message);
          } else {
            ElMessage.warning(res.message)
          }
        })
        .catch(() => {
          ElMessage({
            type: 'info',
            message: t('functionState.cancel'),
          })
        })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: t('functionState.cancel'),
      })
    })
}
//上线
const topLine = async() => {
const topLineShow = async () => {
  blind.value = true;
}
//领取任务/结束任务
const startOrStopTask = async (row,line,isWorking) => {
  ElMessageBox.confirm(
    t('functionState.tips'),
    t('delivery.prompt'),
    {
      confirmButtonText: t('functionState.sure'),
      cancelButtonText: t('functionState.cancel'),
      type: 'warning',
    }
  )
    .then(() => {
      //领取任务
      request.post("/deviceInteraction/primitiveTask/startOrStopPrimitiveTasking",
        {
          "id": row.id,
          "getLine": line,
          "isWorking": isWorking
        }).then((res) => { // 替换为你的API端点
          if (res.code === 200) {
            ElMessage.success(res.message);
          } else {n
            ElMessage.warning(res.message)
          }
        })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: t('functionState.cancel'),
      })
    })
}
const handleDialogClose = () => {
}
const fetchData = async () => {
  //扫码回车提交
  alert(searchs.value);
  searchs.value="";
}
const filterTableData = computed(() =>
  loadData.value.filter(
    (data) =>
      !searchs.value ||data.scanId.toLowerCase().includes(searchs.value.toLowerCase())
  )
)
</script>
<template>
  <div ref="content" style="padding:0 20px;">
    <div id="div-title" style="font-size: 20px; font-weight: bold; margin:10px 0 10px 0;padding-left: 20px;">
      {{$t('machine.upperSlice')}}
      {{ $t('machine.mechanicalArm') }}
    </div>
    <el-dialog v-model="blind" top="30vh" style="text-align: center;" @close="handleDialogClose">
        <!-- 未领取的标准任务 -->
      <el-table :data="findPrimitiveTask" stripe style="height:260px" :header-cell-style="{ background: '#F2F3F5 ', color: '#1D2129', textAlign: 'center' }" :cell-style="{ textAlign: 'center' }">
        <!-- <el-table-column type="selection" min-width="30" /> -->
        <el-table-column type="index" :label="$t('glassInfo.number')" min-width="30" />
        <el-table-column prop="batchNumber" :label="$t('glassInfo.batchNumber')" />
        <el-table-column prop="taskType" :label="$t('glassInfo.taskType')" />
        <el-table-column prop="scanId" :label="$t('glassInfo.scanId')" />
        <el-table-column prop="length" :label="$t('glassInfo.length')" />
        <el-table-column prop="width" :label="$t('glassInfo.width')" />
        <el-table-column prop="thickness" :label="$t('glassInfo.thickness')" />
        <el-table-column prop="taskQuantity" :label="$t('glassInfo.taskQuantity')" />
        <el-table-column prop="reportCount" :label="$t('glassInfo.reportCount')" />
        <el-table-column prop="workState" :label="$t('glassInfo.workState')" />
        <el-table-column fixed="right" :label="$t('productStock.operate')" align="center" width="70">
          <template #default="scope">
            <el-button size="mini" link type="primary" plain @click="startOrStopTask(scope.row,2,1)">{{
              $t('functionState.getTask') }}</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <hr />
    <br>
    <div id="search" >
    <div id="search">
      <!-- 功能 -->
      <el-button :type="(findMachine['state']=='暂停'?'danger':'success')" id="ButtonMachineStatus" @click="machineStatus((findMachine['state']=='暂停'?'开工':'暂停'))">{{findMachine['state']=='开工'?$t('functionState.start'):$t('functionState.stop')}}</el-button>
      <el-button type="primary" id="ButtonTopLine" @click="topLine">{{$t('functionState.topLine')}}</el-button>
      <!-- <el-button type="primary" id="searchButton" @click="downLine('下线')">下线</el-button>
      <el-button type="primary" id="searchButton" @click="workStatus('破损')">破损</el-button>
      <el-button type="primary" id="searchButton" @click="workStatus('完工')">完工</el-button> -->
      <el-button :type="(findMachine['state'] == '暂停' ? 'danger' : 'success')" id="ButtonMachineStatus"
        @click="machineStatus((findMachine['state'] == '暂停' ? '开工' : '暂停'))">{{ findMachine['state'] == '开工' ?
          $t('functionState.start') : $t('functionState.stop') }}</el-button>
      <el-button type="primary" id="ButtonTopLine" @click="topLineShow">{{ $t('functionState.getTask') }}</el-button>
      <el-button :type="(findMachine['mode'] == '定制' ? 'danger' : 'success')" id="ButtonMachineMode"
        @click="machineMode((findMachine['mode'] == 0 ? 1 : 0))">{{ findMachine['mode'] == 0 ?
         $t('functionState.modeD') : $t('functionState.modeB') }}</el-button>
    </div>
    <div id="main-body" style="min-height:240px;">
      <!-- 表格内容 -->
      <el-table :data="loadData" stripe
      <el-table :data="filterTableData" stripe style="height:260px"
        :header-cell-style="{ background: '#F2F3F5 ', color: '#1D2129', textAlign: 'center' }"
        :cell-style="{ textAlign: 'center' }">
        <!-- <el-table-column type="selection" min-width="30" /> -->
        <el-table-column type="index" :label="$t('glassInfo.number')" min-width="30" />
        <el-table-column prop="batchNumber" :label="$t('glassInfo.batchNumber')"/>
        <el-table-column prop="taskType" :label="$t('glassInfo.taskType')"/>
        <el-table-column prop="glassId" :label="$t('glassInfo.glassId')"/>
        <el-table-column prop="length" :label="$t('glassInfo.length')"/>
        <el-table-column prop="width" :label="$t('glassInfo.width')"/>
        <el-table-column prop="thickness" :label="$t('glassInfo.thickness')"/>
        <el-table-column prop="workState" :label="$t('glassInfo.workState')"/>
        <el-table-column prop="batchNumber" sortable :label="$t('glassInfo.batchNumber')" />
        <el-table-column prop="taskType" sortable :label="$t('glassInfo.taskType')" />
        <el-table-column prop="scanId" sortable :label="$t('glassInfo.scanId')" >
        <template #header>
            <div>
              <div>{{ $t('glassInfo.taskType') }}
                <el-icon @click="fetchData"><CaretTop /></el-icon>
                <el-icon @click="fetchData"><CaretBottom /></el-icon>
                <el-icon color="#409efc"><Filter /></el-icon>
              </div>
              <el-input v-model="searchs" type="primary" id="ReportSubmission" @keyup.enter="fetchData"></el-input>
              <!-- <el-input size="small" placeholder="Type to search" /> -->
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="length" sortable :label="$t('glassInfo.length')" />
        <el-table-column prop="width" sortable :label="$t('glassInfo.width')" />
        <el-table-column prop="thickness" sortable :label="$t('glassInfo.thickness')" />
        <el-table-column prop="taskQuantity" sortable :label="$t('glassInfo.taskQuantity')" />
        <el-table-column prop="isWorking" sortable :label="$t('glassInfo.isWorking')" />
        <el-table-column fixed="right" :label="$t('productStock.operate')" align="center" width="270">
          <template #default="scope">
            <el-button size="mini" link type="primary" plain @click="workStatus(scope.row, '重发')" >{{$t('functionState.anew')}}</el-button>
            <el-button size="mini" link type="primary" plain @click="workStatus(scope.row, '完工')">{{$t('functionState.finish')}}</el-button>
            <el-button size="mini" link type="primary" plain @click="damagedTask(scope.row)">{{$t('functionState.lose')}}</el-button>
            <el-button size="mini" link type="primary" plain @click="glassDownLine(scope.row)">{{$t('functionState.downLine')}}</el-button>
            <el-button size="mini" link type="primary" plain @click="startOrStopTask(scope.row,2,2)">{{
              $t('functionState.stopTask') }}</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div id="main-body"
      style="width: 45%; height: 400px;margin: 50px 0 0 50px;background-image: url(../../src/assets/上片机.png) ;background-size: 100% 100%;">
      <!-- 画图内容 -->
      <div style="width: 200px; height: 100px; background-color: red; position: relative; top: 271px; left: 158px">
        <div style="width: 500px; height: 300px; position: relative; top: -250PX; left: 800px">
          <el-table :data="loadData" stripe class="custom-table"
        :header-cell-style="{ background: '#F2F3F5 ', color: '#1D2129', textAlign: 'center',height: '80px'}"
        :cell-style="{ textAlign: 'center',height: '80px'}">
        <!-- <el-table-column type="selection" min-width="30" /> -->
        <el-table-column type="index" :label="$t('glassInfo.number')" min-width="55" />
        <el-table-column prop="batchNumber" :label="$t('glassInfo.batchNumber')"/>
        <el-table-column prop="taskType" :label="$t('glassInfo.taskType')"/>
        <el-table-column prop="glassId" :label="$t('glassInfo.glassId')" />
        <el-table-column prop="length" :label="$t('glassInfo.length')" min-width="55"/>
        <el-table-column prop="width" :label="$t('glassInfo.width')" min-width="55"/>
        <el-table-column prop="thickness" :label="$t('glassInfo.thickness')"/>
        <el-table-column prop="workState" :label="$t('glassInfo.workState')"/>
        <el-table-column fixed="right" :label="$t('productStock.operate')" align="center" width="100">
          <template #default="scope">
            <el-button size="mini" style="min-width: 100px;" link type="primary" plain @click="workStatus(scope.row, '绑定')" >{{$t('functionState.bound')}}</el-button>
          </template>
        </el-table-column>
      </el-table>
        </div>
    <div id="main-body" style="width: 100%; height: 460px;min-width: 1200px;">
      <el-image style="width: 70%;min-width: 900px; height: 460px;float: left;" src="../../src/assets/扫码识别.png"></el-image>
      <!-- <div style="width: 70%;min-width: 900px; height: 460px;background-image: url(../../src/assets/扫码识别.png) ;background-size: 100% 100%;float: left;">
      </div> -->
      <div style="width: 30%;min-width: 300px; height: 460px;float: left;padding: 20px;;">
        <el-table :data="sendRecords" stripe
          :header-cell-style="{ background: '#F2F3F5 ', color: '#1D2129', textAlign: 'center', height: '30px' }"
          :cell-style="{ textAlign: 'center' }">
          <el-table-column prop="sendContent" :label="$t('glassInfo.sendContent')" />
        </el-table>
      </div>
      <div style="clear:both"></div>
    </div>
  </div>
</template>
<style scoped>
table {
  text-align: center;
  width: 100%;
@@ -318,4 +442,11 @@
  border: none;
  cursor: pointer;
}
.dotClass {
  width:10px;
  height:10px;
  border-radius: 50%;
  display: block;
  margin-left: 10px;
}
</style>