feat(platform): preserve vehicle context in customer tasks

This commit is contained in:
lingniu
2026-07-05 19:07:50 +08:00
parent e48ea7d22a
commit 08c275af34
4 changed files with 53 additions and 5 deletions

View File

@@ -329,10 +329,12 @@ export default function App() {
const context = await loadVehicleContext(lookupKey, nextProtocol); const context = await loadVehicleContext(lookupKey, nextProtocol);
const resolved = context?.resolved; const resolved = context?.resolved;
const nextKey = context?.nextKey ?? lookupKey; const nextKey = context?.nextKey ?? lookupKey;
const resolvedProtocol = nextProtocol || context?.overview.primaryProtocol?.trim() || '';
setActiveVin(nextKey); setActiveVin(nextKey);
setActiveProtocol(nextProtocol); setAnalysisVin(nextKey);
setActiveProtocol(resolvedProtocol);
setActivePage('detail'); setActivePage('detail');
replaceHash('detail', nextKey, nextProtocol); replaceHash('detail', nextKey, resolvedProtocol);
if (!resolved) { if (!resolved) {
Toast.warning('未匹配到车辆身份,已打开问题排查视图'); Toast.warning('未匹配到车辆身份,已打开问题排查视图');
} }
@@ -443,6 +445,40 @@ export default function App() {
replaceHash('mileage', keyword ?? nextVin, protocol ?? nextProtocol, restFilters); replaceHash('mileage', keyword ?? nextVin, protocol ?? nextProtocol, restFilters);
}; };
const openCustomerTask = (page: PageKey) => {
const keyword = (activeVin || analysisVin).trim();
const protocol = activeProtocol.trim();
if (!keyword) {
navigatePage(page);
return;
}
if (page === 'map') {
openMap({ keyword, protocol });
return;
}
if (page === 'realtime') {
openRealtime({ keyword, protocol });
return;
}
if (page === 'history') {
openHistoryWithFilters({ keyword, protocol });
return;
}
if (page === 'history-query') {
openRawWithFilters({ keyword, protocol, tab: 'raw' });
return;
}
if (page === 'mileage') {
openMileageWithFilters({ keyword, protocol });
return;
}
if (page === 'alert-events' || page === 'quality') {
openQuality({ keyword, protocol });
return;
}
navigatePage(page);
};
const updateVehicleDetailQuery = (keyword: string, protocol?: string) => { const updateVehicleDetailQuery = (keyword: string, protocol?: string) => {
const nextKeyword = keyword.trim(); const nextKeyword = keyword.trim();
const nextProtocol = protocol?.trim() ?? ''; const nextProtocol = protocol?.trim() ?? '';
@@ -476,7 +512,7 @@ export default function App() {
}; };
return ( return (
<AppShell activePage={activePage} linkIssueCount={linkIssueCount} activeAlertRuleCount={activeAlertRuleCount} p0AlertRuleCount={p0AlertRuleCount} platformRelease={platformRelease} currentVehicleStatus={currentVehicleStatus} currentVehicleLabel={currentVehicleLabel} currentVehicleConsistency={currentVehicleConsistency} onChange={navigatePage} onVehicleSearch={openVehicle}> <AppShell activePage={activePage} linkIssueCount={linkIssueCount} activeAlertRuleCount={activeAlertRuleCount} p0AlertRuleCount={p0AlertRuleCount} platformRelease={platformRelease} currentVehicleStatus={currentVehicleStatus} currentVehicleLabel={currentVehicleLabel} currentVehicleConsistency={currentVehicleConsistency} onChange={navigatePage} onCustomerTask={openCustomerTask} onVehicleSearch={openVehicle}>
{pages[activePage]} {pages[activePage]}
</AppShell> </AppShell>
); );

View File

@@ -131,6 +131,7 @@ export function AppShell({
currentVehicleLabel, currentVehicleLabel,
currentVehicleConsistency, currentVehicleConsistency,
onChange, onChange,
onCustomerTask,
onVehicleSearch, onVehicleSearch,
children children
}: { }: {
@@ -143,6 +144,7 @@ export function AppShell({
currentVehicleLabel?: string; currentVehicleLabel?: string;
currentVehicleConsistency?: VehicleSourceConsistency; currentVehicleConsistency?: VehicleSourceConsistency;
onChange: (page: PageKey) => void; onChange: (page: PageKey) => void;
onCustomerTask?: (page: PageKey) => void;
onVehicleSearch: (keyword: string) => void | Promise<void>; onVehicleSearch: (keyword: string) => void | Promise<void>;
children: ReactNode; children: ReactNode;
}) { }) {
@@ -212,7 +214,7 @@ export function AppShell({
key={item.page} key={item.page}
type="button" type="button"
className={selectedPage === item.page ? 'vp-customer-task-dispatch-action vp-customer-task-dispatch-action-active' : 'vp-customer-task-dispatch-action'} className={selectedPage === item.page ? 'vp-customer-task-dispatch-action vp-customer-task-dispatch-action-active' : 'vp-customer-task-dispatch-action'}
onClick={() => onChange(item.page)} onClick={() => (onCustomerTask ?? onChange)(item.page)}
aria-label={`客户任务 ${item.label} ${item.question}`} aria-label={`客户任务 ${item.label} ${item.question}`}
> >
<strong>{item.label}</strong> <strong>{item.label}</strong>

View File

@@ -198,7 +198,8 @@ function qualityActionRecommendation(row: QualityIssueRow) {
} }
function issueCount(summary: QualitySummary, issueType: string) { function issueCount(summary: QualitySummary, issueType: string) {
return summary.issueTypes.find((item) => item.name === issueType)?.count ?? 0; const issueTypes = Array.isArray(summary.issueTypes) ? summary.issueTypes : [];
return issueTypes.find((item) => item.name === issueType)?.count ?? 0;
} }
const issuePriorityWeight: Record<string, number> = { const issuePriorityWeight: Record<string, number> = {

View File

@@ -2945,6 +2945,15 @@ test('shows resolved vehicle service status after topbar search', async () => {
expect(screen.getByText('一致性:数据通道不完整')).toBeInTheDocument(); expect(screen.getByText('一致性:数据通道不完整')).toBeInTheDocument();
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/vehicle-service/overview?keyword=%E7%B2%A4AG18312'), undefined); expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/vehicle-service/overview?keyword=%E7%B2%A4AG18312'), undefined);
expect(fetchMock).not.toHaveBeenCalledWith(expect.stringContaining('/api/vehicles/resolve'), undefined); expect(fetchMock).not.toHaveBeenCalledWith(expect.stringContaining('/api/vehicles/resolve'), undefined);
fireEvent.click(screen.getByRole('button', { name: '客户任务 轨迹回放 这段时间怎么跑' }));
expect(window.location.hash).toBe('#/history?keyword=LB9A32A24R0LS1426&protocol=JT808');
fireEvent.click(screen.getByRole('button', { name: '客户任务 统计查询 里程怎么算' }));
expect(window.location.hash).toBe('#/mileage?keyword=LB9A32A24R0LS1426&protocol=JT808');
fireEvent.click(screen.getByRole('button', { name: '客户任务 数据导出 证据怎么给客户' }));
expect(window.location.hash).toBe('#/history-query?keyword=LB9A32A24R0LS1426&protocol=JT808&tab=raw');
fireEvent.click(screen.getByRole('button', { name: '客户任务 告警通知 异常谁处理' }));
expect(window.location.hash).toBe('#/alert-events?keyword=LB9A32A24R0LS1426&protocol=JT808');
}); });
test('shows row service status in dashboard vehicle previews', async () => { test('shows row service status in dashboard vehicle previews', async () => {