fix(center): 数据看板与概览补齐「已取消」运行统计

- 壳子上报 start + 终态(done/error/cancelled),统计只认 start 作总数、done 作成功、error 作失败,cancelled 三类都不进,导致 成功+失败 ≠ 总数

- /api/admin/stats:新增 runs.cancelled / runs.triggered,total 改为终态记录数,failed 纳入 running(未收尾中断),trend 与 topPlugins 补 cancelled;成功+失败+取消严格等于总数

- 数据看板:hero 加取消徽标与口径说明,运行构成环图三段,趋势加取消线,插件排行显示取消数;概览运行卡片扩为 5 张(含已取消)

- 成功率口径不变:success/(success+failed),取消不进分母
This commit is contained in:
2026-11-06 15:40:48 +08:00
parent 2db8e5747f
commit 7849b22058
3 changed files with 87 additions and 30 deletions
@@ -38,7 +38,8 @@ const trendData = computed(() => {
return [
{ name: '触发', data: trend.map((t: any) => t.runs), showAreaColor: true },
{ name: '成功', data: trend.map((t: any) => t.success) },
{ name: '失败', data: trend.map((t: any) => t.failed) }
{ name: '失败', data: trend.map((t: any) => t.failed) },
{ name: '取消', data: trend.map((t: any) => t.cancelled) }
]
})
@@ -101,24 +102,25 @@ onMounted(load)
</el-col>
</el-row>
<!-- 运行统计 -->
<el-row :gutter="14" class="mb-3.5">
<el-col :xs="12" :sm="12" :md="6" v-for="(c, i) in [
{ title: '运行总次数', count: stats.runs?.total || 0, icon: 'ri:play-circle-line', iconStyle: 'bg-[#377dff]', desc: '全部触发' },
{ title: '成功', count: stats.runs?.success || 0, icon: 'ri:checkbox-circle-line', iconStyle: 'bg-[#00b42a]', desc: 'done / success' },
{ title: '失败', count: stats.runs?.failed || 0, icon: 'ri:close-circle-line', iconStyle: 'bg-[#f53f3f]', desc: 'error / failed' },
{ title: '活跃用户', count: stats.runs?.activeUsers || 0, icon: 'ri:user-heart-line', iconStyle: 'bg-[#ff7d00]', desc: '有触发记录' }
]" :key="i">
<ArtStatsCard
:title="c.title"
:count="c.count"
:icon="c.icon"
:icon-style="c.iconStyle"
:description="c.desc"
class="rounded-xl mb-3.5"
/>
</el-col>
</el-row>
<!-- 运行统计(总次数 = 成功 + 失败 + 取消,口径已闭合) -->
<div class="mb-3.5 grid grid-cols-2 gap-3.5 md:grid-cols-3 xl:grid-cols-5">
<ArtStatsCard
v-for="(c, i) in [
{ title: '运行总次数', count: stats.runs?.total || 0, icon: 'ri:play-circle-line', iconStyle: 'bg-[#377dff]', desc: '成功+失败+取消' },
{ title: '成功', count: stats.runs?.success || 0, icon: 'ri:checkbox-circle-line', iconStyle: 'bg-[#00b42a]', desc: 'done / success' },
{ title: '失败', count: stats.runs?.failed || 0, icon: 'ri:close-circle-line', iconStyle: 'bg-[#f53f3f]', desc: 'error / failed' },
{ title: '已取消', count: stats.runs?.cancelled || 0, icon: 'ri:stop-circle-line', iconStyle: 'bg-[#8a8f99]', desc: 'cancelled(用户停止/排队取消)' },
{ title: '活跃用户', count: stats.runs?.activeUsers || 0, icon: 'ri:user-heart-line', iconStyle: 'bg-[#ff7d00]', desc: '有触发记录' }
]"
:key="i"
:title="c.title"
:count="c.count"
:icon="c.icon"
:icon-style="c.iconStyle"
:description="c.desc"
class="rounded-xl"
/>
</div>
<!-- 图表区 -->
<el-row :gutter="14" class="mb-3.5">
@@ -16,14 +16,20 @@
return [
{ name: '触发', data: trend.map((t: any) => t.runs), showAreaColor: true },
{ name: '成功', data: trend.map((t: any) => t.success) },
{ name: '失败', data: trend.map((t: any) => t.failed) }
{ name: '失败', data: trend.map((t: any) => t.failed) },
{ name: '取消', data: trend.map((t: any) => t.cancelled) }
]
})
const trendX = computed(() => (data.value.trend || []).map((t: any) => t.day))
/** 运行总次数 = 终态记录数(成功+失败+取消),三者相加严格等于它 */
const totalRuns = computed(() => data.value.runs?.total || 0)
const triggeredRuns = computed(() => data.value.runs?.triggered || 0)
const successCount = computed(() => data.value.runs?.success || 0)
const failedCount = computed(() => data.value.runs?.failed || 0)
/** 用户取消(强制停止 / 排队取消 / 排队超时 / 客户端退出)不算失败 */
const cancelledCount = computed(() => data.value.runs?.cancelled || 0)
/** 成功率分母:只算成功+失败,取消不进分母(壳子上报口径) */
const finishedCount = computed(() => successCount.value + failedCount.value)
const successRate = computed(() => {
@@ -38,7 +44,8 @@
const ringData = computed(() => [
{ name: '成功', value: successCount.value },
{ name: '失败', value: failedCount.value }
{ name: '失败', value: failedCount.value },
{ name: '取消', value: cancelledCount.value }
])
const avgDuration = computed(() => {
@@ -156,10 +163,16 @@
<span class="hero-chip">
<i class="dot bg-[#ffb3b3]"></i>失败 {{ fmtNum(failedCount) }}
</span>
<span class="hero-chip">
<i class="dot bg-[#ffd591]"></i>取消 {{ fmtNum(cancelledCount) }}
</span>
<span class="hero-chip">
<i class="dot bg-white/60"></i>平均耗时 {{ avgDuration }}
</span>
</div>
<div class="mt-2 text-[11px] text-white/60">
总次数 = 成功 + 失败 + 取消;触发上报 {{ fmtNum(triggeredRuns) }} 次(含排队取消、仍在运行)
</div>
</div>
<div class="shrink-0">
@@ -213,7 +226,7 @@
<div>
<span class="font-semibold">近 14 天运行趋势</span>
<span class="ml-2 text-xs text-g-400"
>触发 = start · 成功 = done/success · 失败 = error/failed</span
>触发 = start · 成功 = done/success · 失败 = error/failed · 取消 = cancelled</span
>
</div>
<span class="text-xs text-g-400">近 14 天</span>
@@ -236,7 +249,7 @@
<div class="relative">
<ArtRingChart
:data="ringData"
:colors="['#00b42a', '#f53f3f']"
:colors="['#00b42a', '#f53f3f', '#8a8f99']"
:radius="['56%', '80%']"
:border-radius="8"
height="180px"
@@ -254,7 +267,7 @@
<span class="font-medium text-g-900">
{{ fmtNum(successCount) }}
<span class="ml-1 text-xs font-normal text-g-400">
{{ finishedCount ? Math.round((successCount / finishedCount) * 100) : 0 }}%
{{ totalRuns ? Math.round((successCount / totalRuns) * 100) : 0 }}%
</span>
</span>
</div>
@@ -263,7 +276,16 @@
<span class="font-medium text-g-900">
{{ fmtNum(failedCount) }}
<span class="ml-1 text-xs font-normal text-g-400">
{{ finishedCount ? Math.round((failedCount / finishedCount) * 100) : 0 }}%
{{ totalRuns ? Math.round((failedCount / totalRuns) * 100) : 0 }}%
</span>
</span>
</div>
<div class="flex-cb text-sm">
<span class="flex-c gap-2 text-g-500"> <i class="dot bg-[#8a8f99]"></i>取消 </span>
<span class="font-medium text-g-900">
{{ fmtNum(cancelledCount) }}
<span class="ml-1 text-xs font-normal text-g-400">
{{ totalRuns ? Math.round((cancelledCount / totalRuns) * 100) : 0 }}%
</span>
</span>
</div>
@@ -312,6 +334,10 @@
<b :class="p.failed ? 'text-[var(--el-color-danger)]' : 'text-g-400'">
{{ fmtNum(p.failed) }}
</b>
· 取消
<b :class="p.cancelled ? 'text-[#8a8f99]' : 'text-g-400'">
{{ fmtNum(p.cancelled) }}
</b>
</span>
</div>
<div class="mt-1.5 h-1.5 overflow-hidden rounded-full bg-[var(--el-fill-color)]">