fix: 修复定时任务的调度台创建方法

This commit is contained in:
DLmaster361
2025-09-24 18:11:48 +08:00
parent ff8f501b98
commit cf4c8cfe17

View File

@@ -10,6 +10,7 @@ import {
getPowerActionText, getPowerActionText,
type SchedulerTab, type SchedulerTab,
type TaskMessage, type TaskMessage,
type SchedulerStatus,
} from './schedulerConstants' } from './schedulerConstants'
// 电源操作状态仍然保存到localStorage中以便重启后保持用户设置 // 电源操作状态仍然保存到localStorage中以便重启后保持用户设置
@@ -133,39 +134,19 @@ export function useSchedulerLogic() {
} }
const createSchedulerTabForTask = (taskId: string) => { const createSchedulerTabForTask = (taskId: string) => {
// 检查是否已经存在相同websocketId的调度台
const existingTab = schedulerTabs.value.find(tab => tab.websocketId === taskId)
if (existingTab) {
console.log('[Scheduler] 调度台已存在,切换到该调度台:', existingTab.title)
activeSchedulerTab.value = existingTab.key
return
}
// 创建新调度台 // 使用现有的addSchedulerTab函数创建新调度台,并传入特定的配置选项
tabCounter++ const newTab = addSchedulerTab({
const tab: SchedulerTab = { title: `调度台${tabCounter}`,
key: `tab-${tabCounter}`, status: '运行',
title: `自动调度台${tabCounter}`, websocketId: taskId,
closable: true, })
status: '运行', // 直接设置为运行状态
selectedTaskId: null,
selectedMode: TaskCreateIn.mode.AutoMode,
websocketId: taskId, // 设置websocketId
taskQueue: [],
userQueue: [],
logs: [],
isLogAtBottom: true,
lastLogContent: '',
}
schedulerTabs.value.push(tab)
activeSchedulerTab.value = tab.key
// 立即订阅该任务的WebSocket消息 // 立即订阅该任务的WebSocket消息
subscribeToTask(tab) subscribeToTask(newTab)
console.log('[Scheduler] 已创建新的自动调度台:', tab.title, '任务ID:', taskId) console.log('[Scheduler] 已创建新的自动调度台:', newTab.title, '任务ID:', taskId)
message.success(`已自动创建调度台: ${tab.title}`) message.success(`已自动创建调度台: ${newTab.title}`)
saveTabsToStorage(schedulerTabs.value) saveTabsToStorage(schedulerTabs.value)
} }
@@ -195,16 +176,23 @@ export function useSchedulerLogic() {
watchTabsChanges() watchTabsChanges()
// Tab 管理 // Tab 管理
const addSchedulerTab = () => { const addSchedulerTab = (options?: { title?: string, status?: string, websocketId?: string }) => {
tabCounter++ tabCounter++
const status = options?.status || '新建'
// 使用更安全的类型断言确保状态值是有效的SchedulerStatus
const validStatus: SchedulerStatus =
['新建', '运行', '等待', '结束', '异常'].includes(status) ?
status as SchedulerStatus :
'新建'
const tab: SchedulerTab = { const tab: SchedulerTab = {
key: `tab-${tabCounter}`, key: `tab-${tabCounter}`,
title: `调度台${tabCounter}`, title: options?.title || `调度台${tabCounter}`,
closable: true, closable: true,
status: '新建', status: validStatus,
selectedTaskId: null, selectedTaskId: null,
selectedMode: TaskCreateIn.mode.AutoMode, selectedMode: TaskCreateIn.mode.AutoMode,
websocketId: null, websocketId: options?.websocketId || null,
taskQueue: [], taskQueue: [],
userQueue: [], userQueue: [],
logs: [], logs: [],
@@ -213,6 +201,8 @@ export function useSchedulerLogic() {
} }
schedulerTabs.value.push(tab) schedulerTabs.value.push(tab)
activeSchedulerTab.value = tab.key activeSchedulerTab.value = tab.key
return tab
} }
const removeSchedulerTab = (key: string) => { const removeSchedulerTab = (key: string) => {
@@ -932,5 +922,4 @@ export function useSchedulerLogic() {
// 任务总览面板引用管理 // 任务总览面板引用管理
setOverviewRef, setOverviewRef,
} }
} }