From 792236ef78c2cdd3a989fb40a7f2e2487c4e17b6 Mon Sep 17 00:00:00 2001
From: huang <1532065656@qq.com>
Date: 星期三, 26 十一月 2025 17:06:11 +0800
Subject: [PATCH] 添加各个设备基础可配置参数
---
mes-web/src/views/plcTest/components/MultiDeviceTest/TaskOrchestration.vue | 260 ++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 233 insertions(+), 27 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..74906ce 100644
--- a/mes-web/src/views/plcTest/components/MultiDeviceTest/TaskOrchestration.vue
+++ b/mes-web/src/views/plcTest/components/MultiDeviceTest/TaskOrchestration.vue
@@ -5,30 +5,74 @@
<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">
- <el-form-item label="鐜荤拑ID鍒楄〃">
+ <el-form :model="form" label-width="120px" :rules="rules" ref="formRef">
+ <el-form-item label="鐜荤拑ID鍒楄〃" prop="glassIds" required>
<el-input
v-model="glassIdsInput"
type="textarea"
:rows="4"
- placeholder="璇疯緭鍏ョ幓鐠冩潯鐮侊紝鏀寔澶氳鎴栭�楀彿鍒嗛殧"
+ placeholder="璇疯緭鍏ョ幓鐠冩潯鐮侊紝鏀寔澶氳鎴栭�楀彿鍒嗛殧锛屾瘡琛屼竴涓垨閫楀彿鍒嗛殧"
+ show-word-limit
+ :maxlength="5000"
/>
+ <div class="form-tip">
+ 宸茶緭鍏� {{ glassIds.length }} 涓幓鐠僆D
+ </div>
</el-form-item>
- <el-form-item label="浣嶇疆缂栫爜">
- <el-input v-model="form.positionCode" placeholder="渚嬪锛歅OS1" />
- </el-form-item>
- <el-form-item label="瀛樺偍浣嶇疆">
- <el-input-number v-model="form.storagePosition" :min="1" :max="200" />
- </el-form-item>
+
+ <el-divider content-position="left">鎵ц閰嶇疆</el-divider>
+
<el-form-item label="鎵ц闂撮殧 (ms)">
- <el-input-number v-model="form.executionInterval" :min="100" :max="10000" />
+ <el-input-number
+ v-model="form.executionInterval"
+ :min="100"
+ :max="10000"
+ :step="100"
+ placeholder="璁惧鎿嶄綔闂撮殧鏃堕棿"
+ />
+ <div class="form-tip">姣忎釜璁惧鎿嶄綔涔嬮棿鐨勯棿闅旀椂闂达紙姣锛�</div>
+ </el-form-item>
+
+ <el-form-item label="瓒呮椂鏃堕棿 (鍒嗛挓)">
+ <el-input-number
+ v-model="form.timeoutMinutes"
+ :min="1"
+ :max="60"
+ :step="1"
+ placeholder="浠诲姟瓒呮椂鏃堕棿"
+ />
+ <div class="form-tip">浠诲姟鎵ц鐨勬渶澶ц秴鏃舵椂闂�</div>
+ </el-form-item>
+
+ <el-form-item label="閲嶈瘯娆℃暟">
+ <el-input-number
+ v-model="form.retryCount"
+ :min="0"
+ :max="10"
+ :step="1"
+ placeholder="澶辫触閲嶈瘯娆℃暟"
+ />
+ <div class="form-tip">璁惧鎿嶄綔澶辫触鏃剁殑鏈�澶ч噸璇曟鏁�</div>
</el-form-item>
</el-form>
</div>
@@ -37,8 +81,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: {
@@ -50,18 +95,51 @@
const emit = defineEmits(['task-started'])
const form = reactive({
- positionCode: '',
- storagePosition: null,
- executionInterval: 1000
+ executionInterval: 1000,
+ timeoutMinutes: 30,
+ retryCount: 3
})
+
+const formRef = ref(null)
+
+const rules = {
+ glassIds: [
+ {
+ validator: (rule, value, callback) => {
+ if (glassIds.value.length === 0) {
+ callback(new Error('璇疯嚦灏戣緭鍏ヤ竴涓幓鐠僆D'))
+ } else if (glassIds.value.length > 100) {
+ callback(new Error('鐜荤拑ID鏁伴噺涓嶈兘瓒呰繃100涓�'))
+ } else {
+ // 楠岃瘉鐜荤拑ID鏍煎紡
+ const invalidIds = glassIds.value.filter(id => {
+ // 绠�鍗曠殑鏍煎紡楠岃瘉锛氫笉鑳戒负绌猴紝闀垮害鍦�1-50涔嬮棿
+ return !id || id.length === 0 || id.length > 50
+ })
+ if (invalidIds.length > 0) {
+ callback(new Error(`瀛樺湪鏃犳晥鐨勭幓鐠僆D鏍煎紡锛岃妫�鏌))
+ } else {
+ callback()
+ }
+ }
+ },
+ trigger: 'blur'
+ }
+ ]
+}
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()
}
)
@@ -73,32 +151,141 @@
.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) {
ElMessage.warning('璇峰厛閫夋嫨璁惧缁�')
return
}
+
+ // 琛ㄥ崟楠岃瘉
+ if (!formRef.value) return
+ try {
+ await formRef.value.validate()
+ } catch (error) {
+ ElMessage.warning('璇锋鏌ヨ〃鍗曡緭鍏�')
+ return
+ }
+
if (glassIds.value.length === 0) {
ElMessage.warning('璇疯嚦灏戣緭鍏ヤ竴涓幓鐠僆D')
return
}
+
try {
loading.value = true
- await multiDeviceTaskApi.startTask({
+
+ // 鏋勫缓浠诲姟鍙傛暟
+ const parameters = {
+ glassIds: glassIds.value,
+ executionInterval: form.executionInterval || 1000
+ }
+
+ // 璁惧鐗瑰畾閰嶇疆宸茬Щ闄わ紝濡傛湁闇�瑕佸彲鍦ㄦ鎵╁睍
+ if (form.timeoutMinutes) {
+ parameters.timeoutMinutes = form.timeoutMinutes
+ }
+ if (form.retryCount !== null) {
+ parameters.retryCount = form.retryCount
+ }
+
+ // 寮傛鍚姩浠诲姟锛岀珛鍗宠繑鍥烇紝涓嶉樆濉�
+ const response = await multiDeviceTaskApi.startTask({
groupId: props.group.id || props.group.groupId,
- parameters: {
- glassIds: glassIds.value,
- positionCode: form.positionCode || null,
- storagePosition: form.storagePosition,
- executionInterval: form.executionInterval
- }
+ parameters
})
- ElMessage.success('浠诲姟宸插惎鍔�')
- emit('task-started')
+
+ const task = response?.data
+ if (task && task.taskId) {
+ ElMessage.success(`浠诲姟宸插惎鍔紙寮傛鎵ц锛�: ${task.taskId}`)
+ emit('task-started', task)
+
+ // 绔嬪嵆鍒锋柊鐩戞帶鍒楄〃锛屾樉绀烘柊鍚姩鐨勪换鍔�
+ setTimeout(() => {
+ emit('task-started')
+ }, 500)
+
+ // 閲嶇疆琛ㄥ崟锛堜繚鐣欐墽琛岄厤缃級锛屾柟渚跨户缁惎鍔ㄥ叾浠栬澶囩粍
+ glassIdsInput.value = ''
+
+ // 鎻愮ず鐢ㄦ埛鍙互缁х画鍚姩鍏朵粬璁惧缁�
+ ElMessage.info('鍙互缁х画閫夋嫨鍏朵粬璁惧缁勫惎鍔ㄦ祴璇曪紝澶氫釜璁惧缁勫皢骞惰鎵ц')
+ } else {
+ ElMessage.warning('浠诲姟鍚姩鍝嶅簲寮傚父')
+ }
} catch (error) {
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: {}
+ })
+ 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 +318,24 @@
.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;
+}
+
+.form-tip {
+ font-size: 12px;
+ color: #909399;
+ margin-top: 4px;
+ line-height: 1.4;
+}
</style>
--
Gitblit v1.8.0