fix: task list icon display
This commit is contained in:
@@ -20,6 +20,7 @@ type TaskLogResponse struct {
|
|||||||
ID uint `json:"id"`
|
ID uint `json:"id"`
|
||||||
TaskID uint `json:"task_id"`
|
TaskID uint `json:"task_id"`
|
||||||
TaskName string `json:"task_name"`
|
TaskName string `json:"task_name"`
|
||||||
|
TaskType string `json:"task_type"`
|
||||||
Command string `json:"command"`
|
Command string `json:"command"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Duration int64 `json:"duration"`
|
Duration int64 `json:"duration"`
|
||||||
@@ -61,17 +62,23 @@ func (lc *LogController) GetLogs(c *gin.Context) {
|
|||||||
|
|
||||||
var tasks []models.Task
|
var tasks []models.Task
|
||||||
database.DB.Where("id IN ?", taskIDList).Find(&tasks)
|
database.DB.Where("id IN ?", taskIDList).Find(&tasks)
|
||||||
taskMap := make(map[uint]string)
|
taskMap := make(map[uint]models.Task)
|
||||||
for _, t := range tasks {
|
for _, t := range tasks {
|
||||||
taskMap[t.ID] = t.Name
|
taskMap[t.ID] = t
|
||||||
}
|
}
|
||||||
|
|
||||||
result := make([]TaskLogResponse, len(logs))
|
result := make([]TaskLogResponse, len(logs))
|
||||||
for i, log := range logs {
|
for i, log := range logs {
|
||||||
|
task := taskMap[log.TaskID]
|
||||||
|
taskType := task.Type
|
||||||
|
if taskType == "" {
|
||||||
|
taskType = "task"
|
||||||
|
}
|
||||||
result[i] = TaskLogResponse{
|
result[i] = TaskLogResponse{
|
||||||
ID: log.ID,
|
ID: log.ID,
|
||||||
TaskID: log.TaskID,
|
TaskID: log.TaskID,
|
||||||
TaskName: taskMap[log.TaskID],
|
TaskName: task.Name,
|
||||||
|
TaskType: taskType,
|
||||||
Command: log.Command,
|
Command: log.Command,
|
||||||
Status: log.Status,
|
Status: log.Status,
|
||||||
Duration: log.Duration,
|
Duration: log.Duration,
|
||||||
|
|||||||
@@ -285,6 +285,7 @@ export interface TaskLog {
|
|||||||
id: number
|
id: number
|
||||||
task_id: number
|
task_id: number
|
||||||
task_name: string
|
task_name: string
|
||||||
|
task_type: string
|
||||||
command: string
|
command: string
|
||||||
status: string
|
status: string
|
||||||
duration: number
|
duration: number
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { Button } from '@/components/ui/button'
|
|||||||
import { Input } from '@/components/ui/input'
|
import { Input } from '@/components/ui/input'
|
||||||
import Pagination from '@/components/Pagination.vue'
|
import Pagination from '@/components/Pagination.vue'
|
||||||
import LogViewer from './LogViewer.vue'
|
import LogViewer from './LogViewer.vue'
|
||||||
import { RefreshCw, X, Search, Maximize2 } from 'lucide-vue-next'
|
import { RefreshCw, X, Search, Maximize2, GitBranch, Terminal } from 'lucide-vue-next'
|
||||||
import { api, type TaskLog, type LogDetail } from '@/api'
|
import { api, type TaskLog, type LogDetail } from '@/api'
|
||||||
import { toast } from 'vue-sonner'
|
import { toast } from 'vue-sonner'
|
||||||
import pako from 'pako'
|
import pako from 'pako'
|
||||||
@@ -101,6 +101,10 @@ function formatDuration(ms: number): string {
|
|||||||
return `${(ms / 60000).toFixed(1)}m`
|
return `${(ms / 60000).toFixed(1)}m`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getTaskTypeTitle(type: string) {
|
||||||
|
return type === 'repo' ? '仓库同步' : '普通任务'
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
// 从 URL 读取 task_id 参数
|
// 从 URL 读取 task_id 参数
|
||||||
const taskIdParam = route.query.task_id
|
const taskIdParam = route.query.task_id
|
||||||
@@ -142,6 +146,7 @@ watch(() => route.query.task_id, (newTaskId) => {
|
|||||||
<!-- 表头 -->
|
<!-- 表头 -->
|
||||||
<div class="flex items-center gap-4 px-4 py-2 border-b bg-muted/50 text-sm text-muted-foreground font-medium overflow-x-auto">
|
<div class="flex items-center gap-4 px-4 py-2 border-b bg-muted/50 text-sm text-muted-foreground font-medium overflow-x-auto">
|
||||||
<span class="w-12 shrink-0">ID</span>
|
<span class="w-12 shrink-0">ID</span>
|
||||||
|
<span class="w-8 shrink-0 text-center">类型</span>
|
||||||
<span class="w-20 sm:w-28 shrink-0">任务名称</span>
|
<span class="w-20 sm:w-28 shrink-0">任务名称</span>
|
||||||
<span :class="selectedLog ? 'w-40 shrink-0 hidden sm:block' : 'w-32 sm:flex-1 shrink-0 sm:shrink'">命令</span>
|
<span :class="selectedLog ? 'w-40 shrink-0 hidden sm:block' : 'w-32 sm:flex-1 shrink-0 sm:shrink'">命令</span>
|
||||||
<span class="w-12 shrink-0 text-center">状态</span>
|
<span class="w-12 shrink-0 text-center">状态</span>
|
||||||
@@ -163,6 +168,10 @@ watch(() => route.query.task_id, (newTaskId) => {
|
|||||||
@click="selectLog(log)"
|
@click="selectLog(log)"
|
||||||
>
|
>
|
||||||
<span class="w-12 shrink-0 text-muted-foreground text-sm">#{{ log.id }}</span>
|
<span class="w-12 shrink-0 text-muted-foreground text-sm">#{{ log.id }}</span>
|
||||||
|
<span class="w-8 shrink-0 flex justify-center" :title="getTaskTypeTitle(log.task_type || 'task')">
|
||||||
|
<GitBranch v-if="log.task_type === 'repo'" class="h-4 w-4 text-primary" />
|
||||||
|
<Terminal v-else class="h-4 w-4 text-muted-foreground" />
|
||||||
|
</span>
|
||||||
<span class="w-20 sm:w-28 font-medium truncate shrink-0 text-sm">
|
<span class="w-20 sm:w-28 font-medium truncate shrink-0 text-sm">
|
||||||
<TextOverflow :text="log.task_name" title="任务名称" />
|
<TextOverflow :text="log.task_name" title="任务名称" />
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { Badge } from '@/components/ui/badge'
|
|||||||
import { Checkbox } from '@/components/ui/checkbox'
|
import { Checkbox } from '@/components/ui/checkbox'
|
||||||
import Pagination from '@/components/Pagination.vue'
|
import Pagination from '@/components/Pagination.vue'
|
||||||
import DirTreeSelect from '@/components/DirTreeSelect.vue'
|
import DirTreeSelect from '@/components/DirTreeSelect.vue'
|
||||||
import { Plus, Play, Pencil, Trash2, Search, ScrollText, ChevronDown, X, GitBranch } from 'lucide-vue-next'
|
import { Plus, Play, Pencil, Trash2, Search, ScrollText, ChevronDown, X, GitBranch, Terminal } from 'lucide-vue-next'
|
||||||
import { api, type Task, type EnvVar, type RepoConfig } from '@/api'
|
import { api, type Task, type EnvVar, type RepoConfig } from '@/api'
|
||||||
import { toast } from 'vue-sonner'
|
import { toast } from 'vue-sonner'
|
||||||
import { useSiteSettings } from '@/composables/useSiteSettings'
|
import { useSiteSettings } from '@/composables/useSiteSettings'
|
||||||
@@ -267,8 +267,8 @@ function viewLogs(taskId: number) {
|
|||||||
router.push({ path: '/history', query: { task_id: String(taskId) } })
|
router.push({ path: '/history', query: { task_id: String(taskId) } })
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTaskTypeLabel(type: string) {
|
function getTaskTypeTitle(type: string) {
|
||||||
return type === 'repo' ? '仓库' : '普通'
|
return type === 'repo' ? '仓库同步' : '普通任务'
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
@@ -302,7 +302,7 @@ onMounted(() => {
|
|||||||
<!-- 表头 -->
|
<!-- 表头 -->
|
||||||
<div class="flex items-center gap-4 px-4 py-2 border-b bg-muted/50 text-sm text-muted-foreground font-medium min-w-[700px]">
|
<div class="flex items-center gap-4 px-4 py-2 border-b bg-muted/50 text-sm text-muted-foreground font-medium min-w-[700px]">
|
||||||
<span class="w-12 shrink-0">ID</span>
|
<span class="w-12 shrink-0">ID</span>
|
||||||
<span class="w-16 shrink-0">类型</span>
|
<span class="w-8 shrink-0 text-center">类型</span>
|
||||||
<span class="w-20 sm:w-28 shrink-0">名称</span>
|
<span class="w-20 sm:w-28 shrink-0">名称</span>
|
||||||
<span class="w-32 sm:flex-1 shrink-0 sm:shrink">命令/地址</span>
|
<span class="w-32 sm:flex-1 shrink-0 sm:shrink">命令/地址</span>
|
||||||
<span class="w-32 shrink-0 hidden md:block">定时规则</span>
|
<span class="w-32 shrink-0 hidden md:block">定时规则</span>
|
||||||
@@ -322,10 +322,9 @@ onMounted(() => {
|
|||||||
class="flex items-center gap-4 px-4 py-2 hover:bg-muted/50 transition-colors"
|
class="flex items-center gap-4 px-4 py-2 hover:bg-muted/50 transition-colors"
|
||||||
>
|
>
|
||||||
<span class="w-12 shrink-0 text-muted-foreground text-sm">#{{ task.id }}</span>
|
<span class="w-12 shrink-0 text-muted-foreground text-sm">#{{ task.id }}</span>
|
||||||
<span class="w-16 shrink-0">
|
<span class="w-8 shrink-0 flex justify-center" :title="getTaskTypeTitle(task.type || 'task')">
|
||||||
<Badge :variant="task.type === 'repo' ? 'default' : 'secondary'" class="text-xs">
|
<GitBranch v-if="task.type === 'repo'" class="h-4 w-4 text-primary" />
|
||||||
{{ getTaskTypeLabel(task.type || 'task') }}
|
<Terminal v-else class="h-4 w-4 text-muted-foreground" />
|
||||||
</Badge>
|
|
||||||
</span>
|
</span>
|
||||||
<span class="w-20 sm:w-28 font-medium truncate shrink-0 text-sm">
|
<span class="w-20 sm:w-28 font-medium truncate shrink-0 text-sm">
|
||||||
<TextOverflow :text="task.name" title="任务名称" />
|
<TextOverflow :text="task.name" title="任务名称" />
|
||||||
|
|||||||
Reference in New Issue
Block a user