feat: add more opt feature

This commit is contained in:
engigu
2026-02-26 20:29:20 +08:00
parent acc65dce64
commit b127d7a3d5
12 changed files with 258 additions and 38 deletions
+48
View File
@@ -269,6 +269,54 @@ func (fc *FileController) MoveFile(c *gin.Context) {
utils.Success(c, nil)
}
func (fc *FileController) CopyFile(c *gin.Context) {
var req struct {
SourcePath string `json:"sourcePath" binding:"required"`
TargetPath string `json:"targetPath" binding:"required"`
}
if err := c.ShouldBindJSON(&req); err != nil {
utils.BadRequest(c, err.Error())
return
}
sourceFull, sourceSafe := fc.checkPath(req.SourcePath, false)
targetFull, targetSafe := fc.checkPath(req.TargetPath, false)
if !sourceSafe || !targetSafe {
utils.Forbidden(c, "访问被拒绝")
return
}
if sourceFull == targetFull {
utils.Success(c, nil)
return
}
// Read content
content, err := os.ReadFile(sourceFull)
if err != nil {
utils.NotFound(c, "源文件不存在或无法读取")
return
}
// 确保目标目录存在
os.MkdirAll(filepath.Dir(targetFull), 0755)
// 检查目标是否存在
if _, err := os.Stat(targetFull); err == nil {
utils.BadRequest(c, "目标已存在")
return
}
if err := os.WriteFile(targetFull, content, 0644); err != nil {
utils.ServerError(c, err.Error())
return
}
utils.Success(c, nil)
}
func (fc *FileController) RenameFile(c *gin.Context) {
var req struct {
OldPath string `json:"oldPath" binding:"required"`
+7 -3
View File
@@ -54,6 +54,7 @@ func (tc *TaskController) CreateTask(c *gin.Context) {
var req struct {
Name string `json:"name" binding:"required"`
Command string `json:"command"`
Tags string `json:"tags"`
Type string `json:"type"`
Config string `json:"config"`
Schedule string `json:"schedule"`
@@ -90,7 +91,7 @@ func (tc *TaskController) CreateTask(c *gin.Context) {
workDir = resolveWorkDir(req.WorkDir)
}
task := tc.taskService.CreateTask(req.Name, req.Command, req.Schedule, req.Timeout, workDir, req.CleanConfig, req.Envs, req.Type, req.Config, req.AgentID, req.Languages, req.TriggerType)
task := tc.taskService.CreateTask(req.Name, req.Command, req.Schedule, req.Timeout, workDir, req.CleanConfig, req.Envs, req.Type, req.Config, req.AgentID, req.Languages, req.TriggerType, req.Tags)
// 如果是 Agent 任务,通知 Agent;否则添加到本地 cron
if task.AgentID != nil && *task.AgentID > 0 {
@@ -107,6 +108,8 @@ func (tc *TaskController) GetTasks(c *gin.Context) {
name := c.DefaultQuery("name", "")
agentIDStr := c.DefaultQuery("agent_id", "")
tags := c.DefaultQuery("tags", "")
var agentID *uint
if agentIDStr != "" {
if id, err := strconv.ParseUint(agentIDStr, 10, 32); err == nil {
@@ -115,7 +118,7 @@ func (tc *TaskController) GetTasks(c *gin.Context) {
}
}
tasks, total := tc.taskService.GetTasksWithPagination(p.Page, p.PageSize, name, agentID)
tasks, total := tc.taskService.GetTasksWithPagination(p.Page, p.PageSize, name, agentID, tags)
utils.PaginatedResponse(c, vo.ToTaskVOListFromModels(tasks), total, p)
}
@@ -152,6 +155,7 @@ func (tc *TaskController) UpdateTask(c *gin.Context) {
var req struct {
Name string `json:"name"`
Command string `json:"command"`
Tags string `json:"tags"`
Type string `json:"type"`
Config string `json:"config"`
Schedule string `json:"schedule"`
@@ -183,7 +187,7 @@ func (tc *TaskController) UpdateTask(c *gin.Context) {
workDir = resolveWorkDir(req.WorkDir)
}
task := tc.taskService.UpdateTask(id, req.Name, req.Command, req.Schedule, req.Timeout, workDir, req.CleanConfig, req.Envs, req.Enabled, req.Type, req.Config, req.AgentID, req.Languages, req.TriggerType)
task := tc.taskService.UpdateTask(id, req.Name, req.Command, req.Schedule, req.Timeout, workDir, req.CleanConfig, req.Envs, req.Enabled, req.Type, req.Config, req.AgentID, req.Languages, req.TriggerType, req.Tags)
if task == nil {
utils.NotFound(c, "任务不存在")
return
+1
View File
@@ -37,6 +37,7 @@ type Task struct {
ID uint `json:"id" gorm:"primaryKey"`
Name string `json:"name" gorm:"size:255;not null"`
Command string `json:"command" gorm:"type:text"` // 普通任务的命令
Tags string `json:"tags" gorm:"size:255;default:''"` // 标签,逗号分隔
Type string `json:"type" gorm:"size:20;default:'task'"` // 任务类型: constant.TaskTypeNormal, constant.TaskTypeRepo
TriggerType string `json:"trigger_type" gorm:"size:25;default:'cron'"` // 触发类型: constant.TriggerTypeCron, constant.TriggerTypeBaihuStartup
Config string `json:"config" gorm:"type:text"` // 配置 JSON(仓库同步配置等)
+2
View File
@@ -10,6 +10,7 @@ type TaskVO struct {
ID uint `json:"id"`
Name string `json:"name"`
Command string `json:"command"`
Tags string `json:"tags"`
Type string `json:"type"`
TriggerType string `json:"trigger_type"`
Config string `json:"config"`
@@ -36,6 +37,7 @@ func ToTaskVO(task *models.Task) *TaskVO {
ID: task.ID,
Name: task.Name,
Command: task.Command,
Tags: task.Tags,
Type: task.Type,
TriggerType: task.TriggerType,
Config: task.Config,
+1
View File
@@ -163,6 +163,7 @@ func Setup(c *Controllers) *gin.Engine {
files.POST("/delete", c.File.DeleteFile)
files.POST("/rename", c.File.RenameFile)
files.POST("/move", c.File.MoveFile)
files.POST("/copy", c.File.CopyFile)
files.POST("/upload", c.File.UploadArchive)
files.POST("/uploadfiles", c.File.UploadFiles)
}
+8 -3
View File
@@ -12,7 +12,7 @@ func NewTaskService() *TaskService {
return &TaskService{}
}
func (ts *TaskService) CreateTask(name, command, schedule string, timeout int, workDir, cleanConfig, envs, taskType, config string, agentID *uint, languages []map[string]string, triggerType string) *models.Task {
func (ts *TaskService) CreateTask(name, command, schedule string, timeout int, workDir, cleanConfig, envs, taskType, config string, agentID *uint, languages []map[string]string, triggerType string, tags string) *models.Task {
if taskType == "" {
taskType = "task"
}
@@ -22,6 +22,7 @@ func (ts *TaskService) CreateTask(name, command, schedule string, timeout int, w
task := &models.Task{
Name: name,
Command: command,
Tags: tags,
Type: taskType,
TriggerType: triggerType,
Config: config,
@@ -48,7 +49,7 @@ func (ts *TaskService) GetTasks() []models.Task {
}
// GetTasksWithPagination 分页获取任务列表
func (ts *TaskService) GetTasksWithPagination(page, pageSize int, name string, agentID *uint) ([]models.Task, int64) {
func (ts *TaskService) GetTasksWithPagination(page, pageSize int, name string, agentID *uint, tags string) ([]models.Task, int64) {
var tasks []models.Task
var total int64
@@ -56,6 +57,9 @@ func (ts *TaskService) GetTasksWithPagination(page, pageSize int, name string, a
if name != "" {
query = query.Where("name LIKE ?", "%"+name+"%")
}
if tags != "" {
query = query.Where("tags LIKE ?", "%"+tags+"%")
}
if agentID != nil {
query = query.Where("agent_id = ?", *agentID)
}
@@ -74,13 +78,14 @@ func (ts *TaskService) GetTaskByID(id int) *models.Task {
return &task
}
func (ts *TaskService) UpdateTask(id int, name, command, schedule string, timeout int, workDir, cleanConfig, envs string, enabled bool, taskType, config string, agentID *uint, languages []map[string]string, triggerType string) *models.Task {
func (ts *TaskService) UpdateTask(id int, name, command, schedule string, timeout int, workDir, cleanConfig, envs string, enabled bool, taskType, config string, agentID *uint, languages []map[string]string, triggerType string, tags string) *models.Task {
var task models.Task
if err := database.DB.First(&task, id).Error; err != nil {
return nil
}
task.Name = name
task.Command = command
task.Tags = tags
task.Schedule = schedule
task.Timeout = timeout
task.WorkDir = workDir
+4 -1
View File
@@ -58,11 +58,12 @@ export const api = {
request('/auth/register', { method: 'POST', body: JSON.stringify(data) })
},
tasks: {
list: (params?: { page?: number; page_size?: number; name?: string; agent_id?: number }) => {
list: (params?: { page?: number; page_size?: number; name?: string; agent_id?: number; tags?: string }) => {
const query = new URLSearchParams()
if (params?.page) query.set('page', String(params.page))
if (params?.page_size) query.set('page_size', String(params.page_size))
if (params?.name) query.set('name', params.name)
if (params?.tags) query.set('tags', params.tags)
if (params?.agent_id) query.set('agent_id', String(params.agent_id))
return request<TaskListResponse>(`/tasks?${query}`)
},
@@ -160,6 +161,7 @@ export const api = {
delete: (path: string) => request('/files/delete', { method: 'POST', body: JSON.stringify({ path }) }),
rename: (oldPath: string, newPath: string) => request('/files/rename', { method: 'POST', body: JSON.stringify({ oldPath, newPath }) }),
move: (oldPath: string, newPath: string) => request('/files/move', { method: 'POST', body: JSON.stringify({ oldPath, newPath }) }),
copy: (sourcePath: string, targetPath: string) => request('/files/copy', { method: 'POST', body: JSON.stringify({ sourcePath, targetPath }) }),
uploadArchive: async (file: File, targetPath?: string) => {
const formData = new FormData()
formData.append('file', file)
@@ -265,6 +267,7 @@ export interface Task {
id: number
name: string
command: string
tags: string
type: string
trigger_type: string
config: string
+19 -3
View File
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { computed, ref } from 'vue'
import { Folder, File, ChevronRight, ChevronDown } from 'lucide-vue-next'
import { Folder, File, ChevronRight, ChevronDown, Trash2, Copy as CopyIcon } from 'lucide-vue-next'
import type { FileNode } from '@/api'
defineOptions({
@@ -20,6 +20,8 @@ const emit = defineEmits<{
create: [parentDir: string]
move: [oldPath: string, newPath: string]
rename: [path: string]
downloadFile: [path: string]
duplicate: [path: string]
}>()
const depth = computed(() => props.depth ?? 0)
@@ -84,13 +86,27 @@ function handleDrop(e: DragEvent) {
<span v-else class="w-3" />
<Folder v-if="node.isDir" class="h-3 w-3 text-yellow-500 flex-shrink-0" />
<File v-else class="h-3 w-3 text-blue-500 flex-shrink-0" />
<span class="truncate flex-1">{{ node.name }}</span>
<span class="truncate">{{ node.name }}</span>
<div v-if="!node.isDir" class="opacity-0 group-hover:opacity-100 flex items-center gap-1 ml-auto shrink-0 pr-1 transition-opacity">
<span @click.stop="$emit('duplicate', node.path)" class="cursor-pointer text-muted-foreground hover:text-foreground" title="复制">
<CopyIcon class="h-3 w-3" />
</span>
<span @click.stop="$emit('delete', node.path)" class="cursor-pointer text-destructive hover:text-destructive/80" title="删除">
<Trash2 class="h-3 w-3" />
</span>
</div>
<div v-else class="opacity-0 group-hover:opacity-100 flex items-center gap-1 ml-auto shrink-0 pr-1 transition-opacity">
<span @click.stop="$emit('delete', node.path)" class="cursor-pointer text-destructive hover:text-destructive/80" title="删除">
<Trash2 class="h-3 w-3" />
</span>
</div>
</div>
<template v-if="node.isDir && isExpanded && node.children">
<FileTreeNode v-for="child in node.children" :key="child.path" :node="child" :expanded-dirs="expandedDirs"
:selected-path="selectedPath" :depth="depth + 1" @select="$emit('select', $event)"
@create="$emit('create', $event)" @move="(oldPath, newPath) => $emit('move', oldPath, newPath)"
@rename="$emit('rename', $event)" />
@rename="$emit('rename', $event)" @delete="$emit('delete', $event)" @download-file="$emit('downloadFile', $event)"
@duplicate="$emit('duplicate', $event)" />
</template>
</div>
</template>
+26 -1
View File
@@ -267,6 +267,31 @@ async function handleDownload(path: string) {
}
}
async function handleCopyFile(path: string) {
console.log('Copy file requested:', path)
try {
const parts = path.split('/')
const filename = parts.pop() || ''
const dir = parts.join('/')
const dotIndex = filename.lastIndexOf('.')
let newFilename = ''
if (dotIndex !== -1 && dotIndex > 0) {
newFilename = filename.substring(0, dotIndex) + '-副本' + filename.substring(dotIndex)
} else {
newFilename = filename + '-副本'
}
const targetPath = dir ? `${dir}/${newFilename}` : newFilename
await api.files.copy(path, targetPath)
toast.success('已复制为 ' + newFilename)
await loadTree()
} catch (error: any) {
toast.error('复制失败: ' + (error.message || '未知错误'))
}
}
onMounted(loadTree)
</script>
@@ -295,7 +320,7 @@ onMounted(loadTree)
</div>
<FileTreeNode v-for="node in fileTree" :key="node.path" :node="node" :expanded-dirs="expandedDirs"
:selected-path="selectedFile || selectedDir" @select="handleSelect" @delete="confirmDeleteFile"
@download-file="handleDownload" />
@download-file="handleDownload" @duplicate="handleCopyFile" />
</div>
</div>
+37
View File
@@ -8,6 +8,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@
import { Switch } from '@/components/ui/switch'
import { Checkbox } from '@/components/ui/checkbox'
import DirTreeSelect from '@/components/DirTreeSelect.vue'
import { X } from 'lucide-vue-next'
import { api, type Task, type RepoConfig, type Agent } from '@/api'
import { toast } from 'vue-sonner'
@@ -58,6 +59,23 @@ const cleanType = ref('none')
const cleanKeep = ref(30)
const allAgents = ref<Agent[]>([])
const selectedAgentId = ref<string>('local')
const tagInput = ref('')
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(',')
}
const concurrencyEnabled = computed({
get: () => repoConfig.value.concurrency === 1,
@@ -178,6 +196,25 @@ async function save() {
<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>
</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"
+37
View File
@@ -39,6 +39,7 @@ const cronPresets = [
]
const form = ref<Partial<Task>>({})
const tagInput = ref('')
const cleanType = ref('none')
const cleanKeep = ref(30)
const allEnvVars = ref<EnvVar[]>([])
@@ -57,6 +58,22 @@ watch(concurrencyEnabled, (val) => {
concurrency.value = val ? 1 : 0
})
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(',')
}
// 当前显示的工作目录(根据选择的执行位置)
const currentWorkDir = computed({
get: () => workDirCache.value[selectedAgentId.value] || '',
@@ -362,6 +379,26 @@ async function save() {
<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>
</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">
+68 -27
View File
@@ -6,8 +6,8 @@ import { Input } from '@/components/ui/input'
import Pagination from '@/components/Pagination.vue'
import TaskDialog from './TaskDialog.vue'
import RepoDialog from './RepoDialog.vue'
import { Plus, Play, Pencil, Trash2, Search, ScrollText, GitBranch, Terminal, Server, Monitor, X, Loader2, Wifi, WifiOff, Zap, ZapOff } from 'lucide-vue-next'
import { api, type Task, type Agent } from '@/api'
import { Plus, Play, Pencil, Trash2, Search, ScrollText, GitBranch, Terminal, Server, Monitor, X, Loader2, Wifi, WifiOff, Zap, ZapOff, Copy, Tag } from 'lucide-vue-next'
import { api, type Agent, type Task } from '@/api'
import { toast } from 'vue-sonner'
import { useSiteSettings } from '@/composables/useSiteSettings'
import { useRouter, useRoute } from 'vue-router'
@@ -28,6 +28,7 @@ const showDeleteDialog = ref(false)
const deleteTaskId = ref<number | null>(null)
const filterName = ref('')
const filterTags = ref('')
const filterAgentId = ref<number | null>(null)
const currentPage = ref(1)
const total = ref(0)
@@ -67,6 +68,7 @@ async function loadTasks() {
page: currentPage.value,
page_size: pageSize.value,
name: filterName.value || undefined,
tags: filterTags.value || undefined,
agent_id: filterAgentId.value || undefined
})
tasks.value = res.data
@@ -122,6 +124,21 @@ function openEdit(task: Task) {
}
}
function duplicateTask(task: Task) {
const newTask = { ...task }
delete (newTask as any).id
delete (newTask as any).last_run
delete (newTask as any).next_run
newTask.name = newTask.name + ' - 副本'
editingTask.value = newTask
isEdit.value = false
if (task.type === TASK_TYPE.REPO) {
showRepoDialog.value = true
} else {
showTaskDialog.value = true
}
}
function confirmDelete(id: number) {
deleteTaskId.value = id
showDeleteDialog.value = true
@@ -203,7 +220,12 @@ watch(() => route.query.agent_id, (newVal) => {
<div class="flex items-center gap-2">
<div class="relative flex-1 sm:flex-none">
<Search class="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
<Input v-model="filterName" placeholder="搜索任务..." class="h-9 pl-9 w-full sm:w-56 text-sm"
<Input v-model="filterName" placeholder="搜索任务..." class="h-9 pl-9 w-full sm:w-40 text-sm"
@input="handleSearch" />
</div>
<div class="relative flex-1 sm:flex-none">
<Tag class="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
<Input v-model="filterTags" placeholder="搜索标签..." class="h-9 pl-9 w-full sm:w-32 text-sm"
@input="handleSearch" />
</div>
<div v-if="filterAgentId"
@@ -224,32 +246,40 @@ watch(() => route.query.agent_id, (newVal) => {
<div class="rounded-lg border bg-card overflow-x-auto">
<!-- 表头 -->
<div
class="flex items-center gap-2 sm:gap-4 px-3 sm:px-4 py-2 border-b bg-muted/20 text-xs sm:text-sm text-muted-foreground font-medium min-w-[360px] sm:min-w-[800px]">
<span class="w-12 sm:w-14 shrink-0">ID</span>
<span class="w-6 sm:w-8 shrink-0 text-center">类型</span>
<span class="flex-1 min-w-0">名称</span>
<span class="w-20 shrink-0 hidden md:block">执行位置</span>
<span class="w-32 sm:flex-1 shrink-0 sm:shrink hidden sm:block">命令/地址</span>
<span class="w-36 shrink-0 hidden md:block">定时规则</span>
<span class="w-40 shrink-0 hidden lg:block">上次执行</span>
<span class="w-40 shrink-0 hidden lg:block">下次执行</span>
<span class="w-8 sm:w-12 shrink-0 text-center">状态</span>
<span class="w-20 sm:w-36 shrink-0">操作</span>
class="flex flex-wrap sm:flex-nowrap items-center gap-x-2 gap-y-2 sm:gap-4 px-3 sm:px-4 py-2 border-b bg-muted/20 text-xs sm:text-sm text-muted-foreground font-medium min-w-0 sm:min-w-[1000px]">
<span class="w-10 sm:w-12 shrink-0 max-sm:order-1">ID</span>
<span class="w-8 shrink-0 text-center max-sm:order-2">类型</span>
<span class="flex-1 min-w-0 sm:flex-none sm:w-40 md:w-48 lg:w-56 shrink-0 max-sm:order-3">名称</span>
<span class="w-24 sm:w-32 shrink-0 hidden md:block">执行位置</span>
<span class="flex-1 min-w-[120px] max-sm:order-6 block sm:block max-sm:mt-1">命令/地址</span>
<span class="w-24 shrink-0 hidden md:block">定时规则</span>
<span class="w-32 shrink-0 hidden lg:block">执行时间</span>
<span class="w-8 shrink-0 text-center max-sm:order-4 max-sm:ml-auto">状态</span>
<span class="w-28 sm:w-32 shrink-0 text-right sm:text-center max-sm:order-7 max-sm:mt-1">操作</span>
<div class="w-full hidden max-sm:block max-sm:order-5"></div>
</div>
<!-- 列表 -->
<div class="divide-y min-w-[360px] sm:min-w-[800px]">
<div class="divide-y min-w-0 sm:min-w-[1000px]">
<div v-if="tasks.length === 0" class="text-sm text-muted-foreground text-center py-8">
暂无任务
</div>
<div v-for="task in tasks" :key="task.id"
class="flex items-center gap-2 sm:gap-4 px-3 sm:px-4 py-2 hover:bg-muted/30 transition-colors">
<span class="w-12 sm:w-14 shrink-0 text-muted-foreground text-xs sm:text-sm">#{{ task.id }}</span>
<span class="w-6 sm:w-8 shrink-0 flex justify-center" :title="getTaskTypeTitle(task.type || 'task')">
class="flex flex-wrap sm:flex-nowrap items-center gap-x-2 gap-y-2 sm:gap-4 px-3 sm:px-4 py-2 hover:bg-muted/30 transition-colors">
<span class="w-10 sm:w-12 shrink-0 text-muted-foreground text-xs sm:text-sm max-sm:order-1">#{{ task.id }}</span>
<span class="w-8 shrink-0 flex justify-center max-sm:order-2" :title="getTaskTypeTitle(task.type || 'task')">
<GitBranch v-if="task.type === TASK_TYPE.REPO" class="h-3.5 w-3.5 sm:h-4 sm:w-4 text-primary" />
<Terminal v-else class="h-3.5 w-3.5 sm:h-4 sm:w-4 text-primary" />
</span>
<span class="flex-1 min-w-0 font-medium truncate text-xs sm:text-sm">{{ task.name }}</span>
<span class="w-20 shrink-0 hidden md:flex items-center gap-1 text-xs" :title="getExecutorName(task)">
<div class="flex-1 min-w-0 sm:flex-none sm:w-40 md:w-48 lg:w-56 shrink-0 flex flex-col justify-center gap-0.5 overflow-hidden max-sm:order-3">
<span class="font-medium truncate text-xs sm:text-sm cursor-help block w-full" :title="task.name">{{ task.name }}</span>
<div v-if="task.tags" class="flex items-center gap-1 overflow-hidden" :title="task.tags">
<span v-for="tag in task.tags.split(',').filter(Boolean).slice(0, 3)" :key="tag" class="truncate text-[10px] leading-none px-1 py-0.5 bg-secondary text-secondary-foreground rounded border">
{{ tag }}
</span>
<span v-if="task.tags.split(',').filter(Boolean).length > 3" class="text-[10px] text-muted-foreground">...</span>
</div>
</div>
<span class="w-24 sm:w-32 shrink-0 hidden md:flex items-center gap-1 text-xs" :title="getExecutorName(task)">
<Monitor v-if="!task.agent_id" class="h-3 w-3 text-muted-foreground" />
<template v-else>
<Wifi v-if="getExecutorStatus(task) === 'online'" class="h-3 w-3 text-green-500" />
@@ -257,17 +287,24 @@ watch(() => route.query.agent_id, (newVal) => {
</template>
<span class="truncate">{{ getExecutorName(task) }}</span>
</span>
<code
class="w-32 sm:flex-1 shrink-0 sm:shrink text-muted-foreground truncate text-xs bg-muted/40 px-2 py-1 rounded hidden sm:block">
<TextOverflow :text="task.command" :title="task.type === TASK_TYPE.REPO ? '同步地址' : '执行命令'" />
class="flex-1 min-w-[120px] text-muted-foreground truncate text-xs bg-muted/40 px-2 py-1 rounded block sm:block max-sm:order-6 overflow-hidden max-sm:mt-1">
<TextOverflow :text="task.command" :title="task.type === TASK_TYPE.REPO ? '同步地址' : '执行命令'" class="truncate" />
</code>
<div class="w-36 shrink-0 hidden md:flex flex-col items-start justify-center gap-1 overflow-hidden">
<div class="w-24 shrink-0 hidden md:flex flex-col items-start justify-center gap-1 overflow-hidden">
<span v-if="task.trigger_type === TRIGGER_TYPE.BAIHU_STARTUP" class="text-[10px] leading-none bg-primary/10 text-primary px-1.5 py-1 rounded whitespace-nowrap border border-primary/20">服务启动时</span>
<code v-else-if="task.schedule" class="text-muted-foreground text-xs bg-muted/40 px-1.5 py-0.5 rounded truncate max-w-full" :title="task.schedule">{{ task.schedule }}</code>
</div>
<span class="w-40 shrink-0 text-muted-foreground text-xs hidden lg:block">{{ task.last_run || '-' }}</span>
<span class="w-40 shrink-0 text-muted-foreground text-xs hidden lg:block">{{ task.next_run || '-' }}</span>
<span class="w-8 sm:w-12 flex justify-center shrink-0 cursor-pointer group"
<div class="w-32 shrink-0 hidden lg:flex flex-col justify-center gap-0.5">
<span class="text-[11px] text-muted-foreground truncate" :title="'上次执行: ' + (task.last_run || '-')">
: {{ task.last_run || '-' }}
</span>
<span class="text-[11px] text-muted-foreground truncate" :title="'下次执行: ' + (task.next_run || '-')">
: {{ task.next_run || '-' }}
</span>
</div>
<span class="w-8 flex justify-center shrink-0 cursor-pointer group max-sm:order-4 max-sm:ml-auto"
@click="toggleTask(task, !task.enabled)" :title="task.enabled ? '点击禁用' : '点击启用'">
<div v-if="task.enabled"
class="h-6 w-6 rounded-md bg-green-500/10 flex items-center justify-center group-hover:bg-green-500/20 transition-colors">
@@ -278,7 +315,7 @@ watch(() => route.query.agent_id, (newVal) => {
<ZapOff class="h-3.5 w-3.5 text-muted-foreground" />
</div>
</span>
<span class="w-20 sm:w-36 shrink-0 flex justify-center gap-0.5 sm:gap-1">
<span class="w-28 sm:w-32 shrink-0 flex justify-end sm:justify-center gap-0.5 sm:gap-1 max-sm:order-7 max-sm:mt-1">
<Button variant="ghost" size="icon" class="h-6 w-6 sm:h-7 sm:w-7" @click="runTask(task.id)" title="执行"
:disabled="executingTaskId === task.id">
<Loader2 v-if="executingTaskId === task.id" class="h-3 w-3 sm:h-3.5 sm:w-3.5 animate-spin" />
@@ -290,11 +327,15 @@ watch(() => route.query.agent_id, (newVal) => {
<Button variant="ghost" size="icon" class="h-6 w-6 sm:h-7 sm:w-7" @click="openEdit(task)" title="编辑">
<Pencil class="h-3 w-3 sm:h-3.5 sm:w-3.5" />
</Button>
<Button variant="ghost" size="icon" class="h-6 w-6 sm:h-7 sm:w-7" @click="duplicateTask(task)" title="克隆">
<Copy class="h-3 w-3 sm:h-3.5 sm:w-3.5" />
</Button>
<Button variant="ghost" size="icon" class="h-6 w-6 sm:h-7 sm:w-7 text-destructive"
@click="confirmDelete(task.id)" title="删除">
<Trash2 class="h-3 w-3 sm:h-3.5 sm:w-3.5" />
</Button>
</span>
<div class="w-full hidden max-sm:block max-sm:order-5"></div>
</div>
</div>
<!-- 分页 -->