From f6e042f64b3324c441c3246490b28e4acacaeb3e Mon Sep 17 00:00:00 2001
From: wu <731351411@qq.com>
Date: 星期三, 18 九月 2024 09:12:58 +0800
Subject: [PATCH] 页面更换方法

---
 UI-Project/src/views/MechanicalArm/mechanicalArm.vue |  193 +++++++++++++++++++++++++++++++++++++----------
 1 files changed, 150 insertions(+), 43 deletions(-)

diff --git a/UI-Project/src/views/MechanicalArm/mechanicalArm.vue b/UI-Project/src/views/MechanicalArm/mechanicalArm.vue
index f77ae7c..e9a0f38 100644
--- a/UI-Project/src/views/MechanicalArm/mechanicalArm.vue
+++ b/UI-Project/src/views/MechanicalArm/mechanicalArm.vue
@@ -1,41 +1,90 @@
-<!--  鎵撴爣鏈�  -->
+<!--  涓婄墖鏈�  -->
 <script setup>
 import request from "@/utils/request";
 import { ElMessage, ElMessageBox } from "element-plus";
-import { reactive, ref, onMounted } from 'vue'
+import { reactive, ref, onMounted, onBeforeUnmount,onUnmounted } from 'vue'
 import { useI18n } from 'vue-i18n'
+import { WebSocketHost ,host} from '@/utils/constants'
+import { initializeWebSocket, closeWebSocket } from '@/utils/WebSocketService';
 let language = ref(localStorage.getItem('lang') || 'zh')
 const { t } = useI18n()
 const requestData = reactive({
   account: '',
   password: '',
 });
-const mechanicalArmData = ref([]);
+const loadData = ref([]);
+const findMachine = ref([]);
+const machineid=1//鑾峰彇鏁版嵁
+//浣跨敤WebSocket鏂瑰紡灞曠ず鏁版嵁
+let socket = null;
+const socketUrl = `ws://${WebSocketHost}:${host}/api/deviceInteraction/api/talk/mechanicalArm`;
+// 瀹氫箟娑堟伅澶勭悊鍑芥暟锛屾洿鏂� receivedData 鍙橀噺
+const handleMessage = (data) => {
+  // 鏇存柊 tableData 鐨勬暟鎹�
+  loadData.value = data.taskingList[0];
+  findMachine.value = data.machine[0];
+};
+onUnmounted(() => {
+  if (socket) {
+    closeWebSocket(socket);
+  }
+});
+onBeforeUnmount(() => {
+  console.log("鍏抽棴浜�")
+  closeWebSocket();
+});
 
 onMounted(async () => {
-  load();
+  //浣跨敤WebSocket鏂瑰紡灞曠ず鏁版嵁
+  socket = initializeWebSocket(socketUrl, handleMessage);// 鍒濆鍖� WebSocket锛屽苟浼犻�掓秷鎭鐞嗗嚱鏁�
+
+  //浣跨敤鎺ュ彛鏂瑰紡灞曠ず鏁版嵁
+  //load();
 });
