feat(platform): route vehicle searches to detail
This commit is contained in:
@@ -11,12 +11,8 @@ type VehicleQuery = {
|
||||
protocol?: string;
|
||||
};
|
||||
|
||||
const defaultQuery: VehicleQuery = {
|
||||
vin: 'LB9A32A24R0LS1426'
|
||||
};
|
||||
|
||||
export function VehicleDetail() {
|
||||
const [query, setQuery] = useState<VehicleQuery>(defaultQuery);
|
||||
export function VehicleDetail({ vin }: { vin: string }) {
|
||||
const [query, setQuery] = useState<VehicleQuery>({ vin });
|
||||
const [detail, setDetail] = useState<VehicleDetailData | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
@@ -38,8 +34,10 @@ export function VehicleDetail() {
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
load(defaultQuery);
|
||||
}, []);
|
||||
const nextQuery = { vin };
|
||||
setQuery(nextQuery);
|
||||
load(nextQuery);
|
||||
}, [vin]);
|
||||
|
||||
const identity = detail?.identity;
|
||||
const latest = detail?.realtime[0];
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Button, Card, Form, Select, SideSheet, Space, Table, TextArea, Toast } from '@douyinfe/semi-ui';
|
||||
import { Button, Card, Form, Select, Space, Table, Toast } from '@douyinfe/semi-ui';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { api } from '../api/client';
|
||||
import type { VehicleRow } from '../api/types';
|
||||
@@ -6,10 +6,9 @@ import { DataEmpty } from '../components/DataEmpty';
|
||||
import { PageHeader } from '../components/PageHeader';
|
||||
import { StatusTag } from '../components/StatusTag';
|
||||
|
||||
export function Vehicles() {
|
||||
export function Vehicles({ onOpenVehicle }: { onOpenVehicle: (vin: string) => void }) {
|
||||
const [rows, setRows] = useState<VehicleRow[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [selected, setSelected] = useState<VehicleRow | null>(null);
|
||||
|
||||
const load = (values?: Record<string, string>) => {
|
||||
setLoading(true);
|
||||
@@ -35,9 +34,9 @@ export function Vehicles() {
|
||||
{ title: '最后在线', dataIndex: 'lastSeen', width: 170 },
|
||||
{ title: '位置', dataIndex: 'locationText' },
|
||||
{ title: '绑定分', dataIndex: 'bindingScore', width: 90 },
|
||||
{ title: '操作', render: (_: unknown, row: VehicleRow) => <Button onClick={() => setSelected(row)}>详情</Button> }
|
||||
{ title: '操作', render: (_: unknown, row: VehicleRow) => <Button onClick={() => onOpenVehicle(row.vin)}>车辆服务</Button> }
|
||||
],
|
||||
[]
|
||||
[onOpenVehicle]
|
||||
);
|
||||
|
||||
return (
|
||||
@@ -64,9 +63,6 @@ export function Vehicles() {
|
||||
<Table loading={loading} rowKey="vin" dataSource={rows} columns={columns} pagination={false} />
|
||||
)}
|
||||
</Card>
|
||||
<SideSheet title="车辆详情" visible={Boolean(selected)} onCancel={() => setSelected(null)} width={520}>
|
||||
<TextArea value={JSON.stringify(selected, null, 2)} autosize readOnly />
|
||||
</SideSheet>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user