feat(platform-web): show vehicle analysis scope

This commit is contained in:
lingniu
2026-07-04 03:52:55 +08:00
parent a0772be4a6
commit 2e50f43ff4
3 changed files with 54 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
import { Button, Card, Form, Select, SideSheet, Space, Table, Tabs, Toast, Typography } from '@douyinfe/semi-ui';
import { Button, Card, Form, Select, SideSheet, Space, Table, Tabs, Tag, Toast, Typography } from '@douyinfe/semi-ui';
import { IconRefresh, IconSearch } from '@douyinfe/semi-icons';
import { useEffect, useMemo, useState } from 'react';
import { api, type RawFrameQuery } from '../api/client';
@@ -132,6 +132,11 @@ export function History({ initialVin, initialProtocol, onOpenVehicle }: { initia
</Button>
)}
/>
<div className="vp-scope-bar">
<span className="vp-scope-label">{currentVehicleKeyword || '-'}</span>
<Tag color={currentProtocol ? 'blue' : 'green'}>{currentProtocol || '全部来源'}</Tag>
<Typography.Text type="tertiary"> RAW </Typography.Text>
</div>
<Card bordered>
<Form key={`${filters.keyword ?? ''}-${filters.protocol ?? ''}-${filters.includeFields ? 'fields' : 'light'}`} initValues={filters} layout="horizontal" onSubmit={(values) => submit(values)}>
<Form.Input field="keyword" label="车辆关键词" placeholder="VIN / 车牌 / 手机号" style={{ width: 260 }} />

View File

@@ -1,4 +1,4 @@
import { Button, Card, Form, Select, Space, Table, Tag, Toast } from '@douyinfe/semi-ui';
import { Button, Card, Form, Select, Space, Table, Tag, Toast, Typography } from '@douyinfe/semi-ui';
import { useEffect, useState } from 'react';
import { api } from '../api/client';
import type { DailyMileageRow, MileageSummary } from '../api/types';
@@ -79,6 +79,11 @@ export function Mileage({ initialVin, initialProtocol, onOpenVehicle }: { initia
</Button>
)}
/>
<div className="vp-scope-bar">
<span className="vp-scope-label">{currentVehicleKeyword || '-'}</span>
<Tag color={currentProtocol ? 'blue' : 'green'}>{currentProtocol || '全部来源'}</Tag>
<Typography.Text type="tertiary"></Typography.Text>
</div>
<Card bordered>
<Form key={filters.keyword ?? ''} initValues={filters} layout="horizontal" onSubmit={(values) => {
const nextFilters = values as Record<string, string>;

View File

@@ -938,6 +938,48 @@ test('applies protocol from shareable history hash to API requests', async () =>
method: 'POST',
body: expect.stringContaining('"protocol":"JT808"')
}));
expect(screen.getByText('当前车辆粤AG18312')).toBeInTheDocument();
expect(screen.getByText('当前来源JT808')).toBeInTheDocument();
});
test('shows vehicle and source scope on mileage hash', async () => {
window.history.replaceState(null, '', '/#/mileage?keyword=VIN-MILEAGE-001&protocol=GB32960');
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, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/mileage/summary')) {
return {
ok: true,
json: async () => ({
data: { vehicleCount: 1, recordCount: 2, sourceCount: 1, totalMileageKm: 12.3, averageMileagePerVin: 12.3 },
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('当前车辆VIN-MILEAGE-001')).toBeInTheDocument();
expect(screen.getByText('当前来源GB32960')).toBeInTheDocument();
});
test('keeps row protocol when opening vehicle service from history results', async () => {