2025-12-25 20:28:20 +08:00
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { ref, computed, watch } from 'vue'
|
|
|
|
|
import { Button } from '@/components/ui/button'
|
2026-03-06 14:13:37 +08:00
|
|
|
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'
|
2025-12-25 20:28:20 +08:00
|
|
|
import { Input } from '@/components/ui/input'
|
|
|
|
|
import { Label } from '@/components/ui/label'
|
2026-02-07 21:44:09 +08:00
|
|
|
import { Switch } from '@/components/ui/switch'
|
2025-12-25 20:28:20 +08:00
|
|
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
|
|
|
|
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
|
2026-02-13 17:27:55 +08:00
|
|
|
import { ScrollArea } from '@/components/ui/scroll-area'
|
2025-12-25 20:28:20 +08:00
|
|
|
import DirTreeSelect from '@/components/DirTreeSelect.vue'
|
2026-04-01 10:58:24 +08:00
|
|
|
import { Plus, ChevronDown, X, Search, Check, ChevronsUpDown, AlertCircle, Terminal, Zap, Loader2 } from 'lucide-vue-next'
|
2026-02-13 17:27:55 +08:00
|
|
|
import { cn } from '@/lib/utils'
|
2026-03-25 09:39:52 +08:00
|
|
|
import { api, type Task, type EnvVar, type Agent, type MiseLanguage } from '@/api'
|
2026-04-01 10:58:24 +08:00
|
|
|
import { PATHS, TRIGGER_TYPE } from '@/constants'
|
2025-12-25 20:28:20 +08:00
|
|
|
import { toast } from 'vue-sonner'
|
2026-03-18 09:08:40 +08:00
|
|
|
import { getCronDescription } from '@/utils/cron'
|
2026-03-25 09:39:52 +08:00
|
|
|
import TaskNotificationConfig from './components/TaskNotificationConfig.vue'
|
2025-12-25 20:28:20 +08:00
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
|
open: boolean
|
|
|
|
|
task?: Partial<Task>
|
|
|
|
|
isEdit: boolean
|
|
|
|
|
}>()
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
|
'update:open': [value: boolean]
|
|
|
|
|
'saved': []
|
|
|
|
|
}>()
|
|
|
|
|
|
|
|
|
|
const cronPresets = [
|
|
|
|
|
{ label: '每5秒', value: '*/5 * * * * *' },
|
|
|
|
|
{ label: '每30秒', value: '*/30 * * * * *' },
|
|
|
|
|
{ label: '每分钟', value: '0 * * * * *' },
|
|
|
|
|
{ label: '每5分钟', value: '0 */5 * * * *' },
|
|
|
|
|
{ label: '每小时', value: '0 0 * * * *' },
|
|
|
|
|
{ label: '每天0点', value: '0 0 0 * * *' },
|
|
|
|
|
{ label: '每天8点', value: '0 0 8 * * *' },
|
|
|
|
|
{ label: '每周一', value: '0 0 0 * * 1' },
|
|
|
|
|
{ label: '每月1号', value: '0 0 0 1 * *' },
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
const form = ref<Partial<Task>>({})
|
2026-02-26 20:29:20 +08:00
|
|
|
const tagInput = ref('')
|
2025-12-25 20:28:20 +08:00
|
|
|
const cleanType = ref('none')
|
|
|
|
|
const cleanKeep = ref(30)
|
|
|
|
|
const allEnvVars = ref<EnvVar[]>([])
|
2025-12-28 11:42:58 +08:00
|
|
|
const allAgents = ref<Agent[]>([])
|
2026-03-03 17:25:38 +08:00
|
|
|
const selectedEnvIds = ref<string[]>([])
|
2025-12-28 11:42:58 +08:00
|
|
|
const selectedAgentId = ref<string>('local')
|
2026-02-26 10:43:49 +08:00
|
|
|
const selectedTriggerType = ref<string>('cron')
|
2025-12-25 20:28:20 +08:00
|
|
|
const envSearchQuery = ref('')
|
2026-01-02 11:45:29 +08:00
|
|
|
// 为每个执行位置保存独立的工作目录配置
|
|
|
|
|
const workDirCache = ref<Record<string, string>>({})
|
2026-02-07 21:44:09 +08:00
|
|
|
const concurrency = ref(0)
|
|
|
|
|
const concurrencyEnabled = ref(false)
|
2026-03-06 14:13:37 +08:00
|
|
|
const allEnvsEnabled = ref(false)
|
2026-03-25 09:39:52 +08:00
|
|
|
const SCRIPTS_DIR_PLACEHPLDER = '$SCRIPTS_DIR$'
|
2026-03-19 17:08:16 +08:00
|
|
|
const scriptsDir = ref<string>(PATHS.SCRIPTS_DIR)
|
2026-02-07 21:44:09 +08:00
|
|
|
|
2026-03-18 09:08:40 +08:00
|
|
|
const cronDescription = computed(() => {
|
|
|
|
|
if (!form.value.schedule) return ''
|
|
|
|
|
return getCronDescription(form.value.schedule, (navigator as any).language)
|
|
|
|
|
})
|
|
|
|
|
|
2026-04-01 10:58:24 +08:00
|
|
|
|
2026-03-24 11:48:11 +08:00
|
|
|
|
2026-02-07 21:44:09 +08:00
|
|
|
// 监听 concurrencyEnabled 的变化,同步到 concurrency
|
|
|
|
|
watch(concurrencyEnabled, (val) => {
|
|
|
|
|
concurrency.value = val ? 1 : 0
|
|
|
|
|
})
|
2026-01-02 11:45:29 +08:00
|
|
|
|
2026-04-01 10:58:24 +08:00
|
|
|
|
2026-03-06 14:13:37 +08:00
|
|
|
|
|
|
|
|
function onAllEnvsChange(val: boolean) {
|
|
|
|
|
allEnvsEnabled.value = val
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-26 20:29:20 +08:00
|
|
|
function addTag() {
|
|
|
|
|
const val = tagInput.value.trim()
|
|
|
|
|
if (!val) return
|
|
|
|
|
const currentTags = form.value.tags ? form.value.tags.split(',').filter(Boolean) : []
|
|
|
|
|
if (!currentTags.includes(val)) {
|
|
|
|
|
currentTags.push(val)
|
|
|
|
|
form.value.tags = currentTags.join(',')
|
|
|
|
|
}
|
|
|
|
|
tagInput.value = ''
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function removeTag(tagToRemove: string) {
|
|
|
|
|
const currentTags = form.value.tags ? form.value.tags.split(',').filter(Boolean) : []
|
|
|
|
|
form.value.tags = currentTags.filter(t => t !== tagToRemove).join(',')
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-02 11:45:29 +08:00
|
|
|
// 当前显示的工作目录(根据选择的执行位置)
|
|
|
|
|
const currentWorkDir = computed({
|
|
|
|
|
get: () => workDirCache.value[selectedAgentId.value] || '',
|
|
|
|
|
set: (val) => {
|
|
|
|
|
workDirCache.value[selectedAgentId.value] = val
|
|
|
|
|
}
|
|
|
|
|
})
|
2025-12-25 20:28:20 +08:00
|
|
|
|
|
|
|
|
const cleanConfig = computed(() => {
|
|
|
|
|
if (!cleanType.value || cleanType.value === 'none' || cleanKeep.value <= 0) return ''
|
|
|
|
|
return JSON.stringify({ type: cleanType.value, keep: cleanKeep.value })
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const filteredEnvVars = computed(() => {
|
|
|
|
|
return allEnvVars.value.filter(env => {
|
|
|
|
|
const matchSearch = !envSearchQuery.value || env.name.toLowerCase().includes(envSearchQuery.value.toLowerCase())
|
|
|
|
|
const notSelected = !selectedEnvIds.value.includes(env.id)
|
|
|
|
|
return matchSearch && notSelected
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const selectedEnvs = computed(() => {
|
|
|
|
|
return selectedEnvIds.value
|
|
|
|
|
.map(id => allEnvVars.value.find(e => e.id === id))
|
|
|
|
|
.filter((e): e is EnvVar => e !== undefined)
|
|
|
|
|
})
|
|
|
|
|
|
2025-12-28 11:42:58 +08:00
|
|
|
const onlineAgents = computed(() => {
|
|
|
|
|
return allAgents.value.filter(a => a.enabled)
|
|
|
|
|
})
|
|
|
|
|
|
2026-02-13 17:27:55 +08:00
|
|
|
// 语言环境相关
|
|
|
|
|
const installedLangs = ref<MiseLanguage[]>([])
|
|
|
|
|
const loadingLangs = ref(false)
|
2026-02-13 19:26:20 +08:00
|
|
|
const selectedLangs = ref<{ name: string; version: string; availableVersions: string[] }[]>([])
|
|
|
|
|
|
2026-02-13 17:27:55 +08:00
|
|
|
const availablePlugins = ref<string[]>([])
|
|
|
|
|
const pluginSearch = ref('')
|
|
|
|
|
const versionSearch = ref('')
|
|
|
|
|
|
2026-03-25 09:39:52 +08:00
|
|
|
const notificationConfigRef = ref<InstanceType<typeof TaskNotificationConfig> | null>(null)
|
2026-03-25 07:31:45 +08:00
|
|
|
|
2026-02-13 17:27:55 +08:00
|
|
|
const filteredPlugins = computed(() => {
|
|
|
|
|
if (!pluginSearch.value) return availablePlugins.value
|
|
|
|
|
const s = pluginSearch.value.toLowerCase()
|
|
|
|
|
return availablePlugins.value.filter(p => p.toLowerCase().includes(s))
|
|
|
|
|
})
|
|
|
|
|
|
2026-02-13 19:26:20 +08:00
|
|
|
function getFilteredVersions(versions: string[]) {
|
|
|
|
|
if (!versionSearch.value) return versions
|
2026-02-13 17:27:55 +08:00
|
|
|
const s = versionSearch.value.toLowerCase()
|
2026-02-13 19:26:20 +08:00
|
|
|
return versions.filter(v => v.toLowerCase().includes(s))
|
|
|
|
|
}
|
2026-02-13 17:27:55 +08:00
|
|
|
|
|
|
|
|
async function fetchInstalledLangs() {
|
|
|
|
|
loadingLangs.value = true
|
|
|
|
|
try {
|
|
|
|
|
installedLangs.value = await api.mise.list()
|
|
|
|
|
const plugins = new Set<string>()
|
|
|
|
|
installedLangs.value.forEach(l => plugins.add(l.plugin))
|
|
|
|
|
availablePlugins.value = Array.from(plugins).sort()
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('Fetch installed langs failed', e)
|
|
|
|
|
} finally {
|
|
|
|
|
loadingLangs.value = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getLangIcon(plugin: string) {
|
|
|
|
|
const name = plugin?.toLowerCase().trim()
|
|
|
|
|
const mapping: Record<string, string> = {
|
|
|
|
|
'python': 'python/python-original.svg',
|
|
|
|
|
'node': 'nodejs/nodejs-original.svg',
|
|
|
|
|
'nodejs': 'nodejs/nodejs-original.svg',
|
|
|
|
|
'go': 'go/go-original.svg',
|
|
|
|
|
'rust': 'rust/rust-original.svg',
|
|
|
|
|
'ruby': 'ruby/ruby-plain.svg',
|
|
|
|
|
'php': 'php/php-plain.svg',
|
|
|
|
|
'java': 'java/java-plain.svg',
|
|
|
|
|
'deno': 'deno/deno-plain.svg',
|
|
|
|
|
'bun': 'bun/bun-plain.svg',
|
|
|
|
|
'zig': 'zig/zig-original.svg',
|
|
|
|
|
'dotnet': 'dot-net/dot-net-original.svg',
|
|
|
|
|
'.net': 'dot-net/dot-net-original.svg',
|
|
|
|
|
'elixir': 'elixir/elixir-original.svg',
|
|
|
|
|
'erlang': 'erlang/erlang-original.svg',
|
|
|
|
|
'crystal': 'crystal/crystal-original.svg',
|
|
|
|
|
'lua': 'lua/lua-original.svg',
|
|
|
|
|
'julia': 'julia/julia-original.svg',
|
|
|
|
|
'nim': 'nim/nim-original.svg',
|
|
|
|
|
'perl': 'perl/perl-original.svg',
|
|
|
|
|
'scala': 'scala/scala-original.svg',
|
|
|
|
|
'kotlin': 'kotlin/kotlin-original.svg',
|
|
|
|
|
'clojure': 'clojure/clojure-line.svg',
|
|
|
|
|
'dart': 'dart/dart-original.svg',
|
|
|
|
|
'flutter': 'flutter/flutter-original.svg',
|
|
|
|
|
'terraform': 'terraform/terraform-original.svg',
|
|
|
|
|
'docker': 'docker/docker-original.svg',
|
|
|
|
|
'kubernetes': 'kubernetes/kubernetes-plain.svg',
|
|
|
|
|
'ansible': 'ansible/ansible-original.svg',
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mapping[name]) {
|
2026-03-11 10:59:25 +08:00
|
|
|
return `https://fastly.jsdelivr.net/gh/devicons/devicon/icons/${mapping[name]}`
|
2026-02-13 17:27:55 +08:00
|
|
|
}
|
|
|
|
|
return ''
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-13 19:26:20 +08:00
|
|
|
function updateAvailableVersions(lang: { name: string; version: string; availableVersions: string[] }) {
|
|
|
|
|
if (lang.name) {
|
|
|
|
|
lang.availableVersions = installedLangs.value
|
|
|
|
|
.filter(l => l.plugin === lang.name)
|
2026-02-13 17:27:55 +08:00
|
|
|
.map(l => l.version)
|
|
|
|
|
.sort((a, b) => b.localeCompare(a, undefined, { numeric: true }))
|
|
|
|
|
} else {
|
2026-02-13 19:26:20 +08:00
|
|
|
lang.availableVersions = []
|
2026-02-13 17:27:55 +08:00
|
|
|
}
|
2026-02-13 19:26:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function addLang() {
|
|
|
|
|
selectedLangs.value.push({ name: '', version: '', availableVersions: [] })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function removeLang(index: number) {
|
|
|
|
|
selectedLangs.value.splice(index, 1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateLangName(index: number, name: string) {
|
|
|
|
|
const lang = selectedLangs.value[index]
|
|
|
|
|
if (!lang) return
|
|
|
|
|
lang.name = name
|
|
|
|
|
lang.version = '' // reset version
|
|
|
|
|
updateAvailableVersions(lang)
|
|
|
|
|
}
|
2026-02-13 17:27:55 +08:00
|
|
|
|
2025-12-25 20:28:20 +08:00
|
|
|
watch(() => props.open, async (val) => {
|
|
|
|
|
if (val) {
|
2026-03-06 14:13:37 +08:00
|
|
|
form.value = {
|
|
|
|
|
retry_count: props.task?.retry_count ?? 0,
|
|
|
|
|
retry_interval: props.task?.retry_interval ?? 0,
|
|
|
|
|
random_range: props.task?.random_range ?? 0,
|
|
|
|
|
timeout: props.task?.timeout ?? 30,
|
|
|
|
|
...props.task
|
|
|
|
|
}
|
2025-12-25 20:28:20 +08:00
|
|
|
// 解析清理配置
|
|
|
|
|
if (props.task?.clean_config) {
|
|
|
|
|
try {
|
|
|
|
|
const config = JSON.parse(props.task.clean_config)
|
|
|
|
|
cleanType.value = config.type || 'none'
|
|
|
|
|
cleanKeep.value = config.keep || 30
|
|
|
|
|
} catch {
|
|
|
|
|
cleanType.value = 'none'
|
|
|
|
|
cleanKeep.value = 30
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
cleanType.value = 'none'
|
|
|
|
|
cleanKeep.value = 30
|
|
|
|
|
}
|
2026-02-07 21:44:09 +08:00
|
|
|
// 解析任务配置
|
|
|
|
|
try {
|
|
|
|
|
// 确保 config 是有效的 JSON 对象字符串
|
|
|
|
|
let configStr = props.task?.config
|
|
|
|
|
// 如果是 null/undefined 或者空字符串,初始化为 '{}'
|
|
|
|
|
if (!configStr) {
|
|
|
|
|
configStr = '{}'
|
|
|
|
|
}
|
2026-02-10 18:58:21 +08:00
|
|
|
|
2026-02-07 21:44:09 +08:00
|
|
|
const parsed = JSON.parse(configStr)
|
|
|
|
|
// 确保解析结果是对象
|
|
|
|
|
if (parsed && typeof parsed === 'object') {
|
|
|
|
|
const val = parsed['$task_concurrency']
|
|
|
|
|
if (typeof val === 'number') {
|
|
|
|
|
// 如果已存在并发配置,直接使用(0 或 1)
|
|
|
|
|
concurrency.value = val
|
|
|
|
|
concurrencyEnabled.value = val === 1
|
|
|
|
|
} else {
|
|
|
|
|
// 默认值:允许并发
|
|
|
|
|
concurrency.value = 1
|
|
|
|
|
concurrencyEnabled.value = true
|
|
|
|
|
}
|
2026-03-06 14:13:37 +08:00
|
|
|
|
|
|
|
|
// 解析全部环境变量配置
|
|
|
|
|
allEnvsEnabled.value = !!parsed['$task_all_envs']
|
2026-02-07 21:44:09 +08:00
|
|
|
} else {
|
|
|
|
|
concurrency.value = 1
|
|
|
|
|
concurrencyEnabled.value = true
|
2026-03-06 14:13:37 +08:00
|
|
|
allEnvsEnabled.value = false
|
2026-02-07 21:44:09 +08:00
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
concurrency.value = 1
|
|
|
|
|
concurrencyEnabled.value = true
|
|
|
|
|
}
|
2025-12-25 20:28:20 +08:00
|
|
|
// 解析环境变量
|
|
|
|
|
if (props.task?.envs) {
|
2026-03-03 17:25:38 +08:00
|
|
|
selectedEnvIds.value = props.task.envs.split(',').map(s => s.trim()).filter(Boolean)
|
2025-12-25 20:28:20 +08:00
|
|
|
} else {
|
|
|
|
|
selectedEnvIds.value = []
|
|
|
|
|
}
|
2026-02-13 19:26:20 +08:00
|
|
|
// 解析语言环境
|
|
|
|
|
selectedLangs.value = []
|
|
|
|
|
if (props.task?.languages && Array.isArray(props.task.languages)) {
|
|
|
|
|
selectedLangs.value = props.task.languages.map((l: any) => ({
|
|
|
|
|
name: l.name || '',
|
|
|
|
|
version: l.version || '',
|
|
|
|
|
availableVersions: []
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-02 11:45:29 +08:00
|
|
|
// 解析 Agent 和工作目录
|
|
|
|
|
const agentId = props.task?.agent_id ? String(props.task.agent_id) : 'local'
|
|
|
|
|
selectedAgentId.value = agentId
|
2026-02-26 10:43:49 +08:00
|
|
|
// 解析触发类型
|
|
|
|
|
selectedTriggerType.value = props.task?.trigger_type || TRIGGER_TYPE.CRON
|
2026-01-02 11:45:29 +08:00
|
|
|
// 初始化工作目录缓存,将当前任务的工作目录保存到对应的执行位置
|
|
|
|
|
workDirCache.value = {
|
|
|
|
|
[agentId]: props.task?.work_dir || ''
|
|
|
|
|
}
|
2025-12-25 20:28:20 +08:00
|
|
|
envSearchQuery.value = ''
|
2025-12-28 11:42:58 +08:00
|
|
|
// 加载数据
|
|
|
|
|
await loadData()
|
2026-03-19 16:08:02 +08:00
|
|
|
workDirCache.value = {
|
|
|
|
|
[agentId]: agentId === 'local'
|
|
|
|
|
? normalizeLocalWorkDirForDisplay(props.task?.work_dir)
|
|
|
|
|
: (props.task?.work_dir || '')
|
|
|
|
|
}
|
2026-02-13 17:27:55 +08:00
|
|
|
if (selectedAgentId.value === 'local') {
|
|
|
|
|
await fetchInstalledLangs()
|
2026-02-13 19:26:20 +08:00
|
|
|
// 更新所有语言的可用版本
|
|
|
|
|
selectedLangs.value.forEach(lang => {
|
|
|
|
|
updateAvailableVersions(lang)
|
|
|
|
|
})
|
2026-02-13 17:27:55 +08:00
|
|
|
}
|
2026-03-25 07:31:45 +08:00
|
|
|
// 加载通知配置
|
2026-03-25 09:39:52 +08:00
|
|
|
await notificationConfigRef.value?.loadConfig(props.isEdit ? props.task?.id : undefined)
|
2025-12-25 20:28:20 +08:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2025-12-28 11:42:58 +08:00
|
|
|
async function loadData() {
|
|
|
|
|
try {
|
2026-03-19 16:08:02 +08:00
|
|
|
const [envs, agents, paths] = await Promise.all([
|
2025-12-28 11:42:58 +08:00
|
|
|
api.env.all(),
|
2026-03-19 16:08:02 +08:00
|
|
|
api.agents.list(),
|
|
|
|
|
api.settings.getPaths().catch(() => ({ scripts_dir: PATHS.SCRIPTS_DIR }))
|
2025-12-28 11:42:58 +08:00
|
|
|
])
|
|
|
|
|
allEnvVars.value = envs
|
|
|
|
|
allAgents.value = agents
|
2026-03-19 16:08:02 +08:00
|
|
|
scriptsDir.value = paths?.scripts_dir || PATHS.SCRIPTS_DIR
|
2025-12-28 11:42:58 +08:00
|
|
|
} catch { /* ignore */ }
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-03 17:25:38 +08:00
|
|
|
function addEnv(id: string) {
|
2025-12-25 20:28:20 +08:00
|
|
|
if (!selectedEnvIds.value.includes(id)) {
|
|
|
|
|
selectedEnvIds.value.push(id)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-03 17:25:38 +08:00
|
|
|
function removeEnv(id: string) {
|
2026-01-15 19:18:50 +08:00
|
|
|
selectedEnvIds.value = selectedEnvIds.value.filter(envId => envId !== id)
|
2025-12-25 20:28:20 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-19 16:08:02 +08:00
|
|
|
function normalizeLocalWorkDirForDisplay(workDir?: string | null): string {
|
|
|
|
|
if (!workDir) return ''
|
2026-03-25 09:39:52 +08:00
|
|
|
if (workDir === SCRIPTS_DIR_PLACEHPLDER) return ''
|
|
|
|
|
if (workDir.startsWith(`${SCRIPTS_DIR_PLACEHPLDER}/`)) {
|
|
|
|
|
return workDir.slice(SCRIPTS_DIR_PLACEHPLDER.length + 1)
|
2026-03-19 16:08:02 +08:00
|
|
|
}
|
|
|
|
|
const base = scriptsDir.value || PATHS.SCRIPTS_DIR
|
|
|
|
|
if (workDir === base) return ''
|
|
|
|
|
if (workDir.startsWith(`${base}/`)) {
|
|
|
|
|
return workDir.slice(base.length + 1)
|
|
|
|
|
}
|
|
|
|
|
return workDir
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function encodeLocalWorkDir(workDir?: string | null): string {
|
|
|
|
|
const value = workDir?.trim() || ''
|
2026-03-25 09:39:52 +08:00
|
|
|
if (!value) return SCRIPTS_DIR_PLACEHPLDER
|
|
|
|
|
if (value === SCRIPTS_DIR_PLACEHPLDER || value.startsWith(`${SCRIPTS_DIR_PLACEHPLDER}/`)) {
|
2026-03-19 16:08:02 +08:00
|
|
|
return value
|
|
|
|
|
}
|
|
|
|
|
const base = scriptsDir.value || PATHS.SCRIPTS_DIR
|
2026-03-25 09:39:52 +08:00
|
|
|
if (value === base) return SCRIPTS_DIR_PLACEHPLDER
|
2026-03-19 16:08:02 +08:00
|
|
|
if (value.startsWith(`${base}/`)) {
|
2026-03-25 09:39:52 +08:00
|
|
|
return `${SCRIPTS_DIR_PLACEHPLDER}/${value.slice(base.length + 1)}`
|
2026-03-19 16:08:02 +08:00
|
|
|
}
|
2026-03-25 09:39:52 +08:00
|
|
|
return `${SCRIPTS_DIR_PLACEHPLDER}/${value.replace(/^\/+/, '')}`
|
2026-03-19 16:08:02 +08:00
|
|
|
}
|
|
|
|
|
|
2025-12-25 20:28:20 +08:00
|
|
|
async function save() {
|
|
|
|
|
try {
|
|
|
|
|
form.value.clean_config = cleanConfig.value
|
|
|
|
|
form.value.envs = selectedEnvIds.value.join(',')
|
|
|
|
|
form.value.type = 'task'
|
2026-02-26 10:43:49 +08:00
|
|
|
form.value.trigger_type = selectedTriggerType.value
|
2026-03-03 17:25:38 +08:00
|
|
|
form.value.agent_id = selectedAgentId.value === 'local' ? null : selectedAgentId.value
|
2026-02-10 18:58:21 +08:00
|
|
|
|
2026-02-13 19:26:20 +08:00
|
|
|
// 保存语言环境配置
|
|
|
|
|
form.value.languages = selectedLangs.value.map(l => ({
|
|
|
|
|
name: l.name,
|
|
|
|
|
version: l.version
|
|
|
|
|
}))
|
|
|
|
|
|
2026-02-07 21:44:09 +08:00
|
|
|
// 保存配置 - 确保 concurrency 字段被正确保存
|
|
|
|
|
let config: Record<string, any> = {}
|
2026-02-10 18:58:21 +08:00
|
|
|
|
2026-02-07 21:44:09 +08:00
|
|
|
// 如果 form.value.config 存在,先解析它以保留其他配置
|
|
|
|
|
if (form.value.config) {
|
|
|
|
|
try {
|
|
|
|
|
const parsed = JSON.parse(form.value.config)
|
|
|
|
|
if (parsed && typeof parsed === 'object') {
|
|
|
|
|
config = parsed
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
config = {}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-10 18:58:21 +08:00
|
|
|
|
2026-02-07 21:44:09 +08:00
|
|
|
// 更新并发控制字段 (1: 开启, 0: 关闭)
|
2026-03-06 14:13:37 +08:00
|
|
|
config['$task_concurrency'] = concurrencyEnabled.value ? 1 : 0
|
|
|
|
|
// 更新注入全部环境变量字段
|
|
|
|
|
config['$task_all_envs'] = !!allEnvsEnabled.value
|
2026-02-10 18:58:21 +08:00
|
|
|
|
2026-02-07 21:44:09 +08:00
|
|
|
// 重新序列化配置
|
|
|
|
|
form.value.config = JSON.stringify(config)
|
|
|
|
|
|
2026-01-02 11:45:29 +08:00
|
|
|
// 保存当前选择的执行位置对应的工作目录
|
2026-03-19 16:08:02 +08:00
|
|
|
form.value.work_dir = selectedAgentId.value === 'local'
|
|
|
|
|
? encodeLocalWorkDir(currentWorkDir.value)
|
|
|
|
|
: currentWorkDir.value
|
2026-02-10 18:58:21 +08:00
|
|
|
|
2025-12-25 20:28:20 +08:00
|
|
|
if (props.isEdit && form.value.id) {
|
2026-03-25 07:31:45 +08:00
|
|
|
const task = await api.tasks.update(form.value.id, form.value)
|
2026-03-25 09:39:52 +08:00
|
|
|
await notificationConfigRef.value?.saveConfig(task.id)
|
2025-12-25 20:28:20 +08:00
|
|
|
toast.success('任务已更新')
|
|
|
|
|
} else {
|
2026-03-25 07:31:45 +08:00
|
|
|
const task = await api.tasks.create(form.value)
|
2026-03-25 09:39:52 +08:00
|
|
|
await notificationConfigRef.value?.saveConfig(task.id)
|
2025-12-25 20:28:20 +08:00
|
|
|
toast.success('任务已创建')
|
|
|
|
|
}
|
|
|
|
|
emit('update:open', false)
|
|
|
|
|
emit('saved')
|
2026-03-24 11:48:11 +08:00
|
|
|
} catch (error: any) {
|
|
|
|
|
toast.error('保存失败', {
|
|
|
|
|
description: error.message || '未知错误'
|
|
|
|
|
})
|
2026-02-07 21:44:09 +08:00
|
|
|
}
|
2025-12-25 20:28:20 +08:00
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<Dialog :open="open" @update:open="emit('update:open', $event)">
|
2026-04-01 11:14:42 +08:00
|
|
|
<DialogContent class="sm:max-w-[560px] p-0 overflow-hidden border-none bg-background shadow-2xl transition-all duration-300" style="text-rendering: optimizeLegibility;" @openAutoFocus.prevent>
|
2026-03-06 14:13:37 +08:00
|
|
|
<div class="flex flex-col max-h-[85vh]">
|
2026-04-01 10:58:24 +08:00
|
|
|
<DialogHeader class="px-6 pr-12 pt-6 pb-2 shrink-0 border-b border-muted/50">
|
|
|
|
|
<DialogTitle class="text-xl font-bold py-2">
|
2026-03-24 14:00:17 +08:00
|
|
|
{{ isEdit ? '编辑任务' : '新建任务' }}
|
|
|
|
|
</DialogTitle>
|
|
|
|
|
</DialogHeader>
|
2026-02-13 17:27:55 +08:00
|
|
|
|
2026-03-24 14:00:17 +08:00
|
|
|
<ScrollArea class="flex-1 min-h-0 px-6">
|
2026-04-01 10:58:24 +08:00
|
|
|
<div class="space-y-10 py-6 pb-10">
|
2026-03-24 14:00:17 +08:00
|
|
|
<!-- 基本信息 Section -->
|
|
|
|
|
<section class="space-y-4">
|
2026-04-01 10:58:24 +08:00
|
|
|
<div class="flex items-center gap-2 mb-2">
|
|
|
|
|
<div class="h-4 w-1 bg-primary rounded-full shadow-sm shadow-primary/20" />
|
|
|
|
|
<h3 class="text-sm font-bold text-foreground/90">基本信息</h3>
|
2026-02-13 19:26:20 +08:00
|
|
|
</div>
|
2026-04-01 10:58:24 +08:00
|
|
|
<div class="grid gap-5 pl-3 border-l border-muted">
|
2026-03-24 14:00:17 +08:00
|
|
|
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3">
|
2026-04-01 11:14:42 +08:00
|
|
|
<Label class="sm:text-right text-xs text-foreground/70 uppercase tracking-wider font-bold">任务名称</Label>
|
2026-04-01 10:58:24 +08:00
|
|
|
<Input v-model="form.name" placeholder="输入任务描述性名称" :class="cn('sm:col-span-3 h-9 bg-muted/20 border-muted-foreground/15 transition-all focus:bg-background/50', form.name ? 'text-sm font-medium' : 'text-[11px] font-normal')" />
|
2026-03-24 14:00:17 +08:00
|
|
|
</div>
|
|
|
|
|
<div class="grid grid-cols-1 sm:grid-cols-4 items-start gap-3">
|
2026-04-01 11:14:42 +08:00
|
|
|
<Label class="sm:text-right text-xs text-foreground/70 uppercase tracking-wider font-bold pt-2.5">任务标签</Label>
|
2026-03-24 14:00:17 +08:00
|
|
|
<div class="sm:col-span-3 space-y-2">
|
|
|
|
|
<div class="flex gap-2">
|
|
|
|
|
<div class="relative flex-1">
|
2026-04-01 10:58:24 +08:00
|
|
|
<Input v-model="tagInput" placeholder="输入标签按回车..." :class="cn('h-9 bg-muted/20 border-muted-foreground/15 transition-all pr-12', tagInput ? 'text-sm font-medium' : 'text-[11px] font-normal')" @keydown.enter.prevent="addTag" />
|
|
|
|
|
<Button type="button" variant="ghost" size="sm" class="absolute right-1 top-1 h-7 px-2 text-xs hover:bg-primary/10 hover:text-primary transition-colors" @click.prevent="addTag">添加</Button>
|
2026-03-24 14:00:17 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div v-if="form.tags" class="flex flex-wrap gap-1.5 pt-1">
|
2026-04-01 10:58:24 +08:00
|
|
|
<span v-for="tag in form.tags.split(',').filter(Boolean)" :key="tag" class="flex items-center gap-1.5 bg-primary/5 text-primary px-2.5 py-1 rounded-full text-[11px] font-medium border border-primary/10 group transition-all hover:bg-primary/10">
|
2026-03-24 14:00:17 +08:00
|
|
|
{{ tag }}
|
2026-04-01 10:58:24 +08:00
|
|
|
<button type="button" class="text-primary/40 hover:text-destructive transition-colors shrink-0" @click.prevent="removeTag(tag)"><X class="h-3 w-3" /></button>
|
2026-03-24 14:00:17 +08:00
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3">
|
2026-04-01 11:14:42 +08:00
|
|
|
<Label class="sm:text-right text-xs text-foreground/70 uppercase tracking-wider font-bold">执行位置</Label>
|
2026-03-24 14:00:17 +08:00
|
|
|
<div class="sm:col-span-3">
|
|
|
|
|
<Select v-model="selectedAgentId">
|
2026-04-01 10:58:24 +08:00
|
|
|
<SelectTrigger class="h-9 bg-muted/20 border-muted-foreground/15"><SelectValue placeholder="选择执行节点" /></SelectTrigger>
|
2026-03-24 14:00:17 +08:00
|
|
|
<SelectContent>
|
2026-04-01 10:58:24 +08:00
|
|
|
<SelectItem value="local" class="flex items-center gap-2"><div class="flex items-center gap-2"><div class="w-1.5 h-1.5 rounded-full bg-blue-500" /><span>本地执行 (Local)</span></div></SelectItem>
|
|
|
|
|
<SelectItem v-for="agent in onlineAgents" :key="agent.id" :value="String(agent.id)"><div class="flex items-center gap-2"><div class="w-1.5 h-1.5 rounded-full" :class="agent.status === 'online' ? 'bg-green-500' : 'bg-muted-foreground'" /><span>{{ agent.name }}</span></div></SelectItem>
|
2026-03-24 14:00:17 +08:00
|
|
|
</SelectContent>
|
|
|
|
|
</Select>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3">
|
2026-04-01 11:14:42 +08:00
|
|
|
<Label class="sm:text-right text-xs text-foreground/70 uppercase tracking-wider font-bold">触发方式</Label>
|
2026-03-24 14:00:17 +08:00
|
|
|
<div class="sm:col-span-3">
|
|
|
|
|
<Select v-model="selectedTriggerType">
|
2026-04-01 10:58:24 +08:00
|
|
|
<SelectTrigger class="h-9 bg-muted/20 border-muted-foreground/15"><SelectValue /></SelectTrigger>
|
2026-03-24 14:00:17 +08:00
|
|
|
<SelectContent>
|
|
|
|
|
<SelectItem :value="TRIGGER_TYPE.CRON">⏳ 定时周期触发</SelectItem>
|
|
|
|
|
<SelectItem :value="TRIGGER_TYPE.BAIHU_STARTUP">🚀 系统启动触发</SelectItem>
|
|
|
|
|
</SelectContent>
|
|
|
|
|
</Select>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
|
2026-04-01 10:58:24 +08:00
|
|
|
<!-- 执行配置 Section -->
|
2026-03-24 14:00:17 +08:00
|
|
|
<section class="space-y-4">
|
2026-04-01 10:58:24 +08:00
|
|
|
<div class="flex items-center gap-2 mb-2">
|
|
|
|
|
<div class="h-4 w-1 bg-primary rounded-full shadow-sm shadow-primary/20" />
|
|
|
|
|
<h3 class="text-sm font-bold text-foreground/90">执行配置</h3>
|
2026-03-24 14:00:17 +08:00
|
|
|
</div>
|
2026-04-01 10:58:24 +08:00
|
|
|
<div class="grid gap-5 pl-3 border-l border-muted">
|
2026-03-24 14:00:17 +08:00
|
|
|
<template v-if="selectedAgentId === 'local'">
|
|
|
|
|
<div class="grid grid-cols-1 sm:grid-cols-4 items-start gap-3">
|
|
|
|
|
<div class="sm:col-span-1" />
|
|
|
|
|
<div class="sm:col-span-3">
|
2026-04-01 10:58:24 +08:00
|
|
|
<div class="flex items-center gap-2.5 p-3 rounded-xl bg-amber-500/5 border border-amber-500/10 text-amber-600 dark:text-amber-400 text-[11px] leading-relaxed font-medium">
|
|
|
|
|
<AlertCircle class="h-4 w-4 shrink-0 text-amber-500" /><p>请先在<b>「语言依赖」</b>中安装所需的运行时。执行脚本时将自动注入该环境。</p>
|
2026-03-24 14:00:17 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="grid grid-cols-1 sm:grid-cols-4 items-start gap-3">
|
2026-04-01 11:14:42 +08:00
|
|
|
<Label class="sm:text-right text-xs text-foreground/70 uppercase tracking-wider font-bold pt-2.5">语言环境</Label>
|
2026-03-24 14:00:17 +08:00
|
|
|
<div class="sm:col-span-3 space-y-2">
|
2026-04-01 10:58:24 +08:00
|
|
|
<div v-for="(clang, idx) in selectedLangs" :key="idx" class="flex gap-2 p-2 rounded-lg bg-muted/20 border border-muted-foreground/10 group/lang relative overflow-hidden">
|
2026-03-24 14:00:17 +08:00
|
|
|
<div class="absolute left-0 top-0 bottom-0 w-0.5 bg-primary/20 group-hover/lang:bg-primary transition-colors" />
|
|
|
|
|
<Popover>
|
2026-04-01 10:58:24 +08:00
|
|
|
<PopoverTrigger asChild><Button variant="ghost" class="justify-between flex-1 h-8 text-xs font-normal hover:bg-background/50"><div class="flex items-center gap-2 truncate"><div v-if="clang.name && getLangIcon(clang.name)" class="w-4 h-4 shrink-0 rounded-sm bg-white p-0.5 border shadow-sm"><img :src="getLangIcon(clang.name)" class="w-full h-full object-contain" /></div><span class="font-medium">{{ clang.name || "选择环境..." }}</span></div><ChevronsUpDown class="ml-1 h-3 w-3 opacity-40" /></Button></PopoverTrigger>
|
2026-03-24 14:00:17 +08:00
|
|
|
<PopoverContent class="p-0 w-[240px]" align="start">
|
2026-04-01 10:58:24 +08:00
|
|
|
<div class="p-2 border-b bg-muted/30"><div class="relative"><Search class="absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground" /><Input v-model="pluginSearch" placeholder="搜索已安装语言..." :class="cn('h-8 pl-8 bg-background border-muted-foreground/20', pluginSearch ? 'text-xs font-medium' : 'text-[10px]')" /></div></div>
|
2026-03-24 14:00:17 +08:00
|
|
|
<ScrollArea class="h-48 p-1">
|
2026-04-01 10:58:24 +08:00
|
|
|
<div v-if="loadingLangs" class="flex items-center justify-center py-6"><Loader2 class="h-5 w-5 animate-spin text-primary/50" /></div>
|
|
|
|
|
<button v-else v-for="p in filteredPlugins" :key="p" @click="updateLangName(idx, p)" class="w-full flex items-center px-3 py-2 text-xs rounded-md hover:bg-accent text-left transition-all mb-0.5"><span class="flex-1" :class="{ 'font-bold text-primary': clang.name === p }">{{ p }}</span><Check v-if="clang.name === p" class="h-3 w-3 text-primary" /></button>
|
2026-03-24 14:00:17 +08:00
|
|
|
</ScrollArea>
|
|
|
|
|
</PopoverContent>
|
|
|
|
|
</Popover>
|
|
|
|
|
<Popover>
|
2026-04-01 10:58:24 +08:00
|
|
|
<PopoverTrigger asChild :disabled="!clang.name"><Button variant="ghost" class="justify-between w-28 h-8 text-xs font-normal hover:bg-background/50" :disabled="!clang.name"><span class="truncate">{{ clang.version || "版本..." }}</span><ChevronsUpDown class="h-3 w-3 opacity-40 ml-1" /></Button></PopoverTrigger>
|
2026-03-24 14:00:17 +08:00
|
|
|
<PopoverContent class="p-0 w-[160px]" align="start">
|
2026-04-01 10:58:24 +08:00
|
|
|
<ScrollArea class="h-48 p-1"><button v-for="v in getFilteredVersions(clang.availableVersions)" :key="v" @click="clang.version = v" class="w-full flex items-center px-3 py-2 text-xs rounded-md hover:bg-accent font-mono mb-0.5"><span class="flex-1 truncate" :class="{ 'font-bold text-primary': clang.version === v }">{{ v }}</span><Check v-if="clang.version === v" class="h-3 w-3 text-primary" /></button></ScrollArea>
|
2026-03-24 14:00:17 +08:00
|
|
|
</PopoverContent>
|
|
|
|
|
</Popover>
|
2026-04-01 10:58:24 +08:00
|
|
|
<Button variant="ghost" size="icon" class="h-8 w-8 text-muted-foreground hover:text-destructive hover:bg-destructive/10 shrink-0" @click="removeLang(idx)"><X class="h-4 w-4" /></Button>
|
2026-03-24 14:00:17 +08:00
|
|
|
</div>
|
2026-04-01 10:58:24 +08:00
|
|
|
<Button variant="outline" size="sm" class="w-full h-9 text-xs border-dashed border-muted-foreground/30 text-muted-foreground hover:text-primary hover:border-primary/50 transition-all bg-muted/5 hover:bg-primary/5 rounded-xl" @click="addLang"><Plus class="h-4 w-4 mr-2" /> 添加运行时环境 (Mise)</Button>
|
2026-03-06 14:13:37 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-03-24 14:00:17 +08:00
|
|
|
</template>
|
|
|
|
|
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3">
|
2026-04-01 11:14:42 +08:00
|
|
|
<Label class="sm:text-right text-xs text-foreground/70 uppercase tracking-wider font-bold">执行命令</Label>
|
2026-04-01 10:58:24 +08:00
|
|
|
<div class="sm:col-span-3 relative"><Input v-model="form.command" placeholder="例如: python main.py --args" :class="cn('h-9 bg-muted/20 border-muted-foreground/15 transition-all focus:bg-background/50 pr-10', form.command ? 'font-mono text-sm tracking-tight font-medium' : 'text-[11px] font-normal')" /><Terminal class="absolute right-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground opacity-40 pointer-events-none" /></div>
|
2025-12-25 20:28:20 +08:00
|
|
|
</div>
|
2026-03-24 14:00:17 +08:00
|
|
|
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3">
|
2026-04-01 11:14:42 +08:00
|
|
|
<Label class="sm:text-right text-xs text-foreground/70 uppercase tracking-wider font-bold">工作目录</Label>
|
2026-04-01 10:58:24 +08:00
|
|
|
<div class="sm:col-span-3"><DirTreeSelect v-if="selectedAgentId === 'local'" v-model="currentWorkDir" class="h-9" /><Input v-else v-model="currentWorkDir" placeholder="任务运行路径(留空取 Agent 默认值)" :class="cn('h-9 bg-muted/20 border-muted-foreground/15 transition-all focus:bg-background/50', currentWorkDir ? 'font-mono text-sm tracking-tight font-medium' : 'text-[11px] font-normal')" /></div>
|
2026-03-06 14:13:37 +08:00
|
|
|
</div>
|
2026-03-24 14:00:17 +08:00
|
|
|
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3 pb-1">
|
2026-04-01 11:14:42 +08:00
|
|
|
<Label class="sm:text-right text-xs text-foreground/70 uppercase tracking-wider font-bold">变量注入</Label>
|
2026-04-01 10:58:24 +08:00
|
|
|
<div class="sm:col-span-3"><div class="flex items-center space-x-2 bg-muted/10 px-3 py-1.5 rounded-full border border-muted-foreground/10 w-fit"><Switch :model-value="allEnvsEnabled" @update:model-value="onAllEnvsChange" id="all-envs" class="scale-90" /><Label for="all-envs" class="text-[11px] font-medium cursor-pointer">全量注入</Label></div></div>
|
2026-03-06 14:13:37 +08:00
|
|
|
</div>
|
2026-03-24 14:00:17 +08:00
|
|
|
<div v-if="!allEnvsEnabled" class="grid grid-cols-1 sm:grid-cols-4 items-start gap-3">
|
2026-04-01 11:14:42 +08:00
|
|
|
<Label class="sm:text-right text-xs text-foreground/70 uppercase tracking-wider font-bold pt-2.5">按需包含</Label>
|
2026-03-24 14:00:17 +08:00
|
|
|
<div class="sm:col-span-3 space-y-2">
|
2026-04-01 10:58:24 +08:00
|
|
|
<Popover><PopoverTrigger as-child><Button variant="outline" class="w-full justify-between h-9 bg-muted/10 border-muted-foreground/15 text-xs rounded-xl"><span class="text-muted-foreground">选择关联的环境变量...</span><ChevronDown class="h-4 w-4 opacity-30" /></Button></PopoverTrigger>
|
|
|
|
|
<PopoverContent class="p-0 w-[400px]" align="start"><ScrollArea class="h-64 p-2"><div v-for="env in filteredEnvVars" :key="env.id" @click.stop="addEnv(env.id)" class="p-3 rounded-lg hover:bg-primary/5 cursor-pointer text-sm font-mono font-bold">{{ env.name }}</div></ScrollArea></PopoverContent>
|
2026-03-06 14:13:37 +08:00
|
|
|
</Popover>
|
2026-04-01 10:58:24 +08:00
|
|
|
<div v-if="selectedEnvs.length > 0" class="flex flex-wrap gap-2 p-3 rounded-xl bg-muted/10 border border-muted-foreground/10 min-h-12"><div v-for="env in selectedEnvs" :key="env?.id" class="flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-background border border-muted-foreground/15 text-[11px] font-mono font-medium">{{ env?.name }}<X class="h-2.5 w-2.5 cursor-pointer" @click="removeEnv(env!.id)" /></div></div>
|
2026-03-06 14:13:37 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-03-24 14:00:17 +08:00
|
|
|
</section>
|
2026-03-06 14:13:37 +08:00
|
|
|
|
2026-04-01 10:58:24 +08:00
|
|
|
<!-- 调度策略 Section -->
|
2026-03-24 14:00:17 +08:00
|
|
|
<section class="space-y-4">
|
2026-04-01 10:58:24 +08:00
|
|
|
<div class="flex items-center gap-2 mb-2">
|
2026-03-30 17:43:21 +08:00
|
|
|
<div class="h-4 w-1 bg-primary rounded-full shadow-sm shadow-primary/20" />
|
|
|
|
|
<h3 class="text-sm font-bold text-foreground/90">调度策略</h3>
|
2026-03-24 14:00:17 +08:00
|
|
|
</div>
|
|
|
|
|
<div class="grid gap-5 pl-3 border-l border-muted">
|
|
|
|
|
<template v-if="selectedTriggerType === TRIGGER_TYPE.CRON">
|
|
|
|
|
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3">
|
2026-04-01 11:14:42 +08:00
|
|
|
<Label class="sm:text-right text-xs text-foreground/70 uppercase tracking-wider font-bold">定时规则</Label>
|
2026-03-24 14:00:17 +08:00
|
|
|
<div class="sm:col-span-3">
|
2026-04-01 10:58:24 +08:00
|
|
|
<Input v-model="form.schedule" placeholder="秒 分 时 日 月 周 (必须 6 位)" :class="cn('h-9 bg-muted/20 border-muted-foreground/15 transition-all focus:ring-1 focus:ring-primary/40 focus:border-primary/40', form.schedule ? 'font-mono text-sm tracking-[0.1em] font-medium' : 'text-[11px] font-normal')" />
|
|
|
|
|
<div v-if="cronDescription" class="mt-2.5 p-2 px-3 rounded-xl bg-primary/5 border border-primary/10 text-[11px] text-primary/80 font-medium flex items-center gap-2.5"><Zap class="h-3 w-3 text-primary" />{{ cronDescription }}</div>
|
|
|
|
|
<div class="mt-3 flex flex-wrap gap-1.5"><button v-for="preset in cronPresets" :key="preset.value" class="px-2.5 py-1 text-[10px] rounded-lg bg-muted/30 border border-transparent hover:border-primary/30 hover:bg-primary/5 font-medium" @click.prevent="form.schedule = preset.value">{{ preset.label }}</button></div>
|
2026-03-24 14:00:17 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
2026-03-06 14:13:37 +08:00
|
|
|
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3">
|
2026-04-01 11:14:42 +08:00
|
|
|
<Label class="sm:text-right text-xs text-foreground/70 uppercase tracking-wider font-bold">失败策略</Label>
|
2026-03-24 14:00:17 +08:00
|
|
|
<div class="sm:col-span-3 flex items-center gap-3">
|
2026-04-01 10:58:24 +08:00
|
|
|
<span class="text-[11px] text-muted-foreground">重试</span>
|
|
|
|
|
<Input :model-value="form.retry_count" @update:model-value="v => form.retry_count = Number(v)" type="number" :min="0" class="w-20 h-9 bg-muted/20 border-muted-foreground/15 text-center font-bold" />
|
|
|
|
|
<span class="text-[11px] text-muted-foreground">次</span>
|
2026-03-06 14:13:37 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-04-01 11:14:42 +08:00
|
|
|
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3">
|
|
|
|
|
<Label class="sm:text-right text-xs text-foreground/70 uppercase tracking-wider font-bold">运行策略</Label>
|
|
|
|
|
<div class="sm:col-span-3 flex items-center gap-3">
|
|
|
|
|
<Input :model-value="form.timeout" @update:model-value="v => form.timeout = Number(v)" type="number" :min="0" class="w-20 h-9 bg-muted/20 border-muted-foreground/15 text-center font-bold" />
|
|
|
|
|
<span class="text-[11px] text-muted-foreground">分钟超时</span>
|
2026-03-06 14:13:37 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-03-24 14:00:17 +08:00
|
|
|
</section>
|
2026-03-25 09:39:52 +08:00
|
|
|
<TaskNotificationConfig ref="notificationConfigRef" :task-id="isEdit ? task?.id : undefined" />
|
|
|
|
|
</div>
|
|
|
|
|
</ScrollArea>
|
2026-04-01 10:58:24 +08:00
|
|
|
<div class="flex items-center justify-between px-6 py-4 bg-muted/20 border-t shrink-0 backdrop-blur-sm">
|
|
|
|
|
<p class="text-[10px] text-muted-foreground/50 italic">最后编辑于: {{ isEdit ? (form.updated_at || '刚才') : '现在' }}</p>
|
|
|
|
|
<div class="flex gap-3">
|
|
|
|
|
<Button variant="ghost" size="sm" class="hover:bg-muted font-medium text-xs px-6" @click="emit('update:open', false)">取消</Button>
|
|
|
|
|
<Button size="sm" class="px-8 font-semibold text-xs shadow-lg shadow-primary/20 bg-primary hover:bg-primary/90" @click="save">确定保存</Button>
|
|
|
|
|
</div>
|
2025-12-25 20:28:20 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-04-01 10:58:24 +08:00
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
2025-12-25 20:28:20 +08:00
|
|
|
</template>
|
2026-03-25 21:05:40 +08:00
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
:deep(*) {
|
2026-04-01 11:14:42 +08:00
|
|
|
text-rendering: optimizeLegibility;
|
2026-03-25 21:05:40 +08:00
|
|
|
}
|
2026-04-01 10:58:24 +08:00
|
|
|
:deep(label) {
|
2026-03-25 21:05:40 +08:00
|
|
|
text-rendering: optimizeLegibility;
|
2026-04-01 11:14:42 +08:00
|
|
|
letter-spacing: 0.01em;
|
2026-03-25 21:05:40 +08:00
|
|
|
}
|
|
|
|
|
</style>
|
2026-04-01 10:58:24 +08:00
|
|
|
|