feat(platform-web): link analysis pages to vehicle service
This commit is contained in:
@@ -1,12 +1,16 @@
|
|||||||
import { Typography } from '@douyinfe/semi-ui';
|
import { Typography } from '@douyinfe/semi-ui';
|
||||||
|
import type { ReactNode } from 'react';
|
||||||
|
|
||||||
export function PageHeader({ title, description }: { title: string; description: string }) {
|
export function PageHeader({ title, description, actions }: { title: string; description: string; actions?: ReactNode }) {
|
||||||
return (
|
return (
|
||||||
<div style={{ marginBottom: 16 }}>
|
<div className="vp-page-header">
|
||||||
<Typography.Title heading={3} style={{ margin: 0 }}>
|
<div>
|
||||||
{title}
|
<Typography.Title heading={3} style={{ margin: 0 }}>
|
||||||
</Typography.Title>
|
{title}
|
||||||
<Typography.Text type="tertiary">{description}</Typography.Text>
|
</Typography.Title>
|
||||||
|
<Typography.Text type="tertiary">{description}</Typography.Text>
|
||||||
|
</div>
|
||||||
|
{actions ? <div className="vp-page-header-actions">{actions}</div> : null}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,10 +118,20 @@ export function History({ initialVin, initialProtocol, onOpenVehicle }: { initia
|
|||||||
}, [initialVin, initialProtocol]);
|
}, [initialVin, initialProtocol]);
|
||||||
|
|
||||||
const rawFieldCount = useMemo(() => Object.keys(selectedRaw?.parsedFields ?? {}).length, [selectedRaw]);
|
const rawFieldCount = useMemo(() => Object.keys(selectedRaw?.parsedFields ?? {}).length, [selectedRaw]);
|
||||||
|
const currentVehicleKeyword = filters.keyword?.trim() ?? '';
|
||||||
|
const currentProtocol = filters.protocol?.trim() ?? '';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="vp-page">
|
<div className="vp-page">
|
||||||
<PageHeader title="历史数据" description="按车辆查询位置历史和 RAW 帧历史,数据来源只作为过滤和诊断维度" />
|
<PageHeader
|
||||||
|
title="历史数据"
|
||||||
|
description="按车辆查询位置历史和 RAW 帧历史,数据来源只作为过滤和诊断维度"
|
||||||
|
actions={(
|
||||||
|
<Button disabled={!currentVehicleKeyword} onClick={() => onOpenVehicle(currentVehicleKeyword, currentProtocol)}>
|
||||||
|
当前车辆服务
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
<Card bordered>
|
<Card bordered>
|
||||||
<Form key={`${filters.keyword ?? ''}-${filters.protocol ?? ''}-${filters.includeFields ? 'fields' : 'light'}`} initValues={filters} layout="horizontal" onSubmit={(values) => submit(values)}>
|
<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 }} />
|
<Form.Input field="keyword" label="车辆关键词" placeholder="VIN / 车牌 / 手机号" style={{ width: 260 }} />
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ export function Mileage({ initialVin, initialProtocol, onOpenVehicle }: { initia
|
|||||||
const [summaryLoading, setSummaryLoading] = useState(true);
|
const [summaryLoading, setSummaryLoading] = useState(true);
|
||||||
const [filters, setFilters] = useState<Record<string, string>>({ keyword: initialVin, protocol: initialProtocol ?? '' });
|
const [filters, setFilters] = useState<Record<string, string>>({ keyword: initialVin, protocol: initialProtocol ?? '' });
|
||||||
const [pagination, setPagination] = useState({ currentPage: 1, pageSize: 20, total: 0 });
|
const [pagination, setPagination] = useState({ currentPage: 1, pageSize: 20, total: 0 });
|
||||||
|
const currentVehicleKeyword = filters.keyword?.trim() ?? '';
|
||||||
|
const currentProtocol = filters.protocol?.trim() ?? '';
|
||||||
|
|
||||||
const loadSummary = (values: Record<string, string> = filters) => {
|
const loadSummary = (values: Record<string, string> = filters) => {
|
||||||
setSummaryLoading(true);
|
setSummaryLoading(true);
|
||||||
@@ -68,7 +70,15 @@ export function Mileage({ initialVin, initialProtocol, onOpenVehicle }: { initia
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="vp-page">
|
<div className="vp-page">
|
||||||
<PageHeader title="里程统计" description="按车辆汇总每日里程、区间里程和异常差值分析" />
|
<PageHeader
|
||||||
|
title="里程统计"
|
||||||
|
description="按车辆汇总每日里程、区间里程和异常差值分析"
|
||||||
|
actions={(
|
||||||
|
<Button disabled={!currentVehicleKeyword} onClick={() => onOpenVehicle(currentVehicleKeyword, currentProtocol)}>
|
||||||
|
当前车辆服务
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
<Card bordered>
|
<Card bordered>
|
||||||
<Form key={filters.keyword ?? ''} initValues={filters} layout="horizontal" onSubmit={(values) => {
|
<Form key={filters.keyword ?? ''} initValues={filters} layout="horizontal" onSubmit={(values) => {
|
||||||
const nextFilters = values as Record<string, string>;
|
const nextFilters = values as Record<string, string>;
|
||||||
|
|||||||
@@ -84,6 +84,20 @@ body {
|
|||||||
padding: var(--vp-page-gutter);
|
padding: var(--vp-page-gutter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.vp-page-header {
|
||||||
|
min-height: 54px;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.vp-page-header-actions {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
padding-top: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
.vp-section {
|
.vp-section {
|
||||||
background: var(--vp-surface);
|
background: var(--vp-surface);
|
||||||
border: 1px solid var(--vp-border);
|
border: 1px solid var(--vp-border);
|
||||||
|
|||||||
@@ -398,3 +398,48 @@ test('opens history with the currently selected vehicle detail source', async ()
|
|||||||
expect(window.location.hash).toBe('#/history?keyword=VIN001&protocol=JT808');
|
expect(window.location.hash).toBe('#/history?keyword=VIN001&protocol=JT808');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('opens vehicle service from an empty history query with the current filters', async () => {
|
||||||
|
window.history.replaceState(null, '', '/#/history?keyword=VIN404&protocol=JT808');
|
||||||
|
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
|
||||||
|
const path = String(input);
|
||||||
|
if (path.includes('/api/vehicles/resolve')) {
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({
|
||||||
|
data: {
|
||||||
|
lookupKey: 'VIN404',
|
||||||
|
resolved: true,
|
||||||
|
vin: 'VIN404',
|
||||||
|
plate: '',
|
||||||
|
phone: '',
|
||||||
|
oem: '',
|
||||||
|
protocols: ['JT808'],
|
||||||
|
online: false,
|
||||||
|
lastSeen: ''
|
||||||
|
},
|
||||||
|
traceId: 'trace-test',
|
||||||
|
timestamp: 1783094400000
|
||||||
|
})
|
||||||
|
} as Response;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({
|
||||||
|
data: path.includes('/api/ops/health')
|
||||||
|
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
|
||||||
|
: { items: [], total: 0, limit: 10, offset: 0 },
|
||||||
|
traceId: 'trace-test',
|
||||||
|
timestamp: 1783094400000
|
||||||
|
})
|
||||||
|
} as Response;
|
||||||
|
});
|
||||||
|
|
||||||
|
render(<App />);
|
||||||
|
|
||||||
|
fireEvent.click(await screen.findByRole('button', { name: '当前车辆服务' }));
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(window.location.hash).toBe('#/detail?keyword=VIN404&protocol=JT808');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user