feat: add startup task and fix backup import

This commit is contained in:
engigu
2026-02-26 10:43:49 +08:00
parent afb412e71c
commit acc65dce64
12 changed files with 131 additions and 66 deletions
View File
+1
View File
@@ -266,6 +266,7 @@ export interface Task {
name: string
command: string
type: string
trigger_type: string
config: string
schedule: string
timeout: number
+6
View File
@@ -34,6 +34,12 @@ export const TASK_TYPE = {
REPO: 'repo',
} as const
// 触发类型
export const TRIGGER_TYPE = {
CRON: 'cron',
BAIHU_STARTUP: 'baihu_startup',
} as const
// Agent 状态
export const AGENT_STATUS = {
ONLINE: 'online',
+20
View File
@@ -12,6 +12,7 @@ import DirTreeSelect from '@/components/DirTreeSelect.vue'
import { Plus, ChevronDown, X, Search, Check, ChevronsUpDown, Loader2, AlertCircle } from 'lucide-vue-next'
import { cn } from '@/lib/utils'
import { api, type Task, type EnvVar, type Agent, type MiseLanguage } from '@/api'
import { TRIGGER_TYPE } from '@/constants'
import { toast } from 'vue-sonner'
const props = defineProps<{
@@ -44,6 +45,7 @@ const allEnvVars = ref<EnvVar[]>([])
const allAgents = ref<Agent[]>([])
const selectedEnvIds = ref<number[]>([])
const selectedAgentId = ref<string>('local')
const selectedTriggerType = ref<string>('cron')
const envSearchQuery = ref('')
// 为每个执行位置保存独立的工作目录配置
const workDirCache = ref<Record<string, string>>({})
@@ -254,6 +256,8 @@ watch(() => props.open, async (val) => {
// 解析 Agent 和工作目录
const agentId = props.task?.agent_id ? String(props.task.agent_id) : 'local'
selectedAgentId.value = agentId
// 解析触发类型
selectedTriggerType.value = props.task?.trigger_type || TRIGGER_TYPE.CRON
// 初始化工作目录缓存,将当前任务的工作目录保存到对应的执行位置
workDirCache.value = {
[agentId]: props.task?.work_dir || ''
@@ -298,6 +302,7 @@ async function save() {
form.value.clean_config = cleanConfig.value
form.value.envs = selectedEnvIds.value.join(',')
form.value.type = 'task'
form.value.trigger_type = selectedTriggerType.value
form.value.agent_id = selectedAgentId.value === 'local' ? null : Number(selectedAgentId.value)
// 保存语言环境配置
@@ -374,6 +379,21 @@ async function save() {
</div>
</div>
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-2 sm:gap-3">
<Label class="sm:text-right text-sm">触发类型</Label>
<div class="sm:col-span-3">
<Select v-model="selectedTriggerType">
<SelectTrigger class="h-8 text-sm">
<SelectValue placeholder="定时触发" />
</SelectTrigger>
<SelectContent>
<SelectItem :value="TRIGGER_TYPE.CRON">定时触发</SelectItem>
<SelectItem :value="TRIGGER_TYPE.BAIHU_STARTUP">服务启动时触发</SelectItem>
</SelectContent>
</Select>
</div>
</div>
<!-- 本地任务语言版本配置 -->
<template v-if="selectedAgentId === 'local'">
<div class="grid grid-cols-1 sm:grid-cols-4 items-start gap-2 sm:gap-3">
+5 -3
View File
@@ -11,7 +11,7 @@ import { api, type Task, type Agent } from '@/api'
import { toast } from 'vue-sonner'
import { useSiteSettings } from '@/composables/useSiteSettings'
import { useRouter, useRoute } from 'vue-router'
import { TASK_TYPE, AGENT_STATUS } from '@/constants'
import { TASK_TYPE, AGENT_STATUS, TRIGGER_TYPE } from '@/constants'
import TextOverflow from '@/components/TextOverflow.vue'
const router = useRouter()
@@ -261,8 +261,10 @@ watch(() => route.query.agent_id, (newVal) => {
class="w-32 sm:flex-1 shrink-0 sm:shrink text-muted-foreground truncate text-xs bg-muted/40 px-2 py-1 rounded hidden sm:block">
<TextOverflow :text="task.command" :title="task.type === TASK_TYPE.REPO ? '同步地址' : '执行命令'" />
</code>
<code class="w-36 shrink-0 text-muted-foreground text-xs bg-muted/40 px-2 py-1 rounded hidden md:block">{{ task.schedule
}}</code>
<div class="w-36 shrink-0 hidden md:flex flex-col items-start justify-center gap-1 overflow-hidden">
<span v-if="task.trigger_type === TRIGGER_TYPE.BAIHU_STARTUP" class="text-[10px] leading-none bg-primary/10 text-primary px-1.5 py-1 rounded whitespace-nowrap border border-primary/20">服务启动时</span>
<code v-else-if="task.schedule" class="text-muted-foreground text-xs bg-muted/40 px-1.5 py-0.5 rounded truncate max-w-full" :title="task.schedule">{{ task.schedule }}</code>
</div>
<span class="w-40 shrink-0 text-muted-foreground text-xs hidden lg:block">{{ task.last_run || '-' }}</span>
<span class="w-40 shrink-0 text-muted-foreground text-xs hidden lg:block">{{ task.next_run || '-' }}</span>
<span class="w-8 sm:w-12 flex justify-center shrink-0 cursor-pointer group"