feat(platform): copy priority alert notification

This commit is contained in:
lingniu
2026-07-04 15:06:02 +08:00
parent 21294e8b79
commit c96144e92a
2 changed files with 163 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ import { SourceStatusTags } from '../components/SourceStatusTags';
import { StatusTag } from '../components/StatusTag';
import { VehicleMap, type VehicleMapPoint } from '../components/VehicleMap';
import { isAMapConfigured } from '../config/appConfig';
import { buildAppHash } from '../domain/appRoute';
import { qualityIssueLabel, qualityProtocolLabel } from '../domain/qualityIssue';
import { qualityIssueVehicleLookup } from '../domain/vehicleLookup';
@@ -114,6 +115,39 @@ function priorityIssueEvidenceFilters(row: QualityIssueRow) {
};
}
function appURL(hash: string) {
return `${window.location.origin}${window.location.pathname}${hash}`;
}
async function copyText(value: string, label: string) {
try {
await navigator.clipboard.writeText(value);
Toast.success(`已复制${label}`);
} catch {
Toast.error(`复制${label}失败`);
}
}
function priorityIssueNotificationText(row: QualityIssueRow) {
const lookup = qualityIssueVehicleLookup(row);
const filters = priorityIssueEvidenceFilters(row);
const rawFilters = { ...filters, tab: 'raw', includeFields: 'true' };
const priority = row.severity === 'error' ? 'P0' : 'P1';
return [
`${priority} 告警通知】${qualityIssueLabel(row.issueType)}`,
`车辆:${priorityIssueVehicleLabel(row)}`,
`数据来源:${qualityProtocolLabel(row.protocol)}`,
`问题:${qualityIssueLabel(row.issueType)}`,
`最后时间:${row.lastSeen || '-'}`,
`详情:${row.detail || '-'}`,
`实时定位:${appURL(buildAppHash({ page: 'realtime', keyword: lookup.key, protocol: row.protocol }))}`,
`轨迹证据:${appURL(buildAppHash({ page: 'history', keyword: filters.keyword, protocol: filters.protocol, filters }))}`,
`RAW证据${appURL(buildAppHash({ page: 'history', keyword: rawFilters.keyword, protocol: rawFilters.protocol, filters: rawFilters }))}`,
`车辆服务:${appURL(buildAppHash({ page: 'detail', keyword: lookup.key, protocol: row.protocol }))}`,
`告警筛选:${appURL(buildAppHash({ page: 'quality', protocol: row.protocol, filters: { issueType: row.issueType } }))}`
].join('\n');
}
function sourceConsistencyAction(row: VehicleCoverageRow, onFilter: (filters: Record<string, string>) => void) {
const consistency = row.sourceConsistency;
if (!consistency) {
@@ -463,6 +497,14 @@ export function Dashboard({
>
RAW证据
</Button>
<Button
size="small"
theme="light"
aria-label="首页复制告警通知"
onClick={() => copyText(priorityIssueNotificationText(highPriorityIssue), '告警通知')}
>
</Button>
<Button size="small" theme="light" type="warning" onClick={() => onOpenQuality({ issueType: highPriorityIssue.issueType })}>
</Button>

View File

@@ -935,6 +935,127 @@ test('dashboard surfaces highest priority quality issue with evidence shortcuts'
});
});
test('dashboard copies highest priority quality issue notification text', async () => {
window.history.replaceState(null, '', '/#/dashboard');
const writeText = vi.fn(() => Promise.resolve());
Object.defineProperty(navigator, 'clipboard', {
configurable: true,
value: { writeText }
});
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
return {
ok: true,
json: async () => ({
data: { linkHealth: [], kafkaLag: 0, activeConnections: 0, capacityFindings: [], redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/dashboard/summary')) {
return {
ok: true,
json: async () => ({
data: {
onlineVehicles: 88,
activeToday: 96,
frameToday: 1286320,
issueVehicles: 7,
kafkaLag: 0,
protocols: [],
serviceStatuses: [],
linkHealth: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicle-service/summary')) {
return {
ok: true,
json: async () => ({
data: {
totalVehicles: 1033,
boundVehicles: 1024,
onlineVehicles: 88,
singleSourceVehicles: 391,
multiSourceVehicles: 181,
noDataVehicles: 0,
identityRequiredVehicles: 0,
archiveIncompleteVehicles: 0,
serviceStatuses: [],
protocols: [],
missingSources: [],
archiveMissingFields: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/issues')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: '',
plate: '粤A告警1',
phone: '13307795425',
sourceEndpoint: '115.231.168.135:43625',
protocol: 'JT808',
issueType: 'VIN_MISSING',
severity: 'error',
lastSeen: '2026-07-03 20:12:10',
detail: 'JT808 数据缺少 VIN 映射'
}],
total: 1,
limit: 5,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/summary')) {
return {
ok: true,
json: async () => ({
data: { issueVehicleCount: 7, issueRecordCount: 9, errorCount: 1, warningCount: 8, protocols: [], issueTypes: [] },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('最高优先级告警')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '首页复制告警通知' }));
await waitFor(() => {
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('【P0 告警通知】VIN 缺失'));
});
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('车辆粤A告警1 / 13307795425'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('数据来源JT808'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('详情JT808 数据缺少 VIN 映射'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('轨迹证据http://localhost:3000/#/history?keyword=%E7%B2%A4A%E5%91%8A%E8%AD%A61&protocol=JT808&dateFrom=2026-07-03&dateTo=2026-07-04'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('RAW证据http://localhost:3000/#/history?keyword=%E7%B2%A4A%E5%91%8A%E8%AD%A61&protocol=JT808&tab=raw&dateFrom=2026-07-03&dateTo=2026-07-04&includeFields=true'));
});
test('dashboard keeps core vehicle service metrics when preview requests fail', async () => {
window.history.replaceState(null, '', '/#/dashboard');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {