From 366ba040d2447bacd3455299425e3166f1f992bb Mon Sep 17 00:00:00 2001
From: huang <1532065656@qq.com>
Date: 星期四, 20 十一月 2025 14:38:32 +0800
Subject: [PATCH] 添加大车、大理片笼以及多设备串行/并行执行写入基础逻辑

---
 mes-web/src/views/plcTest/components/MultiDeviceTest/TaskOrchestration.vue |  113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 108 insertions(+), 5 deletions(-)

diff --git a/mes-web/src/views/plcTest/components/MultiDeviceTest/TaskOrchestration.vue b/mes-web/src/views/plcTest/components/MultiDeviceTest/TaskOrchestration.vue
index 606f293..f3490b4 100644
--- a/mes-web/src/views/plcTest/components/MultiDeviceTest/TaskOrchestration.vue
+++ b/mes-web/src/views/plcTest/components/MultiDeviceTest/TaskOrchestration.vue
@@ -5,11 +5,24 @@
         <h3>澶氳澶囨祴璇曠紪鎺�</h3>
         <p v-if="group">褰撳墠璁惧缁勶細{{ group.groupName }}锛坽{ group.deviceCount || '-' }} 鍙拌澶囷級</p>
         <p v-else class="warning">璇峰厛鍦ㄥ乏渚ч�夋嫨涓�涓澶囩粍</p>
+        <p v-if="group && loadDeviceName" class="sub-info">涓婂ぇ杞﹁澶囷細{{ loadDeviceName }}</p>
       </div>
-      <el-button type="primary" :disabled="!group" :loading="loading" @click="handleSubmit">
-        <el-icon><Promotion /></el-icon>
-        鍚姩娴嬭瘯
-      </el-button>
+      <div class="action-buttons">
+        <el-button
+          type="danger"
+          plain
+          :disabled="!group || !loadDeviceId || loadDeviceLoading"
+          :loading="clearLoading"
+          @click="handleClearPlc"
+        >
+          <el-icon><Delete /></el-icon>
+          娓呯┖PLC
+        </el-button>
+        <el-button type="primary" :disabled="!group" :loading="loading" @click="handleSubmit">
+          <el-icon><Promotion /></el-icon>
+          鍚姩娴嬭瘯
+        </el-button>
+      </div>
     </div>
 
     <el-form :model="form" label-width="120px">
@@ -37,8 +50,9 @@
 <script setup>
 import { computed, reactive, ref, watch } from 'vue'
 import { ElMessage } from 'element-plus'
-import { Promotion } from '@element-plus/icons-vue'
+import { Delete, Promotion } from '@element-plus/icons-vue'
 import { multiDeviceTaskApi } from '@/api/device/multiDeviceTask'
+import { deviceGroupApi, deviceInteractionApi } from '@/api/device/deviceManagement'
 
 const props = defineProps({
   group: {
@@ -57,11 +71,16 @@
 
 const glassIdsInput = ref('')
 const loading = ref(false)
+const clearLoading = ref(false)
+const loadDeviceId = ref(null)
+const loadDeviceName = ref('')
+const loadDeviceLoading = ref(false)
 
 watch(
   () => props.group,
   () => {
     glassIdsInput.value = ''
+    fetchLoadDevice()
   }
 )
 
@@ -72,6 +91,42 @@
     .map((item) => item.trim())
     .filter((item) => item.length > 0)
 })
+
+const fetchLoadDevice = async () => {
+  loadDeviceId.value = null
+  loadDeviceName.value = ''
+  if (!props.group) {
+    return
+  }
+  const groupId = props.group.id || props.group.groupId
+  if (!groupId) {
+    return
+  }
+  loadDeviceLoading.value = true
+  try {
+    const response = await deviceGroupApi.getGroupDevices(groupId)
+    const rawList = response?.data
+    const deviceList = Array.isArray(rawList)
+      ? rawList
+      : Array.isArray(rawList?.records)
+      ? rawList.records
+      : Array.isArray(rawList?.data)
+      ? rawList.data
+      : []
+    const targetDevice =
+      deviceList.find((item) => (item.deviceType || '').toUpperCase() === 'LOAD_VEHICLE') ||
+      deviceList[0]
+    if (targetDevice && targetDevice.id) {
+      loadDeviceId.value = targetDevice.id
+      loadDeviceName.value = targetDevice.deviceName || targetDevice.deviceCode || `ID: ${targetDevice.id}`
+    }
+  } catch (error) {
+    console.error('鍔犺浇璁惧淇℃伅澶辫触:', error)
+    ElMessage.error(error?.message || '鑾峰彇璁惧淇℃伅澶辫触')
+  } finally {
+    loadDeviceLoading.value = false
+  }
+}
 
 const handleSubmit = async () => {
   if (!props.group) {
@@ -99,6 +154,42 @@
     ElMessage.error(error?.message || '浠诲姟鍚姩澶辫触')
   } finally {
     loading.value = false
+  }
+}
+
+const handleClearPlc = async () => {
+  if (!props.group) {
+    ElMessage.warning('璇峰厛閫夋嫨璁惧缁�')
+    return
+  }
+  if (!loadDeviceId.value) {
+    ElMessage.warning('鏈壘鍒颁笂澶ц溅璁惧锛屾棤娉曟竻绌篜LC')
+    return
+  }
+  try {
+    clearLoading.value = true
+    const response = await deviceInteractionApi.executeOperation({
+      deviceId: loadDeviceId.value,
+      operation: 'clearGlass',
+      params: {
+        positionCode: form.positionCode || null
+      }
+    })
+    if (response?.code !== 200) {
+      throw new Error(response?.message || 'PLC娓呯┖澶辫触')
+    }
+    const result = response?.data
+    if (result?.success) {
+      ElMessage.success(result?.message || 'PLC宸叉竻绌�')
+      glassIdsInput.value = ''
+    } else {
+      throw new Error(result?.message || 'PLC娓呯┖澶辫触')
+    }
+  } catch (error) {
+    console.error('娓呯┖PLC澶辫触:', error)
+    ElMessage.error(error?.message || 'PLC娓呯┖澶辫触')
+  } finally {
+    clearLoading.value = false
   }
 }
 </script>
@@ -131,5 +222,17 @@
 .panel-header .warning {
   color: #f56c6c;
 }
+
+.panel-header .sub-info {
+  margin-top: 4px;
+  color: #606266;
+  font-size: 12px;
+}
+
+.action-buttons {
+  display: flex;
+  gap: 12px;
+  align-items: center;
+}
 </style>
 

--
Gitblit v1.8.0