feat: add env task global setting
This commit is contained in:
@@ -319,6 +319,8 @@ export interface Task {
|
||||
enabled: boolean
|
||||
last_run: string
|
||||
next_run: string
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
}
|
||||
|
||||
export interface RepoConfig {
|
||||
|
||||
+64
-33
@@ -1,5 +1,6 @@
|
||||
@import "tailwindcss";
|
||||
@import "tw-animate-css";
|
||||
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');
|
||||
|
||||
/* Sonner toast styles */
|
||||
[data-sonner-toaster] {
|
||||
@@ -135,28 +136,36 @@
|
||||
@layer base {
|
||||
* {
|
||||
@apply outline-ring/50;
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
*,
|
||||
::before,
|
||||
::after {
|
||||
border-color: transparent;
|
||||
}
|
||||
|
||||
.border,
|
||||
[class*="border-"] {
|
||||
border-color: var(--border);
|
||||
}
|
||||
|
||||
body {
|
||||
@apply bg-background text-foreground antialiased;
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
letter-spacing: -0.01em;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
||||
|
||||
.font-code {
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
.font-code,
|
||||
.font-mono,
|
||||
code,
|
||||
pre {
|
||||
font-family: 'JetBrains Mono', 'Fira Code', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace !important;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,16 +198,20 @@ body {
|
||||
}
|
||||
|
||||
/* 按钮增强 - 更流畅的交互 */
|
||||
button, [role="button"] {
|
||||
button,
|
||||
[role="button"] {
|
||||
transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
button:active, [role="button"]:active {
|
||||
button:active,
|
||||
[role="button"]:active {
|
||||
transform: scale(0.98);
|
||||
}
|
||||
|
||||
/* 输入框增强 - 聚焦效果 */
|
||||
input:focus, textarea:focus, select:focus {
|
||||
input:focus,
|
||||
textarea:focus,
|
||||
select:focus {
|
||||
box-shadow: 0 0 0 3px oklch(from var(--ring) l c h / 0.1);
|
||||
transition: box-shadow 0.2s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
@@ -218,7 +231,8 @@ table tbody tr:hover {
|
||||
}
|
||||
|
||||
/* 模态框和弹出层增强 - 背景模糊 */
|
||||
[role="dialog"]::backdrop, [data-state="open"]::backdrop {
|
||||
[role="dialog"]::backdrop,
|
||||
[data-state="open"]::backdrop {
|
||||
backdrop-filter: blur(4px);
|
||||
animation: fadeIn 0.2s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
@@ -227,13 +241,15 @@ table tbody tr:hover {
|
||||
from {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
to {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* 代码块增强 */
|
||||
code, pre {
|
||||
code,
|
||||
pre {
|
||||
background: oklch(from var(--muted) l c h / 0.5);
|
||||
border-radius: calc(var(--radius) - 2px);
|
||||
padding: 0.125rem 0.375rem;
|
||||
@@ -247,7 +263,10 @@ pre code {
|
||||
}
|
||||
|
||||
/* Windows 小字体优化 */
|
||||
.text-xs, .text-sm, [class*="text-xs"], [class*="text-sm"] {
|
||||
.text-xs,
|
||||
.text-sm,
|
||||
[class*="text-xs"],
|
||||
[class*="text-sm"] {
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
font-weight: 400;
|
||||
@@ -255,25 +274,30 @@ pre code {
|
||||
}
|
||||
|
||||
/* 表格和列表中的小字体优化 */
|
||||
table, [role="table"] {
|
||||
table,
|
||||
[role="table"] {
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
/* 命令和路径文本优化 */
|
||||
code, pre, [class*="font-mono"] {
|
||||
code,
|
||||
pre,
|
||||
[class*="font-mono"] {
|
||||
-webkit-font-smoothing: auto;
|
||||
-moz-osx-font-smoothing: auto;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
/* 徽章和标签增强 */
|
||||
[class*="badge"], [class*="tag"] {
|
||||
[class*="badge"],
|
||||
[class*="tag"] {
|
||||
transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
|
||||
}
|
||||
|
||||
[class*="badge"]:hover, [class*="tag"]:hover {
|
||||
[class*="badge"]:hover,
|
||||
[class*="tag"]:hover {
|
||||
box-shadow: 0 2px 4px 0 rgb(0 0 0 / 0.1);
|
||||
}
|
||||
|
||||
@@ -282,18 +306,17 @@ code, pre, [class*="font-mono"] {
|
||||
0% {
|
||||
background-position: -1000px 0;
|
||||
}
|
||||
|
||||
100% {
|
||||
background-position: 1000px 0;
|
||||
}
|
||||
}
|
||||
|
||||
.skeleton {
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
oklch(from var(--muted) l c h / 0.3) 0%,
|
||||
oklch(from var(--muted) l c h / 0.5) 50%,
|
||||
oklch(from var(--muted) l c h / 0.3) 100%
|
||||
);
|
||||
background: linear-gradient(90deg,
|
||||
oklch(from var(--muted) l c h / 0.3) 0%,
|
||||
oklch(from var(--muted) l c h / 0.5) 50%,
|
||||
oklch(from var(--muted) l c h / 0.3) 100%);
|
||||
background-size: 1000px 100%;
|
||||
animation: shimmer 2s infinite linear;
|
||||
}
|
||||
@@ -341,25 +364,33 @@ code, pre, [class*="font-mono"] {
|
||||
background: oklch(from var(--primary) l c h / 0.3);
|
||||
}
|
||||
|
||||
/* Number input spinner buttons - dark mode */
|
||||
/* Number input spinner - Refined SVG version with more spacing */
|
||||
input[type="number"]::-webkit-inner-spin-button,
|
||||
input[type="number"]::-webkit-outer-spin-button {
|
||||
opacity: 0.6;
|
||||
-webkit-appearance: none;
|
||||
appearance: none;
|
||||
width: 22px;
|
||||
/* Increased width for better hit area and visibility */
|
||||
height: 20px;
|
||||
cursor: pointer;
|
||||
opacity: 0.5;
|
||||
/* Premium SVG Arrows: Increased gap between up and down arrows */
|
||||
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m7 17 5 5 5-5'/%3E%3Cpath d='m7 7 5-5 5 5'/%3E%3C/svg%3E");
|
||||
background-repeat: no-repeat;
|
||||
background-position: center;
|
||||
background-size: 14px;
|
||||
transition: opacity 0.2s ease;
|
||||
margin-right: 2px;
|
||||
}
|
||||
|
||||
input[type="number"]:hover::-webkit-inner-spin-button,
|
||||
input[type="number"]:hover::-webkit-outer-spin-button {
|
||||
opacity: 1;
|
||||
/* Hover effect: Smoothly light up the arrows */
|
||||
input[type="number"]:hover::-webkit-inner-spin-button {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.dark input[type="number"]::-webkit-inner-spin-button,
|
||||
.dark input[type="number"]::-webkit-outer-spin-button {
|
||||
filter: invert(0.7);
|
||||
}
|
||||
|
||||
.dark input[type="number"]:hover::-webkit-inner-spin-button,
|
||||
.dark input[type="number"]:hover::-webkit-outer-spin-button {
|
||||
filter: invert(0.85);
|
||||
/* Light mode support */
|
||||
:root:not(.dark) input[type="number"]::-webkit-inner-spin-button {
|
||||
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m7 17 5 5 5-5'/%3E%3Cpath d='m7 7 5-5 5 5'/%3E%3C/svg%3E");
|
||||
}
|
||||
|
||||
/* Custom scrollbar styles */
|
||||
@@ -421,4 +452,4 @@ input[type="number"]:hover::-webkit-outer-spin-button {
|
||||
|
||||
.apexcharts-tooltip-title {
|
||||
display: none !important;
|
||||
}
|
||||
}
|
||||
@@ -114,7 +114,7 @@ const displayValue = computed(() => {
|
||||
<template>
|
||||
<Popover v-model:open="open">
|
||||
<PopoverTrigger as-child>
|
||||
<Button variant="outline" class="w-full justify-start font-mono text-sm h-9">
|
||||
<Button variant="outline" class="w-full justify-start text-sm h-9">
|
||||
<Folder class="h-4 w-4 mr-2 text-yellow-500 shrink-0" />
|
||||
<span class="truncate">{{ displayValue }}</span>
|
||||
</Button>
|
||||
|
||||
@@ -1,28 +1,30 @@
|
||||
<script setup lang="ts">
|
||||
import type { SwitchRootEmits, SwitchRootProps } from "reka-ui"
|
||||
import type { SwitchRootProps } from "reka-ui"
|
||||
import type { HTMLAttributes } from "vue"
|
||||
import { reactiveOmit } from "@vueuse/core"
|
||||
import {
|
||||
SwitchRoot,
|
||||
SwitchThumb,
|
||||
useForwardPropsEmits,
|
||||
} from "reka-ui"
|
||||
import { SwitchRoot, SwitchThumb } from "reka-ui"
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const props = defineProps<SwitchRootProps & { class?: HTMLAttributes["class"] }>()
|
||||
|
||||
const emits = defineEmits<SwitchRootEmits>()
|
||||
const emits = defineEmits(['update:modelValue'])
|
||||
|
||||
const delegatedProps = reactiveOmit(props, "class")
|
||||
|
||||
const forwarded = useForwardPropsEmits(delegatedProps, emits)
|
||||
function onUpdate(value: boolean) {
|
||||
emits('update:modelValue', value)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<SwitchRoot
|
||||
v-slot="slotProps"
|
||||
data-slot="switch"
|
||||
v-bind="forwarded"
|
||||
:model-value="props.modelValue"
|
||||
:default-value="props.defaultValue"
|
||||
:disabled="props.disabled"
|
||||
:name="props.name"
|
||||
:required="props.required"
|
||||
:value="props.value"
|
||||
:id="props.id"
|
||||
:as-child="props.asChild"
|
||||
:as="props.as"
|
||||
@update:model-value="onUpdate"
|
||||
:class="cn(
|
||||
'peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50',
|
||||
props.class,
|
||||
@@ -31,8 +33,6 @@ const forwarded = useForwardPropsEmits(delegatedProps, emits)
|
||||
<SwitchThumb
|
||||
data-slot="switch-thumb"
|
||||
:class="cn('bg-background dark:data-[state=unchecked]:bg-foreground dark:data-[state=checked]:bg-primary-foreground pointer-events-none block size-4 rounded-full ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0')"
|
||||
>
|
||||
<slot name="thumb" v-bind="slotProps" />
|
||||
</SwitchThumb>
|
||||
/>
|
||||
</SwitchRoot>
|
||||
</template>
|
||||
|
||||
+266
-191
@@ -1,16 +1,18 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch } from 'vue'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from '@/components/ui/dialog'
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import { ScrollArea } from '@/components/ui/scroll-area'
|
||||
import DirTreeSelect from '@/components/DirTreeSelect.vue'
|
||||
import { X } from 'lucide-vue-next'
|
||||
import { X, Globe, GitBranch, Shield, Zap, Clock } from 'lucide-vue-next'
|
||||
import { api, type Task, type RepoConfig, type Agent } from '@/api'
|
||||
import { toast } from 'vue-sonner'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
const props = defineProps<{
|
||||
open: boolean
|
||||
@@ -84,6 +86,10 @@ const concurrencyEnabled = computed({
|
||||
}
|
||||
})
|
||||
|
||||
function onConcurrencyChange(val: boolean) {
|
||||
concurrencyEnabled.value = val
|
||||
}
|
||||
|
||||
const isSingleFile = computed({
|
||||
get: () => !!repoConfig.value.single_file,
|
||||
set: (val: boolean) => {
|
||||
@@ -98,7 +104,13 @@ const cleanConfig = computed(() => {
|
||||
|
||||
watch(() => props.open, async (val) => {
|
||||
if (val) {
|
||||
form.value = { ...props.task }
|
||||
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
|
||||
}
|
||||
// 解析清理配置
|
||||
if (props.task?.clean_config) {
|
||||
try {
|
||||
@@ -165,7 +177,7 @@ async function save() {
|
||||
// 同时也保留在 repoConfig 对象中以便回显
|
||||
const configToSave: any = {
|
||||
...repoConfig.value,
|
||||
'$task_concurrency': repoConfig.value.concurrency !== undefined ? repoConfig.value.concurrency : 1
|
||||
'$task_concurrency': concurrencyEnabled.value ? 1 : 0
|
||||
}
|
||||
|
||||
form.value.config = JSON.stringify(configToSave)
|
||||
@@ -186,197 +198,260 @@ async function save() {
|
||||
|
||||
<template>
|
||||
<Dialog :open="open" @update:open="emit('update:open', $event)">
|
||||
<DialogContent class="sm:max-w-[480px] max-h-[85vh] flex flex-col !gap-0 !p-0" :trap-focus="false"
|
||||
@openAutoFocus.prevent>
|
||||
<DialogHeader class="shrink-0 p-6 pb-0">
|
||||
<DialogTitle>{{ isEdit ? '编辑仓库同步' : '新建仓库同步' }}</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div class="space-y-3 py-3 px-6 overflow-y-auto flex-1 custom-scrollbar">
|
||||
<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>
|
||||
<Input v-model="form.name" placeholder="我的仓库同步" class="sm:col-span-3 h-8 text-sm" />
|
||||
</div>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-start gap-2 sm:gap-3">
|
||||
<Label class="sm:text-right text-sm pt-1.5">任务标签</Label>
|
||||
<div class="sm:col-span-3 space-y-2">
|
||||
<div class="flex gap-2">
|
||||
<Input v-model="tagInput" placeholder="输入标签名称后点击增加或回车键添加" class="flex-1 h-8 text-sm" @keydown.enter.prevent="addTag" />
|
||||
<Button type="button" variant="outline" size="sm" class="h-8" @click="addTag">
|
||||
增加
|
||||
</Button>
|
||||
</div>
|
||||
<div v-if="form.tags" class="flex flex-wrap gap-2">
|
||||
<span v-for="tag in form.tags.split(',').filter(Boolean)" :key="tag" class="flex items-center gap-1 bg-secondary text-secondary-foreground px-2 py-0.5 rounded-md text-xs border">
|
||||
{{ tag }}
|
||||
<button type="button" class="text-muted-foreground hover:text-foreground outline-none" @click.prevent="removeTag(tag)">
|
||||
<X class="h-3 w-3" />
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
<DialogContent class="sm:max-w-[560px] p-0 overflow-hidden border-none bg-background/95 backdrop-blur-xl shadow-2xl" @openAutoFocus.prevent>
|
||||
<div class="absolute inset-0 bg-gradient-to-br from-primary/5 via-transparent to-primary/5 pointer-events-none" />
|
||||
|
||||
<div class="flex flex-col max-h-[85vh]">
|
||||
<DialogHeader class="px-6 pt-6 pb-2 shrink-0">
|
||||
<DialogTitle class="text-xl font-bold bg-clip-text text-transparent bg-gradient-to-r from-foreground to-foreground/70">
|
||||
{{ isEdit ? '编辑仓库同步' : '新建仓库同步' }}
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
<ScrollArea class="flex-1 min-h-0 px-6">
|
||||
<div class="space-y-8 py-4 pb-8">
|
||||
<!-- 基本信息 Section -->
|
||||
<section class="space-y-4">
|
||||
<div class="flex items-center gap-2 mb-1">
|
||||
<div class="h-4 w-1 bg-primary rounded-full" />
|
||||
<h3 class="text-sm font-semibold text-foreground/80">基本信息</h3>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-4 pl-3 border-l border-muted">
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3">
|
||||
<Label class="sm:text-right text-xs text-muted-foreground uppercase tracking-wider">任务名称</Label>
|
||||
<Input v-model="form.name" placeholder="输入同步任务名称" class="sm:col-span-3 h-9 bg-muted/30 border-muted-foreground/20 focus:bg-background transition-all" />
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-start gap-3">
|
||||
<Label class="sm:text-right text-xs text-muted-foreground uppercase tracking-wider pt-2.5">任务标签</Label>
|
||||
<div class="sm:col-span-3 space-y-2">
|
||||
<div class="flex gap-2">
|
||||
<div class="relative flex-1">
|
||||
<Input v-model="tagInput" placeholder="输入标签按回车..." class="h-9 bg-muted/30 border-muted-foreground/20 pr-12" @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="addTag">
|
||||
添加
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="form.tags" class="flex flex-wrap gap-1.5 pt-1">
|
||||
<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">
|
||||
{{ tag }}
|
||||
<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>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 仓库配置 Section -->
|
||||
<section class="space-y-4">
|
||||
<div class="flex items-center gap-2 mb-1">
|
||||
<div class="h-4 w-1 bg-primary rounded-full" />
|
||||
<h3 class="text-sm font-semibold text-foreground/80">核心配置</h3>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-4 pl-3 border-l border-muted">
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3">
|
||||
<Label class="sm:text-right text-xs text-muted-foreground uppercase tracking-wider">源类型</Label>
|
||||
<div class="sm:col-span-3">
|
||||
<Select :model-value="repoConfig.source_type" @update:model-value="(v) => repoConfig.source_type = String(v || 'git')">
|
||||
<SelectTrigger class="h-9 bg-muted/30 border-muted-foreground/20">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="git">
|
||||
<div class="flex items-center gap-2">
|
||||
<GitBranch class="h-3.5 w-3.5" />
|
||||
<span>Git 仓库 (Repository)</span>
|
||||
</div>
|
||||
</SelectItem>
|
||||
<SelectItem value="url">
|
||||
<div class="flex items-center gap-2">
|
||||
<Globe class="h-3.5 w-3.5" />
|
||||
<span>URL 下载 (Direct Link)</span>
|
||||
</div>
|
||||
</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3">
|
||||
<Label class="sm:text-right text-xs text-muted-foreground uppercase tracking-wider font-semibold">源地址</Label>
|
||||
<div class="sm:col-span-3 relative">
|
||||
<Input v-model="repoConfig.source_url"
|
||||
:placeholder="repoConfig.source_type === 'git' ? 'https://github.com/user/repo.git' : 'https://example.com/file.js'"
|
||||
class="h-9 font-mono text-[13px] bg-muted/30 border-muted-foreground/20 focus:bg-background pr-10 transition-all"
|
||||
autocomplete="off" />
|
||||
<Globe class="absolute right-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground opacity-40" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3">
|
||||
<Label class="sm:text-right text-xs text-muted-foreground uppercase tracking-wider">目标路径</Label>
|
||||
<div class="sm:col-span-3">
|
||||
<DirTreeSelect v-if="selectedAgentId === 'local'" :model-value="repoConfig.target_path || ''"
|
||||
@update:model-value="v => repoConfig.target_path = v" class="h-9" />
|
||||
<Input v-else v-model="repoConfig.target_path" placeholder="Agent 上的目标路径" class="h-9 bg-muted/30 border-muted-foreground/20" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="repoConfig.source_type === 'git'" class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3">
|
||||
<Label class="sm:text-right text-xs text-muted-foreground uppercase tracking-wider">分支</Label>
|
||||
<Input v-model="repoConfig.branch" placeholder="main (默认)" class="sm:col-span-3 h-9 bg-muted/30 border-muted-foreground/20 focus:bg-background transition-all" autocomplete="off" />
|
||||
</div>
|
||||
|
||||
<div v-if="repoConfig.source_type === 'git'" class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3">
|
||||
<Label class="sm:text-right text-xs text-muted-foreground uppercase tracking-wider">稀疏路径</Label>
|
||||
<Input v-model="repoConfig.sparse_path" placeholder="指定目录或文件 (可选)" class="sm:col-span-3 h-9 bg-muted/30 border-muted-foreground/20 focus:bg-background transition-all" autocomplete="off" />
|
||||
</div>
|
||||
|
||||
<div v-if="repoConfig.source_type === 'git' && repoConfig.sparse_path" class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3">
|
||||
<Label class="sm:text-right text-xs text-muted-foreground uppercase tracking-wider">下载模式</Label>
|
||||
<div class="sm:col-span-3">
|
||||
<div class="flex items-center space-x-2 bg-muted/20 px-3 py-1.5 rounded-full border border-muted-foreground/10 w-fit">
|
||||
<Checkbox id="single-file-sync" v-model:checked="isSingleFile" class="scale-90" />
|
||||
<Label for="single-file-sync" class="text-[11px] font-medium cursor-pointer">作为单文件直接下载</Label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 访问策略 Section -->
|
||||
<section class="space-y-4">
|
||||
<div class="flex items-center gap-2 mb-1">
|
||||
<div class="h-4 w-1 bg-primary rounded-full" />
|
||||
<h3 class="text-sm font-semibold text-foreground/80">访问控制</h3>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-4 pl-3 border-l border-muted">
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3">
|
||||
<Label class="sm:text-right text-xs text-muted-foreground uppercase tracking-wider">代理配置</Label>
|
||||
<div class="sm:col-span-3">
|
||||
<Select :model-value="repoConfig.proxy" @update:model-value="(v) => repoConfig.proxy = String(v || 'none')">
|
||||
<SelectTrigger class="h-9 bg-muted/30 border-muted-foreground/20">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="opt in proxyOptions" :key="opt.value" :value="opt.value">{{ opt.label }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="repoConfig.proxy === 'custom'" class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3">
|
||||
<Label class="sm:text-right text-xs text-muted-foreground uppercase tracking-wider">代理地址</Label>
|
||||
<Input v-model="repoConfig.proxy_url" placeholder="https://your-proxy.com" class="sm:col-span-3 h-9 bg-muted/30 font-mono text-xs border-muted-foreground/20 focus:bg-background transition-all" autocomplete="off" />
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3">
|
||||
<Label class="sm:text-right text-xs text-muted-foreground uppercase tracking-wider">身份认证</Label>
|
||||
<div class="sm:col-span-3 relative">
|
||||
<Input v-model="repoConfig.auth_token" type="password" placeholder="推荐使用 Token 替代密码" class="h-9 bg-muted/30 border-muted-foreground/20 pr-10 text-xs focus:bg-background transition-all" autocomplete="new-password" />
|
||||
<Shield class="absolute right-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground opacity-40" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 调度策略 Section -->
|
||||
<section class="space-y-4">
|
||||
<div class="flex items-center gap-2 mb-1">
|
||||
<div class="h-4 w-1 bg-primary rounded-full" />
|
||||
<h3 class="text-sm font-semibold text-foreground/80">调度策略</h3>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-5 pl-3 border-l border-muted">
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3">
|
||||
<Label class="sm:text-right text-xs text-muted-foreground uppercase tracking-wider font-semibold">定时规则</Label>
|
||||
<div class="sm:col-span-3">
|
||||
<Input v-model="form.schedule" placeholder="* * * * * *" class="h-9 font-mono text-[13px] bg-muted/30 border-muted-foreground/20 focus:ring-1 focus:ring-primary/50" />
|
||||
<div class="mt-2.5 space-y-2">
|
||||
<div class="flex items-center gap-1.5 text-[10px] text-muted-foreground/70 uppercase font-bold tracking-tighter">
|
||||
<Clock class="h-3 w-3" /> 格式指导: 秒 分 时 日 月 周
|
||||
</div>
|
||||
<div class="flex flex-wrap gap-1.5">
|
||||
<button v-for="preset in cronPresets" :key="preset.value"
|
||||
class="px-2 py-1 text-[10px] rounded-md bg-muted/50 border border-muted-foreground/10 hover:border-primary/50 hover:bg-primary/5 hover:text-primary transition-all font-medium"
|
||||
@click.prevent="form.schedule = preset.value">
|
||||
{{ preset.label }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3">
|
||||
<Label class="sm:text-right text-xs text-muted-foreground uppercase tracking-wider">随机延迟</Label>
|
||||
<div class="sm:col-span-3 flex items-center gap-4">
|
||||
<div class="flex items-center gap-2">
|
||||
<Input :model-value="form.random_range" @update:model-value="v => form.random_range = Number(v || 0)" type="number" :min="0" class="w-20 h-9 bg-muted/30 text-center" />
|
||||
<span class="text-xs font-semibold text-muted-foreground">秒</span>
|
||||
</div>
|
||||
<div class="flex-1 text-[11px] text-muted-foreground leading-snug p-2 rounded-lg bg-blue-500/5 border border-blue-500/10 italic">
|
||||
避免高频并发,在基准时间点后延迟 0~{{ form.random_range || 0 }}s
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-start gap-3">
|
||||
<Label class="sm:text-right text-xs text-muted-foreground uppercase tracking-wider">运行策略</Label>
|
||||
<div class="sm:col-span-3 space-y-4">
|
||||
<div class="flex items-center gap-4">
|
||||
<div class="flex items-center gap-2">
|
||||
<Input :model-value="form.timeout" @update:model-value="v => form.timeout = Number(v || 0)" type="number" :min="0" class="w-20 h-9 bg-muted/30 text-center" />
|
||||
<span class="text-[11px] font-semibold text-muted-foreground">分钟超时</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-2 pl-4 border-l">
|
||||
<Select :model-value="cleanType" @update:model-value="(v) => cleanType = String(v || 'none')">
|
||||
<SelectTrigger class="w-28 h-9 text-xs bg-muted/10">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="none">保留日志</SelectItem>
|
||||
<SelectItem value="day">按天清理</SelectItem>
|
||||
<SelectItem value="count">按条清理</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Input v-if="cleanType && cleanType !== 'none'" :model-value="cleanKeep" @update:model-value="v => cleanKeep = Number(v || 30)" type="number" class="w-16 h-9 bg-muted/30 text-center text-xs" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="p-3 rounded-xl bg-muted/20 border border-muted-foreground/10 space-y-2.5">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center gap-2 text-xs font-semibold">
|
||||
<Zap :class="cn('h-3.5 w-3.5', concurrencyEnabled ? 'text-primary' : 'text-muted-foreground')" />
|
||||
并发控制
|
||||
</div>
|
||||
<Switch :model-value="concurrencyEnabled" @update:model-value="onConcurrencyChange" />
|
||||
</div>
|
||||
<p class="text-[11px] text-muted-foreground leading-relaxed">
|
||||
{{ concurrencyEnabled ? '允许同时开启多个同步副本。' : '当前同步未结束时,新触发将被静默忽略。' }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</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>
|
||||
<Select :model-value="repoConfig.source_type"
|
||||
@update:model-value="(v) => repoConfig.source_type = String(v || 'git')">
|
||||
<SelectTrigger class="sm:col-span-3 h-8 text-sm">
|
||||
<SelectValue placeholder="选择源类型" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="git">Git 仓库</SelectItem>
|
||||
<SelectItem value="url">URL 下载</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</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>
|
||||
<Input v-model="repoConfig.source_url"
|
||||
:placeholder="repoConfig.source_type === 'git' ? 'https://github.com/user/repo.git' : 'https://example.com/file.js'"
|
||||
class="sm:col-span-3 h-8 text-xs font-mono" />
|
||||
</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">
|
||||
<DirTreeSelect v-if="selectedAgentId === 'local'" :model-value="repoConfig.target_path || ''"
|
||||
@update:model-value="v => repoConfig.target_path = v" />
|
||||
<Input v-else v-model="repoConfig.target_path" placeholder="Agent 上的目标路径" class="h-8 text-sm" />
|
||||
</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="selectedAgentId" disabled>
|
||||
<SelectTrigger class="h-8 text-sm">
|
||||
<SelectValue placeholder="本地执行" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="local">本地执行</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<p class="text-xs text-muted-foreground mt-1">仓库同步任务暂时仅支持本地执行</p>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="repoConfig.source_type === 'git'"
|
||||
class="grid grid-cols-1 sm:grid-cols-4 items-center gap-2 sm:gap-3">
|
||||
<Label class="sm:text-right text-sm">分支</Label>
|
||||
<Input v-model="repoConfig.branch" placeholder="main (可选)" class="sm:col-span-3 h-8 text-sm"
|
||||
autocomplete="off" />
|
||||
</div>
|
||||
<div v-if="repoConfig.source_type === 'git'"
|
||||
class="grid grid-cols-1 sm:grid-cols-4 items-center gap-2 sm:gap-3">
|
||||
<Label class="sm:text-right text-sm">稀疏路径</Label>
|
||||
<Input v-model="repoConfig.sparse_path" placeholder="仅拉取指定目录或文件 (可选)" class="sm:col-span-3 h-8 text-sm"
|
||||
autocomplete="off" />
|
||||
</div>
|
||||
<div v-if="repoConfig.source_type === 'git' && repoConfig.sparse_path"
|
||||
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">
|
||||
<div class="flex items-center gap-3">
|
||||
<Checkbox id="single-file-sync" v-model="isSingleFile" />
|
||||
<Label for="single-file-sync" class="text-xs text-muted-foreground font-normal cursor-pointer">
|
||||
直接下载文件(适用于单个文件同步)
|
||||
</Label>
|
||||
</div>
|
||||
</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>
|
||||
<Select :model-value="repoConfig.proxy" @update:model-value="(v) => repoConfig.proxy = String(v || 'none')">
|
||||
<SelectTrigger class="sm:col-span-3 h-8 text-sm">
|
||||
<SelectValue placeholder="选择代理" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="opt in proxyOptions" :key="opt.value" :value="opt.value">{{ opt.label }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div v-if="repoConfig.proxy === 'custom'" class="grid grid-cols-1 sm:grid-cols-4 items-center gap-2 sm:gap-3">
|
||||
<Label class="sm:text-right text-sm">代理地址</Label>
|
||||
<Input v-model="repoConfig.proxy_url" placeholder="https://your-proxy.com/"
|
||||
class="sm:col-span-3 h-8 text-xs font-mono" autocomplete="off" />
|
||||
</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">认证Token</Label>
|
||||
<Input v-model="repoConfig.auth_token" type="text" placeholder="可选,用于私有仓库" class="sm:col-span-3 h-8 text-sm"
|
||||
autocomplete="new-password" />
|
||||
</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 flex items-center gap-2">
|
||||
<Switch v-model="concurrencyEnabled" />
|
||||
<span class="text-sm text-muted-foreground">允许并发</span>
|
||||
<span class="text-xs text-muted-foreground ml-2">(如果任务未执行完成,是否允许再次执行)</span>
|
||||
</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>
|
||||
<Input v-model="form.schedule" placeholder="0 0 0 * * *" class="sm:col-span-3 h-8 text-sm font-mono" />
|
||||
</div>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-start gap-2 sm:gap-3">
|
||||
<span></span>
|
||||
<div class="sm:col-span-3">
|
||||
<p class="text-xs text-muted-foreground mb-1.5">格式: 秒 分 时 日 月 周</p>
|
||||
<div class="flex flex-wrap gap-1">
|
||||
<span v-for="preset in cronPresets" :key="preset.value"
|
||||
class="px-1.5 py-0.5 text-xs rounded bg-muted hover:bg-accent cursor-pointer transition-colors"
|
||||
@click="form.schedule = preset.value">
|
||||
{{ preset.label }}
|
||||
</span>
|
||||
</div>
|
||||
</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 flex items-center gap-2">
|
||||
<div class="flex items-center gap-1.5">
|
||||
<Input v-model.number="form.random_range" type="number" :min="0" :step="1" @input="form.random_range = Math.max(0, Math.floor(form.random_range || 0))" placeholder="0" class="w-20 h-9 text-sm" />
|
||||
<span class="text-sm text-muted-foreground whitespace-nowrap">秒</span>
|
||||
</div>
|
||||
</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 flex flex-wrap items-center gap-2">
|
||||
<div class="flex items-center gap-1.5">
|
||||
<Input v-model.number="form.timeout" type="number" :min="0" :step="1" @input="form.timeout = Math.max(0, Math.floor(form.timeout || 0))" placeholder="30" class="w-20 h-9 text-sm" />
|
||||
<span class="text-sm text-muted-foreground whitespace-nowrap">分钟</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-1.5">
|
||||
<Select :model-value="cleanType" @update:model-value="(v) => cleanType = String(v || 'none')">
|
||||
<SelectTrigger class="w-24 h-9 text-sm">
|
||||
<SelectValue placeholder="不清理" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="none">不清理</SelectItem>
|
||||
<SelectItem value="day">按天数</SelectItem>
|
||||
<SelectItem value="count">按条数</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Input v-if="cleanType && cleanType !== 'none'" v-model.number="cleanKeep" type="number"
|
||||
:placeholder="cleanType === 'day' ? '7' : '100'" class="w-20 h-9 text-sm" />
|
||||
</div>
|
||||
</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 flex items-center gap-2">
|
||||
<div class="flex items-center gap-1.5">
|
||||
<Input v-model.number="form.retry_count" type="number" :min="0" :step="1" @input="form.retry_count = Math.max(0, Math.floor(form.retry_count || 0))" placeholder="0" class="w-16 h-9 text-sm" />
|
||||
<span class="text-sm text-muted-foreground whitespace-nowrap">次</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-1.5 ml-2" v-if="form.retry_count && form.retry_count > 0">
|
||||
<span class="text-sm text-muted-foreground whitespace-nowrap">间隔</span>
|
||||
<Input v-model.number="form.retry_interval" type="number" :min="0" :step="1" @input="form.retry_interval = Math.max(0, Math.floor(form.retry_interval || 0))" placeholder="0" class="w-16 h-9 text-sm" />
|
||||
<span class="text-sm text-muted-foreground whitespace-nowrap">秒</span>
|
||||
</div>
|
||||
</ScrollArea>
|
||||
|
||||
<div class="flex items-center justify-between px-6 py-4 bg-muted/30 border-t shrink-0">
|
||||
<p class="text-[10px] text-muted-foreground">最后编辑于: {{ 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 transition-all hover:scale-105 active:scale-95 bg-primary hover:bg-primary/90" @click="save">
|
||||
确定保存
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter class="shrink-0 p-6 pt-3 border-t">
|
||||
<Button variant="outline" size="sm" @click="emit('update:open', false)">取消</Button>
|
||||
<Button size="sm" @click="save">保存</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</template>
|
||||
|
||||
+429
-291
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch } from 'vue'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from '@/components/ui/dialog'
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
@@ -9,7 +9,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@
|
||||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
|
||||
import { ScrollArea } from '@/components/ui/scroll-area'
|
||||
import DirTreeSelect from '@/components/DirTreeSelect.vue'
|
||||
import { Plus, ChevronDown, X, Search, Check, ChevronsUpDown, Loader2, AlertCircle } from 'lucide-vue-next'
|
||||
import { Plus, ChevronDown, X, Search, Check, ChevronsUpDown, Loader2, AlertCircle, Terminal, Clock, Zap } 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'
|
||||
@@ -52,12 +52,21 @@ const envSearchQuery = ref('')
|
||||
const workDirCache = ref<Record<string, string>>({})
|
||||
const concurrency = ref(0)
|
||||
const concurrencyEnabled = ref(false)
|
||||
const allEnvsEnabled = ref(false)
|
||||
|
||||
// 监听 concurrencyEnabled 的变化,同步到 concurrency
|
||||
watch(concurrencyEnabled, (val) => {
|
||||
concurrency.value = val ? 1 : 0
|
||||
})
|
||||
|
||||
function onConcurrencyChange(val: boolean) {
|
||||
concurrencyEnabled.value = val
|
||||
}
|
||||
|
||||
function onAllEnvsChange(val: boolean) {
|
||||
allEnvsEnabled.value = val
|
||||
}
|
||||
|
||||
function addTag() {
|
||||
const val = tagInput.value.trim()
|
||||
if (!val) return
|
||||
@@ -209,7 +218,13 @@ function updateLangName(index: number, name: string) {
|
||||
|
||||
watch(() => props.open, async (val) => {
|
||||
if (val) {
|
||||
form.value = { ...props.task }
|
||||
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
|
||||
}
|
||||
// 解析清理配置
|
||||
if (props.task?.clean_config) {
|
||||
try {
|
||||
@@ -246,9 +261,13 @@ watch(() => props.open, async (val) => {
|
||||
concurrency.value = 1
|
||||
concurrencyEnabled.value = true
|
||||
}
|
||||
|
||||
// 解析全部环境变量配置
|
||||
allEnvsEnabled.value = !!parsed['$task_all_envs']
|
||||
} else {
|
||||
concurrency.value = 1
|
||||
concurrencyEnabled.value = true
|
||||
allEnvsEnabled.value = false
|
||||
}
|
||||
} catch {
|
||||
concurrency.value = 1
|
||||
@@ -344,7 +363,9 @@ async function save() {
|
||||
}
|
||||
|
||||
// 更新并发控制字段 (1: 开启, 0: 关闭)
|
||||
config['$task_concurrency'] = concurrency.value
|
||||
config['$task_concurrency'] = concurrencyEnabled.value ? 1 : 0
|
||||
// 更新注入全部环境变量字段
|
||||
config['$task_all_envs'] = !!allEnvsEnabled.value
|
||||
|
||||
// 重新序列化配置
|
||||
form.value.config = JSON.stringify(config)
|
||||
@@ -369,305 +390,422 @@ async function save() {
|
||||
|
||||
<template>
|
||||
<Dialog :open="open" @update:open="emit('update:open', $event)">
|
||||
<DialogContent class="sm:max-w-[480px]" @openAutoFocus.prevent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>{{ isEdit ? '编辑任务' : '新建任务' }}</DialogTitle>
|
||||
<DialogContent class="sm:max-w-[560px] p-0 overflow-hidden border-none bg-background/95 backdrop-blur-xl shadow-2xl" @openAutoFocus.prevent>
|
||||
<div class="absolute inset-0 bg-gradient-to-br from-primary/5 via-transparent to-primary/5 pointer-events-none" />
|
||||
|
||||
<div class="flex flex-col max-h-[85vh]">
|
||||
<DialogHeader class="px-6 pt-6 pb-2 shrink-0">
|
||||
<DialogTitle class="text-xl font-bold bg-clip-text text-transparent bg-gradient-to-r from-foreground to-foreground/70">
|
||||
{{ isEdit ? '编辑任务' : '新建任务' }}
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div class="space-y-3 py-3">
|
||||
<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>
|
||||
<Input v-model="form.name" placeholder="我的任务" class="sm:col-span-3 h-8 text-sm" />
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-start gap-2 sm:gap-3">
|
||||
<Label class="sm:text-right text-sm pt-1.5">任务标签</Label>
|
||||
<div class="sm:col-span-3 space-y-2">
|
||||
<div class="flex gap-2">
|
||||
<Input v-model="tagInput" placeholder="输入标签名称后点击增加或回车键添加" class="flex-1 h-8 text-sm" @keydown.enter.prevent="addTag" />
|
||||
<Button type="button" variant="outline" size="sm" class="h-8" @click="addTag">
|
||||
增加
|
||||
</Button>
|
||||
<ScrollArea class="flex-1 min-h-0 px-6">
|
||||
<div class="space-y-8 py-4 pb-8">
|
||||
<!-- 基本信息 Section -->
|
||||
<section class="space-y-4">
|
||||
<div class="flex items-center gap-2 mb-1">
|
||||
<div class="h-4 w-1 bg-primary rounded-full" />
|
||||
<h3 class="text-sm font-semibold text-foreground/80">基本信息</h3>
|
||||
</div>
|
||||
<div v-if="form.tags" class="flex flex-wrap gap-2">
|
||||
<span v-for="tag in form.tags.split(',').filter(Boolean)" :key="tag" class="flex items-center gap-1 bg-secondary text-secondary-foreground px-2 py-0.5 rounded-md text-xs border">
|
||||
{{ tag }}
|
||||
<button type="button" class="text-muted-foreground hover:text-foreground outline-none" @click.prevent="removeTag(tag)">
|
||||
<X class="h-3 w-3" />
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
</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="selectedAgentId">
|
||||
<SelectTrigger class="h-8 text-sm">
|
||||
<SelectValue placeholder="选择执行位置" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="local">本地执行</SelectItem>
|
||||
<SelectItem v-for="agent in onlineAgents" :key="agent.id" :value="String(agent.id)">
|
||||
{{ agent.name }} ({{ agent.status === 'online' ? '在线' : '离线' }})
|
||||
</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</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">
|
||||
<span></span>
|
||||
<div class="sm:col-span-3">
|
||||
<div
|
||||
class="flex items-start gap-2 p-2 rounded-md bg-amber-500/10 border border-amber-500/20 text-amber-600 dark:text-amber-500 text-[11px] leading-relaxed">
|
||||
<AlertCircle class="h-3.5 w-3.5 mt-0.5 shrink-0" />
|
||||
<p>请先在<b>「语言依赖」</b>中安装所需的运行时。任务执行时将使用该环境,确保所有依赖已正确配置(如果是执行 <b>bash</b> 脚本,可随便选择一个环境即可)。</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-start gap-2 sm:gap-3">
|
||||
<Label class="sm:text-right text-sm font-medium pt-2">语言环境</Label>
|
||||
<div class="sm:col-span-3 space-y-2">
|
||||
<div v-for="(clang, idx) in selectedLangs" :key="idx" class="flex gap-2">
|
||||
<Popover>
|
||||
<PopoverTrigger asChild>
|
||||
<Button variant="outline" role="combobox" class="justify-between flex-1 h-8 text-sm font-normal">
|
||||
<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">
|
||||
<img :src="getLangIcon(clang.name)" class="w-full h-full object-contain" />
|
||||
</div>
|
||||
<span>{{ clang.name || "选择环境..." }}</span>
|
||||
</div>
|
||||
<ChevronsUpDown class="ml-2 h-3.5 w-3.5 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent class="p-0 w-[240px]" align="start">
|
||||
<div class="p-2 border-b">
|
||||
<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="h-7 pl-8 text-xs" />
|
||||
</div>
|
||||
</div>
|
||||
<ScrollArea class="h-48">
|
||||
<div class="p-1">
|
||||
<div v-if="loadingLangs" class="flex items-center justify-center py-4">
|
||||
<Loader2 class="h-4 w-4 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
<div v-else-if="filteredPlugins.length === 0"
|
||||
class="py-4 text-center text-xs text-muted-foreground">
|
||||
未找到已安装语言
|
||||
</div>
|
||||
<button v-else v-for="p in filteredPlugins" :key="p" @click="updateLangName(idx, p)"
|
||||
class="w-full flex items-center px-2 py-1.5 text-xs rounded-sm hover:bg-muted text-left transition-colors group">
|
||||
<div class="mr-2 h-4 w-4 shrink-0 flex items-center justify-center relative">
|
||||
<div v-if="getLangIcon(p)"
|
||||
class="w-full h-full rounded-sm bg-white overflow-hidden p-0.5 border">
|
||||
<img :src="getLangIcon(p)" class="w-full h-full object-contain" />
|
||||
</div>
|
||||
<div v-else
|
||||
class="w-full h-full flex items-center justify-center bg-primary/10 rounded-sm text-[8px] font-bold uppercase border">
|
||||
{{ p.substring(0, 2) }}
|
||||
</div>
|
||||
<Check v-if="clang.name === p"
|
||||
class="absolute -right-2 -top-1 h-3 w-3 text-primary bg-background rounded-full border shadow-sm" />
|
||||
</div>
|
||||
<span :class="{ 'font-bold text-primary': clang.name === p }">{{ p }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
|
||||
<Popover>
|
||||
<PopoverTrigger asChild :disabled="!clang.name">
|
||||
<Button variant="outline" role="combobox" class="justify-between w-32 h-8 text-sm font-normal"
|
||||
:disabled="!clang.name">
|
||||
<span class="truncate">{{ clang.version || "选择版本..." }}</span>
|
||||
<div class="flex items-center">
|
||||
<ChevronsUpDown class="h-3.5 w-3.5 shrink-0 opacity-50" />
|
||||
</div>
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent class="p-0 w-[140px]" align="start">
|
||||
<div class="p-2 border-b">
|
||||
<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="versionSearch" placeholder="搜索版本..." class="h-7 pl-8 text-xs" />
|
||||
</div>
|
||||
</div>
|
||||
<ScrollArea class="h-48">
|
||||
<div class="p-1">
|
||||
<div v-if="getFilteredVersions(clang.availableVersions).length === 0"
|
||||
class="py-4 text-center text-xs text-muted-foreground">
|
||||
无可用版本
|
||||
</div>
|
||||
<button v-else v-for="v in getFilteredVersions(clang.availableVersions)" :key="v"
|
||||
@click="clang.version = v"
|
||||
class="w-full flex items-center px-2 py-1.5 text-xs rounded-sm hover:bg-muted text-left transition-colors">
|
||||
<Check :class="cn('mr-2 h-3 w-3', clang.version === v ? 'opacity-100' : 'opacity-0')" />
|
||||
<span class="truncate">{{ v }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
|
||||
<Button variant="ghost" size="icon" class="h-8 w-8 text-muted-foreground hover:text-destructive"
|
||||
@click="removeLang(idx)">
|
||||
<X class="h-4 w-4" />
|
||||
</Button>
|
||||
<div class="grid gap-4 pl-3 border-l border-muted">
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3">
|
||||
<Label class="sm:text-right text-xs text-muted-foreground uppercase tracking-wider">任务名称</Label>
|
||||
<Input v-model="form.name" placeholder="输入任务描述性名称" class="sm:col-span-3 h-9 bg-muted/30 border-muted-foreground/20 focus:bg-background transition-all" />
|
||||
</div>
|
||||
|
||||
<Button variant="outline" size="sm" class="w-full h-8 text-xs border-dashed text-muted-foreground"
|
||||
@click="addLang">
|
||||
<Plus class="h-3.5 w-3.5 mr-1" /> 添加语言环境
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<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>
|
||||
<Input v-model="form.command" placeholder="node script.js" class="sm:col-span-3 h-8 text-sm font-mono" />
|
||||
</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">
|
||||
<DirTreeSelect v-if="selectedAgentId === 'local'" v-model="currentWorkDir" />
|
||||
<Input v-else v-model="currentWorkDir" placeholder="工作目录(可选)" class="h-8 text-sm" />
|
||||
</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>
|
||||
<Input v-model="form.schedule" placeholder="0 * * * * *" class="sm:col-span-3 h-8 text-sm font-mono" />
|
||||
</div>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-start gap-2 sm:gap-3">
|
||||
<span></span>
|
||||
<div class="sm:col-span-3">
|
||||
<p class="text-xs text-muted-foreground mb-1.5">格式: 秒 分 时 日 月 周</p>
|
||||
<div class="flex flex-wrap gap-1">
|
||||
<span v-for="preset in cronPresets" :key="preset.value"
|
||||
class="px-1.5 py-0.5 text-xs rounded bg-muted hover:bg-accent cursor-pointer transition-colors"
|
||||
@click="form.schedule = preset.value">
|
||||
{{ preset.label }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-2 sm:gap-3" v-if="selectedTriggerType === TRIGGER_TYPE.CRON">
|
||||
<Label class="sm:text-right text-sm">随机延迟</Label>
|
||||
<div class="sm:col-span-3 flex items-center gap-2">
|
||||
<div class="flex items-center gap-1.5">
|
||||
<Input v-model.number="form.random_range" type="number" :min="0" :step="1" @input="form.random_range = Math.max(0, Math.floor(form.random_range || 0))" placeholder="0" class="w-20 h-9 text-sm" />
|
||||
<span class="text-sm text-muted-foreground whitespace-nowrap">秒</span>
|
||||
</div>
|
||||
<p class="text-[11px] text-muted-foreground ml-1">开启后,任务将在定时时间点后的 0 ~ {{ form.random_range || 0 }} 秒内随机执行。</p>
|
||||
</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 flex flex-wrap items-center gap-2">
|
||||
<div class="flex items-center gap-1.5">
|
||||
<Input v-model.number="form.timeout" type="number" :min="0" :step="1" @input="form.timeout = Math.max(0, Math.floor(form.timeout || 0))" placeholder="30" class="w-20 h-9 text-sm" />
|
||||
<span class="text-sm text-muted-foreground whitespace-nowrap">分钟</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-1.5">
|
||||
<Select :model-value="cleanType" @update:model-value="(v) => cleanType = String(v || 'none')">
|
||||
<SelectTrigger class="w-24 h-9 text-sm">
|
||||
<SelectValue placeholder="不清理" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="none">不清理</SelectItem>
|
||||
<SelectItem value="day">按天数</SelectItem>
|
||||
<SelectItem value="count">按条数</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Input v-if="cleanType && cleanType !== 'none'" v-model.number="cleanKeep" type="number"
|
||||
:placeholder="cleanType === 'day' ? '7' : '100'" class="w-20 h-9 text-sm" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-start gap-2 sm:gap-3">
|
||||
<Label class="sm:text-right text-sm pt-2">并发控制</Label>
|
||||
<div class="sm:col-span-3 space-y-1.5">
|
||||
<div class="flex items-center gap-2">
|
||||
<Switch v-model="concurrencyEnabled" />
|
||||
<span class="text-sm text-muted-foreground">允许并发</span>
|
||||
</div>
|
||||
<p class="text-xs text-muted-foreground">如果任务未执行完成,是否允许再次执行</p>
|
||||
</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 flex items-center gap-2">
|
||||
<div class="flex items-center gap-1.5">
|
||||
<Input v-model.number="form.retry_count" type="number" :min="0" :step="1" @input="form.retry_count = Math.max(0, Math.floor(form.retry_count || 0))" placeholder="0" class="w-16 h-9 text-sm" />
|
||||
<span class="text-sm text-muted-foreground whitespace-nowrap">次</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-1.5 ml-2" v-if="form.retry_count && form.retry_count > 0">
|
||||
<span class="text-sm text-muted-foreground whitespace-nowrap">间隔</span>
|
||||
<Input v-model.number="form.retry_interval" type="number" :min="0" :step="1" @input="form.retry_interval = Math.max(0, Math.floor(form.retry_interval || 0))" placeholder="0" class="w-16 h-9 text-sm" />
|
||||
<span class="text-sm text-muted-foreground whitespace-nowrap">秒</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-start gap-2 sm:gap-3">
|
||||
<Label class="sm:text-right text-sm pt-1.5">环境变量</Label>
|
||||
<div class="sm:col-span-3 space-y-1.5">
|
||||
<Popover>
|
||||
<PopoverTrigger as-child>
|
||||
<Button variant="outline" class="w-full justify-between font-normal h-8 text-sm">
|
||||
<span class="text-muted-foreground text-xs">搜索并添加环境变量...</span>
|
||||
<ChevronDown class="h-3.5 w-3.5 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent class="w-[260px] p-2" align="start">
|
||||
<Input v-model="envSearchQuery" placeholder="搜索环境变量..." class="mb-2 h-7 text-sm" />
|
||||
<div v-if="filteredEnvVars.length === 0" class="text-xs text-muted-foreground text-center py-2">
|
||||
{{ allEnvVars.length === 0 ? '暂无环境变量' : '无匹配结果' }}
|
||||
</div>
|
||||
<div v-else class="max-h-[140px] overflow-y-auto space-y-0.5">
|
||||
<div v-for="env in filteredEnvVars" :key="env.id"
|
||||
class="flex items-center gap-2 px-2 py-1 rounded hover:bg-muted cursor-pointer text-xs"
|
||||
@click="addEnv(env.id)">
|
||||
<Plus class="h-3 w-3 text-muted-foreground" />
|
||||
<span class="truncate">{{ env.name }}</span>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-start gap-3">
|
||||
<Label class="sm:text-right text-xs text-muted-foreground uppercase tracking-wider pt-2.5">任务标签</Label>
|
||||
<div class="sm:col-span-3 space-y-2">
|
||||
<div class="flex gap-2">
|
||||
<div class="relative flex-1">
|
||||
<Input v-model="tagInput" placeholder="输入标签按回车..." class="h-9 bg-muted/30 border-muted-foreground/20 pr-12" @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="addTag">
|
||||
添加
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="form.tags" class="flex flex-wrap gap-1.5 pt-1">
|
||||
<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">
|
||||
{{ tag }}
|
||||
<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>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
<div v-if="selectedEnvs.length > 0" class="flex flex-wrap gap-1">
|
||||
<div v-for="env in selectedEnvs" :key="env.id"
|
||||
class="inline-flex items-center gap-0.5 px-2 py-0.5 text-xs h-5 rounded-full bg-secondary text-secondary-foreground">
|
||||
<span>{{ env.name }}</span>
|
||||
<X class="h-2.5 w-2.5 cursor-pointer hover:text-destructive" @click="removeEnv(env.id)" />
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3">
|
||||
<Label class="sm:text-right text-xs text-muted-foreground uppercase tracking-wider">执行位置</Label>
|
||||
<div class="sm:col-span-3">
|
||||
<Select v-model="selectedAgentId">
|
||||
<SelectTrigger class="h-9 bg-muted/30 border-muted-foreground/20">
|
||||
<SelectValue placeholder="选择执行节点" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<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>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3">
|
||||
<Label class="sm:text-right text-xs text-muted-foreground uppercase tracking-wider">触发方式</Label>
|
||||
<div class="sm:col-span-3">
|
||||
<Select v-model="selectedTriggerType">
|
||||
<SelectTrigger class="h-9 bg-muted/30 border-muted-foreground/20">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem :value="TRIGGER_TYPE.CRON">⏳ 定时周期触发</SelectItem>
|
||||
<SelectItem :value="TRIGGER_TYPE.BAIHU_STARTUP">🚀 系统启动触发</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 命令配置 Section -->
|
||||
<section class="space-y-4">
|
||||
<div class="flex items-center gap-2 mb-1">
|
||||
<div class="h-4 w-1 bg-primary rounded-full" />
|
||||
<h3 class="text-sm font-semibold text-foreground/80">执行配置</h3>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-4 pl-3 border-l border-muted">
|
||||
<!-- 语言环境 -->
|
||||
<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">
|
||||
<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">
|
||||
<AlertCircle class="h-4 w-4 shrink-0 text-amber-500" />
|
||||
<p>请先在<b>「语言依赖」</b>中安装所需的运行时。任务执行时将使用该环境,确保所有依赖已正确配置(如果是执行 <b>bash</b> 脚本,可随便选择一个环境即可)。</p> </div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-start gap-3">
|
||||
<Label class="sm:text-right text-xs text-muted-foreground uppercase tracking-wider pt-2.5">语言环境</Label>
|
||||
<div class="sm:col-span-3 space-y-2">
|
||||
<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">
|
||||
<div class="absolute left-0 top-0 bottom-0 w-0.5 bg-primary/20 group-hover/lang:bg-primary transition-colors" />
|
||||
<Popover>
|
||||
<PopoverTrigger asChild>
|
||||
<Button variant="ghost" role="combobox" 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>
|
||||
<PopoverContent class="p-0 w-[240px]" align="start">
|
||||
<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="h-8 pl-8 text-xs bg-background" />
|
||||
</div>
|
||||
</div>
|
||||
<ScrollArea class="h-48 p-1">
|
||||
<div v-if="loadingLangs" class="flex items-center justify-center py-6">
|
||||
<Loader2 class="h-5 w-5 animate-spin text-primary/50" />
|
||||
</div>
|
||||
<div v-else-if="filteredPlugins.length === 0" class="py-6 text-center text-xs text-muted-foreground">
|
||||
未找到匹配项
|
||||
</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 group/item mb-0.5">
|
||||
<div class="mr-3 h-5 w-5 shrink-0 flex items-center justify-center transition-transform group-hover/item:scale-110">
|
||||
<img v-if="getLangIcon(p)" :src="getLangIcon(p)" class="w-full h-full object-contain p-0.5 bg-white rounded border" />
|
||||
<div v-else class="w-full h-full flex items-center justify-center bg-primary/10 rounded-sm text-[8px] font-bold border">
|
||||
{{ p.substring(0, 2) }}
|
||||
</div>
|
||||
</div>
|
||||
<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>
|
||||
</ScrollArea>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
|
||||
<Popover>
|
||||
<PopoverTrigger asChild :disabled="!clang.name">
|
||||
<Button variant="ghost" role="combobox" 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>
|
||||
<PopoverContent class="p-0 w-[160px]" align="start">
|
||||
<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="versionSearch" placeholder="搜索版本..." class="h-8 pl-8 text-xs bg-background" />
|
||||
</div>
|
||||
</div>
|
||||
<ScrollArea class="h-48 p-1">
|
||||
<div v-if="getFilteredVersions(clang.availableVersions).length === 0" class="py-6 text-center text-xs text-muted-foreground">
|
||||
无可用版本
|
||||
</div>
|
||||
<button v-else 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 text-left mb-0.5 font-mono">
|
||||
<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>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
|
||||
<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>
|
||||
</div>
|
||||
|
||||
<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/10 hover:bg-primary/5"
|
||||
@click="addLang">
|
||||
<Plus class="h-4 w-4 mr-2" /> 添加运行时环境 (Mise)
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3">
|
||||
<Label class="sm:text-right text-xs text-muted-foreground uppercase tracking-wider font-semibold">执行命令</Label>
|
||||
<div class="sm:col-span-3 relative">
|
||||
<Input v-model="form.command" placeholder="例如: python main.py --args" class="h-9 font-mono text-[13px] bg-muted/30 border-muted-foreground/20 focus:bg-background pr-10" />
|
||||
<Terminal class="absolute right-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground opacity-40" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3">
|
||||
<Label class="sm:text-right text-xs text-muted-foreground uppercase tracking-wider">工作目录</Label>
|
||||
<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="h-9 bg-muted/30 border-muted-foreground/20" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 环境变量注入模式 -->
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3 pb-1">
|
||||
<Label class="sm:text-right text-xs text-muted-foreground uppercase tracking-wider font-semibold">注入模式</Label>
|
||||
<div class="sm:col-span-3">
|
||||
<div class="flex items-center space-x-3 h-9">
|
||||
<div class="flex items-center space-x-2 bg-muted/20 px-3 py-1.5 rounded-full border border-muted-foreground/10">
|
||||
<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>
|
||||
<Popover>
|
||||
<PopoverTrigger as-child>
|
||||
<Button variant="ghost" size="icon" class="h-6 w-6 opacity-40 hover:opacity-100 hover:text-primary transition-all">
|
||||
<AlertCircle class="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent class="w-80 p-4 text-[12px] bg-background/95 backdrop-blur-md border-primary/20 shadow-2xl ring-1 ring-primary/5" align="start">
|
||||
<div class="flex items-start gap-3">
|
||||
<div class="h-8 w-8 rounded-full bg-primary/10 flex items-center justify-center shrink-0">
|
||||
<Zap class="h-4 w-4 text-primary" />
|
||||
</div>
|
||||
<div class="space-y-2.5">
|
||||
<p class="font-bold text-xs uppercase tracking-tight text-primary">安全与全局提示</p>
|
||||
<p class="text-muted-foreground leading-normal">
|
||||
开启此项后,<span class="text-foreground font-semibold underline decoration-primary/30">所有</span> 存储在面板中的环境变量都将直接注入到此脚本的运行进程中。
|
||||
</p>
|
||||
<div class="bg-destructive/10 border border-destructive/20 rounded-md p-2.5 text-destructive/80 text-[11px]">
|
||||
<strong>警告:</strong>此操作允许脚本访问您所有的敏感密钥。如果运行的是来源不明的第三方脚本,极其不建议开启此项。
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="!allEnvsEnabled" class="grid grid-cols-1 sm:grid-cols-4 items-start gap-3">
|
||||
<Label class="sm:text-right text-xs text-muted-foreground uppercase tracking-wider pt-2.5">按需包含</Label>
|
||||
<div class="sm:col-span-3 space-y-2">
|
||||
<Popover>
|
||||
<PopoverTrigger as-child>
|
||||
<Button variant="outline" class="w-full justify-between h-9 bg-muted/10 border-muted-foreground/20 hover:bg-muted/30 font-normal transition-colors group">
|
||||
<div class="flex items-center gap-2 text-muted-foreground group-hover:text-foreground">
|
||||
<Search class="h-3.5 w-3.5 opacity-40" />
|
||||
<span class="text-xs">选择关联的环境变量...</span>
|
||||
</div>
|
||||
<ChevronDown class="h-4 w-4 opacity-30" />
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent class="p-0 w-[400px]" align="start">
|
||||
<div class="p-3 border-b bg-muted/20">
|
||||
<div class="relative">
|
||||
<Search class="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground opacity-50" />
|
||||
<Input v-model="envSearchQuery" placeholder="搜索变量名或备注..." class="pl-9 h-10 text-sm bg-background border-primary/20" />
|
||||
</div>
|
||||
</div>
|
||||
<ScrollArea class="h-64 p-2">
|
||||
<div v-if="filteredEnvVars.length === 0" class="py-12 text-center text-xs text-muted-foreground flex flex-col items-center gap-2">
|
||||
<Search class="h-8 w-8 opacity-10" />
|
||||
未找到可用变量
|
||||
</div>
|
||||
<div v-for="env in filteredEnvVars" :key="env.id" @click="addEnv(env.id)"
|
||||
class="flex flex-col p-3 rounded-lg hover:bg-primary/5 cursor-pointer transition-all border border-transparent hover:border-primary/10 mb-1 group">
|
||||
<div class="flex items-center justify-between mb-1">
|
||||
<span class="text-sm font-mono font-bold tracking-tight group-hover:text-primary transition-colors">{{ env.name }}</span>
|
||||
<Button variant="ghost" size="icon" class="h-6 w-6 opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
<Plus class="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
<div class="text-[11px] text-muted-foreground line-clamp-1 opacity-70">{{ env.remark || "暂无备注" }}</div>
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
|
||||
<div v-if="selectedEnvs.length > 0" class="flex flex-wrap gap-2 p-3 rounded-xl bg-muted/20 border border-muted-foreground/10 min-h-12 shadow-inner">
|
||||
<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/20 text-xs hover:border-primary/50 hover:bg-primary/5 transition-all group shadow-sm">
|
||||
<span class="font-mono font-medium opacity-80 pl-1">{{ env?.name }}</span>
|
||||
<Button variant="ghost" size="icon" class="h-4 w-4 rounded-full p-0 text-muted-foreground hover:text-destructive hover:bg-destructive/10"
|
||||
@click="removeEnv(env!.id)">
|
||||
<X class="h-2.5 w-2.5" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 调度与策略 Section -->
|
||||
<section class="space-y-4">
|
||||
<div class="flex items-center gap-2 mb-1">
|
||||
<div class="h-4 w-1 bg-primary rounded-full" />
|
||||
<h3 class="text-sm font-semibold text-foreground/80">调度策略</h3>
|
||||
</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">
|
||||
<Label class="sm:text-right text-xs text-muted-foreground uppercase tracking-wider font-semibold">定时规则</Label>
|
||||
<div class="sm:col-span-3">
|
||||
<Input v-model="form.schedule" placeholder="* * * * * *" class="h-9 font-mono text-[13px] bg-muted/30 border-muted-foreground/20 focus:ring-1 focus:ring-primary/50" />
|
||||
<div class="mt-2.5 space-y-2">
|
||||
<div class="flex items-center gap-1.5 text-[10px] text-muted-foreground/70 uppercase font-bold tracking-tighter">
|
||||
<Clock class="h-3 w-3" /> 格式指导: 秒 分 时 日 月 周
|
||||
</div>
|
||||
<div class="flex flex-wrap gap-1.5">
|
||||
<button v-for="preset in cronPresets" :key="preset.value"
|
||||
class="px-2 py-1 text-[10px] rounded-md bg-muted/50 border border-muted-foreground/10 hover:border-primary/50 hover:bg-primary/5 hover:text-primary transition-all font-medium"
|
||||
@click.prevent="form.schedule = preset.value">
|
||||
{{ preset.label }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3">
|
||||
<Label class="sm:text-right text-xs text-muted-foreground uppercase tracking-wider">随机延迟</Label>
|
||||
<div class="sm:col-span-3 flex items-center gap-4">
|
||||
<div class="flex items-center gap-2 group">
|
||||
<Input :model-value="form.random_range" @update:model-value="v => form.random_range = Number(v || 0)" type="number" :min="0" class="w-20 h-9 bg-muted/30 text-center" />
|
||||
<span class="text-xs font-semibold text-muted-foreground">秒</span>
|
||||
</div>
|
||||
<div class="flex-1 text-[11px] text-muted-foreground leading-snug p-2 rounded-lg bg-blue-500/5 border border-blue-500/10 italic">
|
||||
在执行点后的 0 ~ {{ form.random_range || 0 }}s 随机触发
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-center gap-3">
|
||||
<Label class="sm:text-right text-xs text-muted-foreground uppercase tracking-wider">失败策略</Label>
|
||||
<div class="sm:col-span-3 flex items-center gap-3">
|
||||
<div class="flex items-center gap-2 flex-1">
|
||||
<span class="text-[11px] text-muted-foreground mr-1 whitespace-nowrap">重试</span>
|
||||
<Input :model-value="form.retry_count" @update:model-value="v => form.retry_count = Number(v || 0)" type="number" :min="0" class="w-20 h-9 bg-muted/30 text-center" />
|
||||
<span class="text-[11px] text-muted-foreground whitespace-nowrap ml-1">次</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-2 flex-1" v-if="form.retry_count && form.retry_count > 0">
|
||||
<span class="text-[11px] text-muted-foreground mr-1 whitespace-nowrap">间隔</span>
|
||||
<Input :model-value="form.retry_interval" @update:model-value="v => form.retry_interval = Number(v || 0)" type="number" :min="0" class="w-20 h-9 bg-muted/30 text-center" />
|
||||
<span class="text-[11px] text-muted-foreground whitespace-nowrap ml-1">秒</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-4 items-start gap-3">
|
||||
<Label class="sm:text-right text-xs text-muted-foreground uppercase tracking-wider">运行策略</Label>
|
||||
<div class="sm:col-span-3 space-y-4">
|
||||
<!-- 超时控制 -->
|
||||
<div class="flex items-center gap-4">
|
||||
<div class="flex items-center gap-2">
|
||||
<Input :model-value="form.timeout" @update:model-value="v => form.timeout = Number(v || 0)" type="number" :min="0" class="w-20 h-9 bg-muted/30 text-center" />
|
||||
<span class="text-[11px] font-semibold text-muted-foreground">分钟超时</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-2 pl-4 border-l">
|
||||
<Select :model-value="cleanType" @update:model-value="(v) => cleanType = String(v || 'none')">
|
||||
<SelectTrigger class="w-28 h-9 text-xs bg-muted/10">
|
||||
<SelectValue placeholder="日志策略" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="none">永久保留日志</SelectItem>
|
||||
<SelectItem value="day">按天数清理</SelectItem>
|
||||
<SelectItem value="count">按条目清理</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Input v-if="cleanType && cleanType !== 'none'" :model-value="cleanKeep" @update:model-value="v => cleanKeep = Number(v || 30)" type="number"
|
||||
class="w-16 h-9 bg-muted/30 text-center text-xs" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 并发控制 -->
|
||||
<div class="p-3 rounded-xl bg-muted/20 border border-muted-foreground/10 space-y-2.5">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center gap-2 text-xs font-semibold">
|
||||
<Zap :class="cn('h-3.5 w-3.5', concurrencyEnabled ? 'text-primary' : 'text-muted-foreground')" />
|
||||
并发控制
|
||||
</div>
|
||||
<Switch :model-value="concurrencyEnabled" @update:model-value="onConcurrencyChange" />
|
||||
</div>
|
||||
<p class="text-[11px] text-muted-foreground leading-relaxed">
|
||||
{{ concurrencyEnabled ? '允许同时开启多个执行副本,不限制并行。' : '当前任务正在执行时,再次触发将被忽略。' }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</ScrollArea>
|
||||
|
||||
<div class="flex items-center justify-between px-6 py-4 bg-muted/30 border-t shrink-0">
|
||||
<p class="text-[10px] text-muted-foreground">最后编辑于: {{ 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 transition-all hover:scale-105 active:scale-95 bg-primary hover:bg-primary/90" @click="save">
|
||||
确定保存
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" size="sm" @click="emit('update:open', false)">取消</Button>
|
||||
<Button size="sm" @click="save">保存</Button>
|
||||
</DialogFooter>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user