-//鑾峰彇鏁版嵁
-const load = async() => {
-  try {
-    const response = await request.post('/deviceInteraction/tasking/findCraftTasking',
-    {
-      "glassId": 0,
-      "state": "绾夸笂",
-      "workState": "宸ヤ綔",
-      "currentCraft": "鎵撶("
-    }); // 鏇挎崲涓轰綘鐨凙PI绔偣  
-    if (response.code === 200) {
-      mechanicalArmData.value= response.data;
-    } else {
-      ElMessage.warning(res.msg)
-    }
-  } catch (error) {
-    // console.error('Error fetching rects :', error);  
-  }
-}
-//淇敼宸ヤ綔鐘舵�� 銆愬け璐�/宸ヤ綔/瀹屾垚銆�
+
+// //鑾峰彇鏁版嵁
+// const load = async() => {
+//   //鑾峰彇璁惧浠诲姟鏁版嵁
+//   try {
+//     const response = await request.post('/deviceInteraction/tasking/findMachineTask',
+//     {
+//       "id": 11
+//     }); // 鏇挎崲涓轰綘鐨凙PI绔偣  
+//     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
+//     }); // 鏇挎崲涓轰綘鐨凙PI绔偣  
+//     if (response.code === 200) {
+//       findMachine.value= response.data;
+//     } else {
+//       ElMessage.warning(res.msg)
+//     }
+//   } catch (error) {
+//     // console.error('Error fetching rects :', error);  
+//   }
+// }
+//淇敼宸ヤ綔鐘舵�� 銆愬け璐�/姝e湪宸ヤ綔/瀹屽伐銆�
 const workStatus = async(row,state) => {
+  let url;
+  if(state=="澶辫触"){
+    url="/deviceInteraction/tasking/loseMachineTask";
+  }else if(state=="姝e湪宸ヤ綔"){
+    url="/deviceInteraction/tasking/startMachineTask";
+  }else if(state=="瀹屽伐"){
+    url="/deviceInteraction/tasking/finishMachineTask";
+  }else{
+    return;
+  }
   ElMessageBox.confirm(
         t('marking.tips'),
         t('delivery.prompt'),  
@@ -47,14 +96,12 @@
       )
         .then(() => {
           //寮�濮嬩慨鏀�
-          request.post("/deviceInteraction/tasking/updateCraftTasking",
+          request.post(url,
             {
-              "glassId": row.glassId,
-              "workState": state
+              "id": machineid,
             }).then((res) => { // 鏇挎崲涓轰綘鐨凙PI绔偣  
               if (res.code === 200) {
                 ElMessage.success(res.message);
-                load();
               } else {
                 ElMessage.warning(res.message)
               }
@@ -70,12 +117,7 @@
 }
 
 //寮�宸�/鏆傚仠
-const machineStatus = async(row,state) => {
-
-}
-
-//涓嬬嚎(鎷胯蛋)
-const downLine = async(row,state) => {
+const machineStatus = async(state) => {
   ElMessageBox.confirm(
         t('marking.tips'),
         t('delivery.prompt'),  
@@ -87,14 +129,75 @@
       )
         .then(() => {
           //涓嬬嚎鎺ュ彛
-          request.post("/deviceInteraction/tasking/updateDownLine",
+          request.post("/deviceInteraction/machine/updateMachineState",
             {
-              "glassId": row.glassId,
+              "id": machineid,
               "state": state
             }).then((res) => { // 鏇挎崲涓轰綘鐨凙PI绔偣  
               if (res.code === 200) {
                 ElMessage.success(res.message);
-                this.load();
+              } else {
+                ElMessage.warning(res.message)
+              }
+            })
+        })
+        .catch(() => {
+          ElMessage({
+            type: 'info',
+            message: t('marking.cancel'),
+          })
+        })
+}
+//鐮存崯
+const damagedTask = async(row) => {
+  ElMessageBox.confirm(
+        t('marking.tips'),
+        t('delivery.prompt'),  
+        {
+          confirmButtonText: t('marking.sure'),
+          cancelButtonText: t('marking.cancel'),
+          type: 'warning',
+        }
+      )
+        .then(() => {
+          //涓嬬嚎鎺ュ彛
+          request.post("/deviceInteraction/tasking/damagedTask",
+            {
+              "glassId": row.glassId
+            }).then((res) => { // 鏇挎崲涓轰綘鐨凙PI绔偣  
+              if (res.code === 200) {
+                ElMessage.success(res.message);
+              } else {
+                ElMessage.warning(res.message)
+              }
+            })
+        })
+        .catch(() => {
+          ElMessage({
+            type: 'info',
+            message: t('marking.cancel'),
+          })
+        })
+}
+//涓嬬嚎(鎷胯蛋)
+const glassDownLine = async(row) => {
+  ElMessageBox.confirm(
+        t('marking.tips'),
+        t('delivery.prompt'),  
+        {
+          confirmButtonText: t('marking.sure'),
+          cancelButtonText: t('marking.cancel'),
+          type: 'warning',
+        }
+      )
+        .then(() => {
+          //涓嬬嚎鎺ュ彛
+          request.post("/deviceInteraction/tasking/glassDownLine",
+            {
+              "glassId": row.glassId,
+            }).then((res) => { // 鏇挎崲涓轰綘鐨凙PI绔偣  
+              if (res.code === 200) {
+                ElMessage.success(res.message);
               } else {
                 ElMessage.warning(res.message)
               }
@@ -116,18 +219,21 @@
 <template>
   <div ref="content">
     <div id="div-title" style="font-size: 20px; font-weight: bold; margin:10px 0 10px 0;padding-left: 20px;">
-      {{ $t('mechanicalArm.deleteTips') }}
+      鑷姩涓婄墖鏈�
     </div>
     <hr />
     <br>
     <div id="search" style="padding-left: 20px;">
       <!-- 鍔熻兘 -->
-      <el-button type="primary" id="searchButton" @click="machineStatus">寮�宸�</el-button>
-      <el-button type="primary" id="searchButton" @click="topLine">涓婄嚎</el-button>
+      <el-button type="primary" id="ButtonMachineStatus" @click="machineStatus((findMachine['state']=='鏆傚仠'?'寮�宸�':'鏆傚仠'))">{{findMachine['state']=='寮�宸�'?'寮�宸�':'鏆傚仠'}}</el-button>
+      <el-button type="primary" id="ButtonTopLine" @click="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> -->
     </div>
     <div id="main-body" style="min-height:240px;">
       <!-- 琛ㄦ牸鍐呭 -->
-      <el-table :data="mechanicalArmData" stripe
+      <el-table :data="loadData" stripe
         :header-cell-style="{ background: '#F2F3F5 ', color: '#1D2129', textAlign: 'center' }"
         :cell-style="{ textAlign: 'center' }">
         <!-- <el-table-column type="selection" min-width="30" /> -->
@@ -141,9 +247,10 @@
         <el-table-column prop="workState" label="鐘舵��" />
         <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, '鐮存崯')">鐮存崯</el-button>
+            <el-button size="mini" link type="primary" plain @click="workStatus(scope.row, '澶辫触')">閲嶅彂</el-button>
             <el-button size="mini" link type="primary" plain @click="workStatus(scope.row, '瀹屽伐')">瀹屽伐</el-button>
-            <el-button size="mini" link type="primary" plain @click="downLine(scope.row, '涓嬬嚎')">涓嬬嚎</el-button>
+            <el-button size="mini" link type="primary" plain @click="damagedTask(scope.row)">鐮存崯</el-button>
+            <el-button size="mini" link type="primary" plain @click="glassDownLine(scope.row)">涓嬬嚎</el-button>
           </template>
         </el-table-column>
       </el-table>

--
Gitblit v1.8.0