refactor(Scheduler): 重构调度台界面和逻辑
This commit is contained in:
@@ -42,7 +42,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-else class="task-panels">
|
<div v-else class="task-panels">
|
||||||
<a-collapse v-model:activeKey="currentTab.activeTaskPanels">
|
<a-collapse v-model:activeKey="currentTab.activeTaskPanels"
|
||||||
|
:key="`collapse-${currentTab.key}-${currentTab.runningTasks.length}`">
|
||||||
<a-collapse-panel v-for="task in currentTab.runningTasks" :key="task.websocketId"
|
<a-collapse-panel v-for="task in currentTab.runningTasks" :key="task.websocketId"
|
||||||
:header="`任务: ${task.taskName}`" style="font-size: 16px; margin-left: 8px">
|
:header="`任务: ${task.taskName}`" style="font-size: 16px; margin-left: 8px">
|
||||||
<template #extra>
|
<template #extra>
|
||||||
@@ -92,18 +93,18 @@
|
|||||||
<!-- 用户队列 -->
|
<!-- 用户队列 -->
|
||||||
<a-col :span="5">
|
<a-col :span="5">
|
||||||
<a-card title="用户队列" size="small" style="height: 100%">
|
<a-card title="用户队列" size="small" style="height: 100%">
|
||||||
<!-- <template #extra>-->
|
<!-- <template #extra>-->
|
||||||
<!-- <span style="font-size: 12px; color: #666;">{{ task.userQueue.length }} 项</span>-->
|
<!-- <span style="font-size: 12px; color: #666;">{{ task.userQueue.length }} 项</span>-->
|
||||||
<!-- </template>-->
|
<!-- </template>-->
|
||||||
<div style="height: calc(100% - 40px); padding: 8px;">
|
<div style="height: calc(100% - 40px); padding: 8px;">
|
||||||
<!-- <!– 调试信息 –>-->
|
<!-- <!– 调试信息 –>-->
|
||||||
<!-- <div v-if="task.userQueue.length === 0"-->
|
<!-- <div v-if="task.userQueue.length === 0"-->
|
||||||
<!-- style="color: #999; font-size: 12px; margin-bottom: 8px;">-->
|
<!-- style="color: #999; font-size: 12px; margin-bottom: 8px;">-->
|
||||||
<!-- 调试: userQueue 长度为 {{ task.userQueue.length }}-->
|
<!-- 调试: userQueue 长度为 {{ task.userQueue.length }}-->
|
||||||
<!-- </div>-->
|
<!-- </div>-->
|
||||||
<!-- <div v-else style="color: #999; font-size: 12px; margin-bottom: 8px;">-->
|
<!-- <div v-else style="color: #999; font-size: 12px; margin-bottom: 8px;">-->
|
||||||
<!-- 调试: 找到 {{ task.userQueue.length }} 个队列项-->
|
<!-- 调试: 找到 {{ task.userQueue.length }} 个队列项-->
|
||||||
<!-- </div>-->
|
<!-- </div>-->
|
||||||
|
|
||||||
<a-list :data-source="task.userQueue" size="small" :locale="{ emptyText: '暂无用户队列' }"
|
<a-list :data-source="task.userQueue" size="small" :locale="{ emptyText: '暂无用户队列' }"
|
||||||
style="height: calc(100% - 30px); overflow-y: auto">
|
style="height: calc(100% - 30px); overflow-y: auto">
|
||||||
@@ -447,25 +448,66 @@ const startQuickTask = async () => {
|
|||||||
const selectedOption = taskOptions.value.find(option => option.value === quickTaskForm.taskId)
|
const selectedOption = taskOptions.value.find(option => option.value === quickTaskForm.taskId)
|
||||||
const taskName = selectedOption?.label || '未知任务'
|
const taskName = selectedOption?.label || '未知任务'
|
||||||
|
|
||||||
// 创建任务并添加到当前调度台
|
// 检查是否已存在同名任务
|
||||||
const task: RunningTask = {
|
const existingTaskIndex = currentTab.value.runningTasks.findIndex(t => t.taskName === taskName)
|
||||||
websocketId: response.websocketId,
|
|
||||||
taskName,
|
if (existingTaskIndex >= 0) {
|
||||||
status: '连接中',
|
// 如果存在同名任务,复用现有任务卡片
|
||||||
websocket: null,
|
const existingTask = currentTab.value.runningTasks[existingTaskIndex]
|
||||||
logs: [],
|
|
||||||
taskQueue: [],
|
// 关闭旧的WebSocket连接(如果存在)
|
||||||
userQueue: [],
|
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.taskId = null
|
||||||
quickTaskForm.mode = '自动代理'
|
quickTaskForm.mode = '自动代理'
|
||||||
@@ -705,7 +747,7 @@ const executeCompletionAction = (action: string) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加任务日志
|
// 添加任务日志 - 使用 websocketId 而不是 task 对象
|
||||||
const addTaskLog = (
|
const addTaskLog = (
|
||||||
task: RunningTask,
|
task: RunningTask,
|
||||||
message: string,
|
message: string,
|
||||||
@@ -714,22 +756,32 @@ const addTaskLog = (
|
|||||||
const now = new Date()
|
const now = new Date()
|
||||||
const time = now.toLocaleTimeString()
|
const time = now.toLocaleTimeString()
|
||||||
|
|
||||||
// 找到任务在当前调度台中的索引
|
// 在所有调度台中查找正确的任务
|
||||||
const taskIndex = currentTab.value.runningTasks.findIndex(t => t.websocketId === task.websocketId)
|
let foundTask = false
|
||||||
if (taskIndex >= 0) {
|
for (const tab of schedulerTabs.value) {
|
||||||
// 直接修改 reactive 数组中的任务对象
|
const taskIndex = tab.runningTasks.findIndex(t => t.websocketId === task.websocketId)
|
||||||
currentTab.value.runningTasks[taskIndex].logs.push({
|
if (taskIndex >= 0) {
|
||||||
time,
|
// 直接修改 reactive 数组中的任务对象
|
||||||
message,
|
tab.runningTasks[taskIndex].logs.push({
|
||||||
type,
|
time,
|
||||||
})
|
message,
|
||||||
|
type,
|
||||||
|
})
|
||||||
|
|
||||||
// 更新任务状态(如果有变化)
|
// 更新任务状态(如果有变化)
|
||||||
if (currentTab.value.runningTasks[taskIndex].status !== task.status) {
|
if (tab.runningTasks[taskIndex].status !== task.status) {
|
||||||
currentTab.value.runningTasks[taskIndex].status = task.status
|
tab.runningTasks[taskIndex].status = task.status
|
||||||
|
}
|
||||||
|
|
||||||
|
foundTask = true
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!foundTask) {
|
||||||
|
console.warn('未找到对应的任务来添加日志,websocketId:', task.websocketId)
|
||||||
|
}
|
||||||
|
|
||||||
// 自动滚动到底部
|
// 自动滚动到底部
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
const outputElement = outputRefs.value.get(task.websocketId)
|
const outputElement = outputRefs.value.get(task.websocketId)
|
||||||
|
|||||||
Reference in New Issue
Block a user