diff --git a/frontend/src/views/Scheduler.vue b/frontend/src/views/Scheduler.vue
index 1bb6822..47ad97d 100644
--- a/frontend/src/views/Scheduler.vue
+++ b/frontend/src/views/Scheduler.vue
@@ -42,7 +42,8 @@
-
+
@@ -92,18 +93,18 @@
-
-
-
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
@@ -447,25 +448,66 @@ const startQuickTask = async () => {
const selectedOption = taskOptions.value.find(option => option.value === quickTaskForm.taskId)
const taskName = selectedOption?.label || '未知任务'
- // 创建任务并添加到当前调度台
- const task: RunningTask = {
- websocketId: response.websocketId,
- taskName,
- status: '连接中',
- websocket: null,
- logs: [],
- taskQueue: [],
- userQueue: [],
+ // 检查是否已存在同名任务
+ const existingTaskIndex = currentTab.value.runningTasks.findIndex(t => t.taskName === taskName)
+
+ if (existingTaskIndex >= 0) {
+ // 如果存在同名任务,复用现有任务卡片
+ const existingTask = currentTab.value.runningTasks[existingTaskIndex]
+
+ // 关闭旧的WebSocket连接(如果存在)
+ if (existingTask.websocket) {
+ existingTask.websocket.close()
+ }
+
+ // 保存旧的 websocketId
+ const oldWebsocketId = existingTask.websocketId
+
+ // 更新任务信息
+ existingTask.websocketId = response.websocketId
+ existingTask.status = '连接中'
+ existingTask.websocket = null
+ existingTask.userQueue = []
+
+ // 添加分隔日志
+ existingTask.logs.push({
+ time: new Date().toLocaleTimeString(),
+ message: '========== 新任务开始 ==========',
+ type: 'info'
+ })
+
+ // 更新 activeTaskPanels 数组:移除旧ID,添加新ID
+ const oldPanelIndex = currentTab.value.activeTaskPanels.indexOf(oldWebsocketId)
+ if (oldPanelIndex >= 0) {
+ currentTab.value.activeTaskPanels.splice(oldPanelIndex, 1)
+ }
+ currentTab.value.activeTaskPanels.push(existingTask.websocketId)
+
+ // 连接新的WebSocket
+ connectWebSocket(existingTask)
+
+ message.success('任务启动成功')
+ } else {
+ // 如果不存在同名任务,创建新任务
+ const task: RunningTask = {
+ websocketId: response.websocketId,
+ taskName,
+ status: '连接中',
+ websocket: null,
+ logs: [],
+ taskQueue: [],
+ userQueue: [],
+ }
+
+ currentTab.value.runningTasks.push(task)
+ currentTab.value.activeTaskPanels.push(task.websocketId)
+
+ // 连接WebSocket
+ connectWebSocket(task)
+
+ message.success('任务启动成功')
}
- currentTab.value.runningTasks.push(task)
- currentTab.value.activeTaskPanels.push(task.websocketId)
-
- // 连接WebSocket
- connectWebSocket(task)
-
- message.success('任务启动成功')
-
// 重置表单
quickTaskForm.taskId = null
quickTaskForm.mode = '自动代理'
@@ -705,7 +747,7 @@ const executeCompletionAction = (action: string) => {
}
}
-// 添加任务日志
+// 添加任务日志 - 使用 websocketId 而不是 task 对象
const addTaskLog = (
task: RunningTask,
message: string,
@@ -714,22 +756,32 @@ const addTaskLog = (
const now = new Date()
const time = now.toLocaleTimeString()
- // 找到任务在当前调度台中的索引
- const taskIndex = currentTab.value.runningTasks.findIndex(t => t.websocketId === task.websocketId)
- if (taskIndex >= 0) {
- // 直接修改 reactive 数组中的任务对象
- currentTab.value.runningTasks[taskIndex].logs.push({
- time,
- message,
- type,
- })
+ // 在所有调度台中查找正确的任务
+ let foundTask = false
+ for (const tab of schedulerTabs.value) {
+ const taskIndex = tab.runningTasks.findIndex(t => t.websocketId === task.websocketId)
+ if (taskIndex >= 0) {
+ // 直接修改 reactive 数组中的任务对象
+ tab.runningTasks[taskIndex].logs.push({
+ time,
+ message,
+ type,
+ })
- // 更新任务状态(如果有变化)
- if (currentTab.value.runningTasks[taskIndex].status !== task.status) {
- currentTab.value.runningTasks[taskIndex].status = task.status
+ // 更新任务状态(如果有变化)
+ if (tab.runningTasks[taskIndex].status !== task.status) {
+ tab.runningTasks[taskIndex].status = task.status
+ }
+
+ foundTask = true
+ break
}
}
+ if (!foundTask) {
+ console.warn('未找到对应的任务来添加日志,websocketId:', task.websocketId)
+ }
+
// 自动滚动到底部
nextTick(() => {
const outputElement = outputRefs.value.get(task.websocketId)