feat(platform): summarize service status on dashboard

This commit is contained in:
lingniu
2026-07-04 01:59:05 +08:00
parent 14408d135d
commit 5d401a8f0b
8 changed files with 132 additions and 10 deletions

View File

@@ -23,9 +23,16 @@ export interface DashboardSummary {
issueVehicles: number;
kafkaLag: number | null;
protocols: ProtocolStat[];
serviceStatuses: ServiceStatusStat[];
linkHealth: LinkHealth[];
}
export interface ServiceStatusStat {
status: string;
title: string;
count: number;
}
export interface VehicleRow {
vin: string;
plate: string;

View File

@@ -1,7 +1,7 @@
import { Button, Card, Col, Form, Row, Select, Space, Spin, Table, Tag, Toast, Typography } from '@douyinfe/semi-ui';
import { useEffect, useState } from 'react';
import { api } from '../api/client';
import type { DashboardSummary, LinkHealth, ProtocolStat, QualityIssueRow, VehicleCoverageRow, VehicleRealtimeRow } from '../api/types';
import type { DashboardSummary, LinkHealth, ProtocolStat, QualityIssueRow, ServiceStatusStat, VehicleCoverageRow, VehicleRealtimeRow } from '../api/types';
import { PageHeader } from '../components/PageHeader';
import { StatusTag } from '../components/StatusTag';
import { qualityIssueVehicleLookup } from '../domain/vehicleLookup';
@@ -12,6 +12,13 @@ const statusColor: Record<string, 'green' | 'orange' | 'red' | 'grey'> = {
error: 'red'
};
const serviceStatusColor: Record<string, 'green' | 'orange' | 'red' | 'grey'> = {
healthy: 'green',
degraded: 'orange',
offline: 'red',
identity_required: 'orange'
};
function formatLag(value?: number | null) {
return value == null ? '未接入' : value.toLocaleString();
}
@@ -74,7 +81,22 @@ export function Dashboard({ onOpenVehicle, onOpenQuality }: { onOpenVehicle: (vi
))}
</div>
<Row gutter={16}>
<Col span={14}>
<Col span={8}>
<Card title="车辆服务状态" bordered>
<Table
pagination={false}
dataSource={summary?.serviceStatuses ?? []}
columns={[
{
title: '状态',
render: (_: unknown, row: ServiceStatusStat) => <Tag color={serviceStatusColor[row.status] ?? 'grey'}>{row.title}</Tag>
},
{ title: '车辆数', dataIndex: 'count' }
]}
/>
</Card>
</Col>
<Col span={8}>
<Card title="数据来源在线分布" bordered>
<Table
pagination={false}
@@ -91,7 +113,7 @@ export function Dashboard({ onOpenVehicle, onOpenQuality }: { onOpenVehicle: (vi
/>
</Card>
</Col>
<Col span={10}>
<Col span={8}>
<Card title="链路健康" bordered>
<Table
pagination={false}

View File

@@ -14,6 +14,49 @@ test('renders vehicle platform shell', () => {
expect(screen.getAllByText('总览工作台').length).toBeGreaterThanOrEqual(1);
});
test('shows vehicle service status distribution on dashboard', async () => {
window.history.replaceState(null, '', '/#/dashboard');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/dashboard/summary')) {
return {
ok: true,
json: async () => ({
data: {
onlineVehicles: 3,
activeToday: 4,
frameToday: 1286320,
issueVehicles: 7,
kafkaLag: 0,
protocols: [],
serviceStatuses: [
{ status: 'healthy', title: '服务正常', count: 12 },
{ status: 'degraded', title: '部分来源离线', count: 39 }
],
linkHealth: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('车辆服务状态')).toBeInTheDocument();
expect(screen.getByText('部分来源离线')).toBeInTheDocument();
expect(screen.getByText('39')).toBeInTheDocument();
});
test('opens vehicle detail from shareable hash', async () => {
window.history.replaceState(null, '', '/#/detail?keyword=%E7%B2%A4AG18312');
vi.spyOn(globalThis, 'fetch').mockResolvedValue({