This commit is contained in:
张成
2025-11-26 15:35:18 +08:00
parent ad1465f2a1
commit c8b60c3349
2 changed files with 79 additions and 26 deletions

View File

@@ -59,15 +59,44 @@
<Card v-if="runningTasks.length > 0" style="margin-bottom: 16px;"> <Card v-if="runningTasks.length > 0" style="margin-bottom: 16px;">
<p slot="title">当前执行中的任务</p> <p slot="title">当前执行中的任务</p>
<Table :columns="taskColumns" :data="runningTasks" :loading="taskLoading"> <Table :columns="taskColumns" :data="runningTasks" :loading="taskLoading">
<template slot-scope="{ row }" slot="progress">
<Progress
:percent="Number(row.progress) || 0"
:status="row.progress === 100 ? 'success' : 'active'"
style="width: 80px;"
/>
</template>
<template slot-scope="{ row }" slot="commands"> <template slot-scope="{ row }" slot="commands">
<div style="display: flex; flex-wrap: wrap; align-items: center;">
<Tag <Tag
v-for="(cmd, index) in row.commands" v-for="(cmd, index) in getDisplayCommands(row.commands)"
:key="index" :key="index"
:color="getCommandColor(cmd.status)" :color="getCommandColor(cmd.status)"
style="margin: 2px;" style="margin: 2px;"
> >
{{ cmd.commandName }} {{ cmd.commandName }}
</Tag> </Tag>
<Poptip
v-if="row.commands && row.commands.length > 3"
trigger="hover"
placement="top"
width="300"
>
<Tag color="default" style="margin: 2px; cursor: pointer;">
更多({{ row.commands.length - 3 }})
</Tag>
<div slot="content" style="max-height: 300px; overflow-y: auto;">
<Tag
v-for="(cmd, index) in row.commands"
:key="index"
:color="getCommandColor(cmd.status)"
style="margin: 4px; display: block;"
>
{{ cmd.commandName }}
</Tag>
</div>
</Poptip>
</div>
</template> </template>
</Table> </Table>
</Card> </Card>
@@ -125,21 +154,14 @@ export default {
}, },
{ {
title: '进度', title: '进度',
key: 'progress', slot: 'progress',
width: 100, width: 120,
render: (h, params) => { align: 'center'
return h('Progress', {
props: {
percent: params.row.progress || 0,
status: 'active'
}
})
}
}, },
{ {
title: '命令列表', title: '命令列表',
slot: 'commands', slot: 'commands',
minWidth: 300 minWidth: 200
} }
], ],
refreshTimer: null refreshTimer: null
@@ -326,7 +348,13 @@ export default {
console.log('执行中任务接口返回:', res) console.log('执行中任务接口返回:', res)
if (res.code === 0) { if (res.code === 0) {
this.runningTasks = res.data || [] // 处理数据并计算进度
this.runningTasks = (res.data || []).map(task => {
return {
...task,
progress: this.calculateProgress(task.commands || [])
}
})
} else { } else {
console.warn('加载执行中任务失败:', res.msg || res.message) console.warn('加载执行中任务失败:', res.msg || res.message)
this.runningTasks = [] this.runningTasks = []
@@ -492,6 +520,31 @@ export default {
'skipped': 'warning' 'skipped': 'warning'
} }
return colorMap[status] || 'default' 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
} }
} }
} }

View File

@@ -217,17 +217,17 @@ module.exports = {
const applyCount = allApplies.filter(item => { const applyCount = allApplies.filter(item => {
const itemDate = dayjs(item.applyTime); const itemDate = dayjs(item.applyTime);
return itemDate.isSameOrAfter(dayStart) && itemDate.isSameOrBefore(dayEnd); return !itemDate.isBefore(dayStart, 'day') && !itemDate.isAfter(dayEnd, 'day');
}).length; }).length;
const jobCount = allJobs.filter(item => { const jobCount = allJobs.filter(item => {
const itemDate = dayjs(item.create_time); const itemDate = dayjs(item.create_time);
return itemDate.isSameOrAfter(dayStart) && itemDate.isSameOrBefore(dayEnd); return !itemDate.isBefore(dayStart, 'day') && !itemDate.isAfter(dayEnd, 'day');
}).length; }).length;
const chatCount = allChats.filter(item => { const chatCount = allChats.filter(item => {
const itemDate = dayjs(item.sendTime); const itemDate = dayjs(item.sendTime);
return itemDate.isSameOrAfter(dayStart) && itemDate.isSameOrBefore(dayEnd); return !itemDate.isBefore(dayStart, 'day') && !itemDate.isAfter(dayEnd, 'day');
}).length; }).length;
dates.push(dateStr); dates.push(dateStr);
@@ -375,7 +375,7 @@ module.exports = {
const count = allApplies.filter(item => { const count = allApplies.filter(item => {
const itemDate = dayjs(item.applyTime); const itemDate = dayjs(item.applyTime);
return itemDate.isSameOrAfter(dayStart) && itemDate.isSameOrBefore(dayEnd); return !itemDate.isBefore(dayStart, 'day') && !itemDate.isAfter(dayEnd, 'day');
}).length; }).length;
dates.push(dateStr); dates.push(dateStr);
@@ -449,7 +449,7 @@ module.exports = {
const count = allJobs.filter(item => { const count = allJobs.filter(item => {
const itemDate = dayjs(item.create_time); const itemDate = dayjs(item.create_time);
return itemDate.isSameOrAfter(dayStart) && itemDate.isSameOrBefore(dayEnd); return !itemDate.isBefore(dayStart, 'day') && !itemDate.isAfter(dayEnd, 'day');
}).length; }).length;
dates.push(dateStr); dates.push(dateStr);
@@ -524,7 +524,7 @@ module.exports = {
const count = allChats.filter(item => { const count = allChats.filter(item => {
const itemDate = dayjs(item.sendTime); const itemDate = dayjs(item.sendTime);
return itemDate.isSameOrAfter(dayStart) && itemDate.isSameOrBefore(dayEnd); return !itemDate.isBefore(dayStart, 'day') && !itemDate.isAfter(dayEnd, 'day');
}).length; }).length;
dates.push(dateStr); dates.push(dateStr);