From c8b60c334982be02daa637f6be3f1f5f6aa7c97c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=88=90?= Date: Wed, 26 Nov 2025 15:35:18 +0800 Subject: [PATCH] 1 --- admin/src/views/home/index.vue | 93 +++++++++++++++++++++++------- api/controller_admin/statistics.js | 12 ++-- 2 files changed, 79 insertions(+), 26 deletions(-) diff --git a/admin/src/views/home/index.vue b/admin/src/views/home/index.vue index f9496d6..7ab1a1b 100644 --- a/admin/src/views/home/index.vue +++ b/admin/src/views/home/index.vue @@ -59,15 +59,44 @@

当前执行中的任务

+
@@ -125,21 +154,14 @@ export default { }, { title: '进度', - key: 'progress', - width: 100, - render: (h, params) => { - return h('Progress', { - props: { - percent: params.row.progress || 0, - status: 'active' - } - }) - } + slot: 'progress', + width: 120, + align: 'center' }, { title: '命令列表', slot: 'commands', - minWidth: 300 + minWidth: 200 } ], refreshTimer: null @@ -326,7 +348,13 @@ export default { console.log('执行中任务接口返回:', res) if (res.code === 0) { - this.runningTasks = res.data || [] + // 处理数据并计算进度 + this.runningTasks = (res.data || []).map(task => { + return { + ...task, + progress: this.calculateProgress(task.commands || []) + } + }) } else { console.warn('加载执行中任务失败:', res.msg || res.message) this.runningTasks = [] @@ -492,6 +520,31 @@ export default { 'skipped': 'warning' } return colorMap[status] || 'default' + }, + + // 获取要显示的命令列表(最多显示3个) + getDisplayCommands(commands) { + if (!commands || !Array.isArray(commands)) { + return [] + } + return commands.slice(0, 3) + }, + + // 根据命令状态计算进度 + calculateProgress(commands) { + if (!commands || !Array.isArray(commands) || commands.length === 0) { + return 0 + } + + // 统计已完成和已失败的命令数(这些状态表示命令已执行完成) + const completedCount = commands.filter(cmd => { + const status = cmd.status || '' + return status === 'completed' || status === 'failed' || status === 'skipped' + }).length + + // 计算进度百分比 + const progress = Math.round((completedCount / commands.length) * 100) + return progress } } } diff --git a/api/controller_admin/statistics.js b/api/controller_admin/statistics.js index f1f9763..de785e5 100644 --- a/api/controller_admin/statistics.js +++ b/api/controller_admin/statistics.js @@ -217,17 +217,17 @@ module.exports = { const applyCount = allApplies.filter(item => { const itemDate = dayjs(item.applyTime); - return itemDate.isSameOrAfter(dayStart) && itemDate.isSameOrBefore(dayEnd); + return !itemDate.isBefore(dayStart, 'day') && !itemDate.isAfter(dayEnd, 'day'); }).length; const jobCount = allJobs.filter(item => { const itemDate = dayjs(item.create_time); - return itemDate.isSameOrAfter(dayStart) && itemDate.isSameOrBefore(dayEnd); + return !itemDate.isBefore(dayStart, 'day') && !itemDate.isAfter(dayEnd, 'day'); }).length; const chatCount = allChats.filter(item => { const itemDate = dayjs(item.sendTime); - return itemDate.isSameOrAfter(dayStart) && itemDate.isSameOrBefore(dayEnd); + return !itemDate.isBefore(dayStart, 'day') && !itemDate.isAfter(dayEnd, 'day'); }).length; dates.push(dateStr); @@ -375,7 +375,7 @@ module.exports = { const count = allApplies.filter(item => { const itemDate = dayjs(item.applyTime); - return itemDate.isSameOrAfter(dayStart) && itemDate.isSameOrBefore(dayEnd); + return !itemDate.isBefore(dayStart, 'day') && !itemDate.isAfter(dayEnd, 'day'); }).length; dates.push(dateStr); @@ -449,7 +449,7 @@ module.exports = { const count = allJobs.filter(item => { const itemDate = dayjs(item.create_time); - return itemDate.isSameOrAfter(dayStart) && itemDate.isSameOrBefore(dayEnd); + return !itemDate.isBefore(dayStart, 'day') && !itemDate.isAfter(dayEnd, 'day'); }).length; dates.push(dateStr); @@ -524,7 +524,7 @@ module.exports = { const count = allChats.filter(item => { const itemDate = dayjs(item.sendTime); - return itemDate.isSameOrAfter(dayStart) && itemDate.isSameOrBefore(dayEnd); + return !itemDate.isBefore(dayStart, 'day') && !itemDate.isAfter(dayEnd, 'day'); }).length; dates.push(dateStr);