chore: try to add stop task more info #75
This commit is contained in:
@@ -18,6 +18,7 @@ const props = withDefaults(defineProps<{
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:open': [value: boolean]
|
||||
'stop': []
|
||||
}>()
|
||||
|
||||
const isFullscreen = ref(false)
|
||||
@@ -74,6 +75,7 @@ onUnmounted(() => {
|
||||
:empty-description="emptyDescription"
|
||||
@close="close"
|
||||
@maximize="isFullscreen = !isFullscreen"
|
||||
@stop="$emit('stop')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -205,23 +205,41 @@ async function deleteTask() {
|
||||
}
|
||||
|
||||
const executingTaskId = ref<string | null>(null)
|
||||
const isStopping = ref(false)
|
||||
|
||||
async function runTask(id: string) {
|
||||
if (executingTaskId.value) return
|
||||
executingTaskId.value = id
|
||||
toast.message('正在执行...', { id: 'executing' })
|
||||
try {
|
||||
const res = await api.tasks.execute(id)
|
||||
if (res.Success === false) {
|
||||
throw new Error(res.Error || '执行失败')
|
||||
toast.success('执行指令已发送')
|
||||
if (res.log_id) {
|
||||
// 开启日志查看器
|
||||
viewLogs(id)
|
||||
}
|
||||
toast.success('触发成功', { id: 'executing' })
|
||||
} catch (error: any) {
|
||||
toast.error(error?.message || '执行失败', { id: 'executing' })
|
||||
toast.error(error.message || '执行失败')
|
||||
} finally {
|
||||
executingTaskId.value = null
|
||||
}
|
||||
}
|
||||
|
||||
async function handleStopTask() {
|
||||
if (!selectedLog.value || isStopping.value) return
|
||||
|
||||
isStopping.value = true
|
||||
try {
|
||||
await api.tasks.stop(selectedLog.value.id)
|
||||
toast.success('停止指令已发送')
|
||||
} catch (error: any) {
|
||||
toast.error(error.message || '停止失败')
|
||||
// 出错时也尝试刷新,因为后端可能已经自动修正了“僵尸”状态
|
||||
loadTasks()
|
||||
} finally {
|
||||
isStopping.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleTask(task: Task, enabled: boolean) {
|
||||
try {
|
||||
await api.tasks.update(task.id, { ...task, enabled })
|
||||
@@ -830,8 +848,10 @@ watch(() => route.query.agent_id, (newVal: any) => {
|
||||
variant="full"
|
||||
:log="selectedLog"
|
||||
:content="displayLogContent"
|
||||
:is-stopping="isStopping"
|
||||
:empty-title="logEmptyTitle"
|
||||
:empty-description="logEmptyDesc" />
|
||||
:empty-description="logEmptyDesc"
|
||||
@stop="handleStopTask" />
|
||||
|
||||
|
||||
<!-- 删除确认 (批量) -->
|
||||
|
||||
Reference in New Issue
Block a user