From 2ea0557f4eef60ce92e9986c06a39ffd25638dff Mon Sep 17 00:00:00 2001 From: caozehui <2427765068@qq.com> Date: Thu, 25 Jun 2026 10:52:19 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A8=8B=E6=8E=A7=E6=BA=90=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/controlSourceDetail.vue | 79 ++++++++++++++++--- .../controlSource/components/machineTree.vue | 6 +- .../src/views/machine/controlSource/index.vue | 42 +++++++++- 3 files changed, 111 insertions(+), 16 deletions(-) diff --git a/frontend/src/views/machine/controlSource/components/controlSourceDetail.vue b/frontend/src/views/machine/controlSource/components/controlSourceDetail.vue index f686911..b803a39 100644 --- a/frontend/src/views/machine/controlSource/components/controlSourceDetail.vue +++ b/frontend/src/views/machine/controlSource/components/controlSourceDetail.vue @@ -158,18 +158,20 @@ type="primary" size="large" @click="startLoading" - :disabled="pauseDisabled" + :loading="isStarting" + :disabled="props.startDisabeld || isStarting || isStopping" > - 启动 + {{ isStarting ? '启动中' : '启动' }} - 停止 + {{ isStopping ? '停止中' : '停止' }} @@ -269,6 +271,10 @@ const tableData: any = ref([]) const tabData: any = ref([]) const showLoading = ref(false) +const isStarting = ref(false) +const isStopping = ref(false) +const selectedScriptName = ref('') +const pendingScriptName = ref('') const column = ref([ { label: 'L1', @@ -291,7 +297,13 @@ const hour = ref(0) const minute = ref(0) const second = ref(0) -const emit = defineEmits(['update:activeName', 'update:activeIndex', 'update:startDisabeld', 'update:pauseDisabled']) +const emit = defineEmits([ + 'update:activeName', + 'update:activeIndex', + 'update:startDisabeld', + 'update:pauseDisabled', + 'update:runningScriptName' +]) watch( () => props.formControl.scriptId, @@ -305,6 +317,16 @@ watch( } } ) + +watch( + () => props.startDisabeld, + value => { + if (!value) { + isStarting.value = false + } + } +) + const controlContent = ref({ userPageId: '', scriptId: '', @@ -376,6 +398,7 @@ const setTab = row => { activeName.value = row.activeName childActiveName.value = row.childActiveName childActiveIndex.value = row.activeIndex + selectedScriptName.value = row.scriptName || '' getTree() emit('update:activeName', activeName.value) // 触发事件并传递 activeName.value emit('update:activeIndex', row.activeIndex) // 触发事件并传递 activeName.value @@ -450,6 +473,12 @@ const view = (row: Partial = {}) => { // 定义 startLoading 方法 const startLoading = async () => { + if (props.startDisabeld || isStarting.value || isStopping.value) { + return + } + + isStarting.value = true + pendingScriptName.value = selectedScriptName.value emit('update:startDisabeld', true) emit('update:pauseDisabled', true) ElMessage.success({ message: '启动中...', duration: 6000 }) @@ -458,25 +487,49 @@ const startLoading = async () => { controlContent.value.scriptId = props.formControl.scriptId controlContent.value.scriptIndex = childActiveIndex.value controlContent.value.sourceId = props.formControl.sourceId - setTimeout(async () => { + + try { + await new Promise(resolve => setTimeout(resolve, 3000)) await startSimulateTest(controlContent.value) - }, 3000) + } catch (error) { + isStarting.value = false + pendingScriptName.value = '' + emit('update:startDisabeld', false) + emit('update:pauseDisabled', true) + ElMessage.error('启动失败!') + } } // 定义 startLoading 方法 const stopLoading = async () => { + if (props.pauseDisabled || isStarting.value || isStopping.value) { + return + } + + isStopping.value = true // 启动加载逻辑 controlContent.value.userPageId = JwtUtil.getLoginName() controlContent.value.scriptId = props.formControl.scriptId controlContent.value.scriptIndex = childActiveIndex.value controlContent.value.sourceId = props.formControl.sourceId - await closeSimulateTest(controlContent.value) - emit('update:pauseDisabled', true) - emit('update:startDisabeld', true) - ElMessage.success({ message: '停止中...', duration: 5000 }) + + try { + await closeSimulateTest(controlContent.value) + emit('update:pauseDisabled', true) + emit('update:startDisabeld', true) + ElMessage.success({ message: '停止中...', duration: 5000 }) + } catch (error) { + isStopping.value = false + emit('update:pauseDisabled', false) + emit('update:startDisabeld', false) + ElMessage.error('停止失败!') + } } const startTimeCount = () => { + isStarting.value = false + emit('update:runningScriptName', pendingScriptName.value || selectedScriptName.value) + pendingScriptName.value = '' // Loading效果展示 showLoading.value = true @@ -500,6 +553,8 @@ const secondToTime = (secd: number) => { } const stopTimeCount = () => { + isStopping.value = false + emit('update:runningScriptName', '') if (timer) { clearInterval(timer) timer = null diff --git a/frontend/src/views/machine/controlSource/components/machineTree.vue b/frontend/src/views/machine/controlSource/components/machineTree.vue index 95cbe7a..37bdd7d 100644 --- a/frontend/src/views/machine/controlSource/components/machineTree.vue +++ b/frontend/src/views/machine/controlSource/components/machineTree.vue @@ -60,7 +60,8 @@ const handleNodeClick = (data, node) => { emit('setTab', { activeName: active, childActiveName: childActive, - activeIndex:data.index + activeIndex:data.index, + scriptName: data.sourceDesc || data.scriptTypeName || '' }) } @@ -112,7 +113,8 @@ function handleCheckChange(data,isChecked) { emit('setTab', { activeName: data.scriptType, childActiveName: data.scriptTypeCode, - activeIndex:data.index + activeIndex:data.index, + scriptName: data.sourceDesc || data.scriptTypeName || '' }) } } diff --git a/frontend/src/views/machine/controlSource/index.vue b/frontend/src/views/machine/controlSource/index.vue index 59b1873..3ff376f 100644 --- a/frontend/src/views/machine/controlSource/index.vue +++ b/frontend/src/views/machine/controlSource/index.vue @@ -53,8 +53,12 @@
- - {{ connectionStatusText }} +
+ + {{ connectionStatusText }} +
+ +
{{ runningScriptStatusText }}
@@ -71,6 +75,7 @@ @update:startDisabeld="startDisabeld = $event" v-model:pauseDisabled="pauseDisabled" @update:pauseDisabled="pauseDisabled = $event" + @update:runningScriptName="runningScriptName = $event" /> @@ -128,6 +133,7 @@ const formContent = ref({ const connectionState = ref(createDisconnectedState()); const startDisabeld = ref(true); const pauseDisabled = ref(true); +const runningScriptName = ref(""); const controlSourceDetailRef = ref>(); const controlContent = ref({ @@ -171,6 +177,9 @@ const closeSocket = () => { const isSourceSwitchEnabled = computed(() => isSourceSelectable(connectionState.value)); const isConnectButtonEnabled = computed(() => canConnect(connectionState.value)); const connectionStatusText = computed(() => getConnectionStatusText(connectionState.value)); +const runningScriptStatusText = computed(() => + runningScriptName.value ? `当前正在加量的脚本:${runningScriptName.value}` : "当前无正在加量脚本" +); const connectionStatusColor = computed(() => { switch (connectionState.value.status) { case "connecting": @@ -363,6 +372,7 @@ watch( resetConnectionState(); startDisabeld.value = true; pauseDisabled.value = true; + runningScriptName.value = ""; controlSourceDetailRef.value?.stopTimeCount(); } ); @@ -481,9 +491,37 @@ const start = async () => { align-items: center; gap: 8px; color: var(--el-text-color-regular); + min-width: 0; + white-space: nowrap; + overflow: hidden; +} + +.connection-status-left { + flex: 0 0 10%; + min-width: 0; + display: flex; + align-items: center; + gap: 8px; + overflow: hidden; +} + +.connection-status-text { + min-width: 0; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.running-script-status { + flex: 0 0 80%; + min-width: 0; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; } .connection-status-dot { + flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%;