feat: 展示通知 outbox 状态

- services: 增加 /notification-outbox 真实接口读取与摘要清洗

- store: 超级管理员加载最近通知 outbox

- settings: 增加通知 outbox 运维表格
This commit is contained in:
湛兮
2026-06-12 03:22:38 +08:00
parent 4988c5be38
commit cc72a24c7d
4 changed files with 170 additions and 1 deletions
+93
View File
@@ -9,14 +9,17 @@ import AuditJsonCell from '../components/AuditJsonCell.vue'
import StatusPill from '../components/StatusPill.vue'
import { devopsApi } from '../services/devopsApi'
import { usePlatformStore } from '../stores/platform'
import { useSessionStore } from '../stores/session'
import type {
AgentConfigSummary,
AuditLogEntry,
IntegrationConfigItem,
IntegrationConfigState,
NotificationOutboxMessage,
} from '../types/devops'
const platform = usePlatformStore()
const session = useSessionStore()
const agentConfigLoading = ref(false)
const agentConfigTesting = ref(false)
const agentConfig = ref<AgentConfigSummary | null>(null)
@@ -42,6 +45,15 @@ const configStatusMeta: Record<
partial: { label: '部分配置', type: 'warning' },
missing: { label: '未配置', type: 'danger' },
}
const outboxStatusMeta: Record<
NotificationOutboxMessage['status'],
{ label: string; type: 'success' | 'warning' | 'danger' | 'info' }
> = {
pending: { label: '待投递', type: 'warning' },
sent: { label: '已投递', type: 'success' },
failed: { label: '投递失败', type: 'danger' },
dead: { label: '已终止', type: 'info' },
}
onMounted(() => {
void loadAgentConfig()
@@ -109,6 +121,20 @@ function auditPayload(record: AuditLogEntry): unknown {
return Object.keys(payload).length > 0 ? payload : null
}
function outboxPayload(record: NotificationOutboxMessage): unknown {
return record.payloadSummary ?? null
}
function outboxStatusLabel(status: NotificationOutboxMessage['status']): string {
return outboxStatusMeta[status]?.label ?? '未知'
}
function outboxStatusType(
status: NotificationOutboxMessage['status'],
): 'success' | 'warning' | 'danger' | 'info' {
return outboxStatusMeta[status]?.type ?? 'info'
}
function variableGroups(item: IntegrationConfigItem): VariableGroup[] {
return [
{
@@ -211,6 +237,15 @@ async function testAgentConfig() {
}
}
async function refreshNotificationOutbox() {
try {
await platform.loadNotificationOutbox()
ElMessage.success('通知 outbox 已刷新')
} catch (error) {
ElMessage.error(error instanceof Error ? error.message : '通知 outbox 刷新失败')
}
}
function applyAgentConfig(config: AgentConfigSummary) {
agentConfig.value = config
agentConfigForm.baseURL = config.baseURL
@@ -386,6 +421,58 @@ function applyAgentConfig(config: AgentConfigSummary) {
</div>
</section>
<section v-if="session.role === 'super_admin'" class="panel">
<div class="panel-header">
<h2>通知 outbox</h2>
<ElButton :icon="Refresh" size="small" @click="refreshNotificationOutbox">
刷新
</ElButton>
</div>
<div class="panel-body">
<ElTable :data="platform.notificationOutbox" border>
<ElTableColumn label="创建时间" min-width="150">
<template #default="{ row }">
{{ formatCheckedAt(row.createdAt) }}
</template>
</ElTableColumn>
<ElTableColumn label="状态" min-width="110">
<template #default="{ row }">
<ElTag :type="outboxStatusType(row.status)" effect="light" round>
{{ outboxStatusLabel(row.status) }}
</ElTag>
</template>
</ElTableColumn>
<ElTableColumn prop="channel" label="渠道" min-width="100" />
<ElTableColumn prop="template" label="模板" min-width="130" />
<ElTableColumn label="发布单" min-width="220">
<template #default="{ row }">
<span class="mono">{{ row.deployRunId || '-' }}</span>
</template>
</ElTableColumn>
<ElTableColumn label="尝试" min-width="80">
<template #default="{ row }">
{{ row.attemptCount }}
</template>
</ElTableColumn>
<ElTableColumn label="错误摘要" min-width="240">
<template #default="{ row }">
<span class="outbox-error">{{ row.lastError || '-' }}</span>
</template>
</ElTableColumn>
<ElTableColumn label="脱敏 payload" min-width="360">
<template #default="{ row }">
<AuditJsonCell :value="outboxPayload(row)" />
</template>
</ElTableColumn>
</ElTable>
<ElEmpty
v-if="platform.notificationOutbox.length === 0"
description="暂无通知 outbox 记录"
:image-size="72"
/>
</div>
</section>
<section class="panel">
<div class="panel-header">
<h2>最近运维审计</h2>
@@ -609,6 +696,12 @@ function applyAgentConfig(config: AgentConfigSummary) {
line-height: 24px;
}
.outbox-error {
color: #b42318;
font-size: 12px;
line-height: 1.5;
}
@media (max-width: 1080px) {
.variable-grid {
grid-template-columns: repeat(2, minmax(0, 1fr));